-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.js
1073 lines (912 loc) · 40.2 KB
/
functions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
function addSourceAndLayer(geojson){
map.addSource('companies', {
'type': 'geojson',
'attribution': `Data collected by <u><a href="https://github.com/chrieke/awesome-geospatial-companies">Christoph Reike</a></u>.<br>\
Contributions and comment are welcome at <u><a href="https://docs.google.com/spreadsheets/d/1pQQfcpPsh2EIJxCamAsL8B4c_GI8BaT-r8LCNckuE5w/edit?usp=sharing">Google Sheets</a></u>.<br>\
Data available directly as <u><a href="${layerUrl}">GeoJSON</a></u>.`,
'data': geojson
});
map.addLayer({
"id": "companies",
"type": "circle",
"source": "companies",
"layout": {},
"paint": {
"circle-radius": {
"property": "Office_Size",
"type": "categorical",
"stops": [
[{zoom: 3, value: "S"}, 4],
[{zoom: 3, value: "S (B)"}, 4],
[{zoom: 3, value: "S (H)"}, 4],
[{zoom: 3, value: "M"}, 4],
[{zoom: 3, value: "M (B)"}, 4],
[{zoom: 3, value: "M (H)"}, 4],
[{zoom: 3, value: "L"}, 4],
[{zoom: 3, value: "L (B)"}, 4],
[{zoom: 3, value: "L (H)"}, 4],
[{zoom: 12, value: "S"}, 5],
[{zoom: 12, value: "S (B)"}, 5],
[{zoom: 12, value: "S (H)"}, 5],
[{zoom: 12, value: "M"}, 8],
[{zoom: 12, value: "M (B)"}, 8],
[{zoom: 12, value: "M (H)"}, 8],
[{zoom: 12, value: "L"}, 12],
[{zoom: 12, value: "L (B)"}, 12],
[{zoom: 12, value: "L (H)"}, 12],
]
},
"circle-stroke-color":[
"case",
[
"boolean",
["feature-state", "hover"],
false
],
"#39d1d3",
[
"match",
["get", "Category"],
"Digital Farming",
"hsl(89,43%,45%)",//"#74ae36",
"Earth Observation",
"hsl(0,90%,66%)",//"#ff5252",
"GIS / Spatial Analysis",
"hsl(55,90%,50%)",//"#ffe900",
"Satellite Operator",
"hsl(0,0%,40%)",//"#757575",
"UAV / Aerial",
"hsl(201,86%,42%)",//"#048ad1",
"Webmap / Cartography",
"hsl(29,89%,48%)",//"#f57801",
"#ccc"
]
],
"circle-stroke-opacity": 1,
"circle-stroke-width": [
"case",
[
"boolean",
["feature-state", "hover"],
false
],
2,
1.5
],
"circle-color": [
"match",
["get", "Category"],
"Digital Farming",
"hsl(89,53%,45%)",//"#74ae36",
"Earth Observation",
"hsl(0,100%,66%)",//"#ff5252",
"GIS / Spatial Analysis",
"hsl(55,100%,50%)",//"#ffe900",
"Satellite Operator",
"hsl(0,0%,46%)",//"#757575",
"UAV / Aerial",
"hsl(201,96%,42%)",//"#048ad1",
"Webmap / Cartography",
"hsl(29,99%,48%)",//"#f57801",
"#ccc"
]
}
});
map.addLayer({
"id": "companies-label",
"type": "symbol",
"source": "companies",
"minzoom": 9.5,
"layout": {
"text-field": ["get", "Name"],
"text-font": ["Roboto Regular"],
"icon-allow-overlap": true,
"icon-anchor": "center",
"text-anchor": "bottom",
"text-size": 16,
"text-allow-overlap": false,
"text-line-height": 1.5,
"text-variable-anchor": ["bottom","top","left","right"]
},
"paint": {
"text-halo-color": "rgba(255, 255, 255, 0.89)",
"text-halo-width": 1.5
}
})
addEvents()
populateSuggestions(geojson)
}
function addEvents(){
map.on('mousemove', 'companies', (e) => {
if (e.features.length > 0) {
if (hoveredStateId !== null) {
map.setFeatureState(
{ source: 'companies', id: hoveredStateId },
{ hover: false }
);
}
hoveredStateId = e.features[0].id;
map.setFeatureState(
{ source: 'companies', id: hoveredStateId },
{ hover: true }
);
}
});
map.on('mouseenter', 'companies', () => {
map.getCanvas().style.cursor = 'pointer'
})
// When the mouse leaves the state-fill layer, update the feature state of the
// previously hovered feature.
map.on('mouseleave', 'companies', () => {
map.getCanvas().style.cursor = ''
if (hoveredStateId !== null) {
map.setFeatureState(
{ source: 'companies', id: hoveredStateId },
{ hover: false }
);
}
hoveredStateId = null;
});
map.on('click', getMapclick)
map.on('click', 'companies', (e) => {
const feature = e.features[0]
const coordinates = feature.geometry.coordinates.slice();
let description = '';
console.log(feature)
description += (feature.properties.Logo && feature.properties.Logo.length >0) ? `<img class='logo-image' src="${feature.properties.Logo}" />` : '';
description += (feature.properties.Name && feature.properties.Name.length >0) ? `<h2>${feature.properties.Name}</h2>` :'';
description += (feature.properties.Notes__ex_name_ && feature.properties.Notes__ex_name_.length >0) ? `<b>Notes (ex-name):</b> ${feature.properties.Notes__ex_name_}<br>` :'';
description += (feature.properties.Office_Size && feature.properties.Office_Size.length >0) ? `<b>Office Size:</b> ${feature.properties.Office_Size}<br>` :'';
description += (feature.properties.Country && feature.properties.Country.length >0) ? `<b>Country:</b> ${feature.properties.Country}<br>` :'';
description += (feature.properties.Category && feature.properties.Category.length >0) ? `<b>Category:</b> ${feature.properties.Category}<br>` :'';
description += (feature.properties.Focus && feature.properties.Focus.length >0) ? `<b>Focus:</b> ${feature.properties.Focus}<br>` :'';
description += (feature.properties.Website && feature.properties.Website.length >0) ? `<b>Website:</b> <a href="${feature.properties.Website}">${feature.properties.Website}</a><br>` :'';
description += (feature.properties.City && feature.properties.City.length >0) ? `<b>City:</b> ${feature.properties.City}<br>` :'';
description += (feature.properties.Address && feature.properties.Address.length >0) ? `<b>Address:</b> ${feature.properties.Address}<br>` :'';
description += suggestEditButton()
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new maplibregl.Popup()
.setLngLat(coordinates)
.setHTML(description)
.on('open', function(){
attachEditEvent(feature);
})
.addTo(map);
gtag('event', 'popup_open', {
'company_name': feature.properties.Name,
'company_id': feature.id,
'country_name':feature.properties.Country,
'category':feature.properties.Category
});
});
}
function refreshData(){
fetch(layerUrl)
.then(res => res.json())
.then(data => {
map.getSource('companies').setData(data)
})
}
let currentParameters ={
type:'add',
name:'',
lat:0.0,
lon:0.0,
description:'',
ex_name:'',
office_Size:'',
country:'',
category:'',
focus:'',
website:'',
city:'',
address:''
}
const fieldNames = {
name:'Name',
lat:'Latitude',
lon:'Longitude',
description:'Description',
ex_name:'Notes - Former name',
office_Size:'Office Size',
country:'Country',
category:'Category',
focus:'Focus',
website:'Website',
city:'City',
address:'Address'
}
function attachEditEvent(feature){
let openEditButton = document.getElementById('openEditControl')
openEditButton.feature = feature;
openEditButton.onclick = openEditForm
}
function openEditForm(){
let openEditButton = document.getElementById('openEditControl')
let feature = openEditButton.feature;
console.log(feature)
ToggleForm()
if(map.hasControl(addCompanyControl)){
document.getElementById('inputName').value = feature.properties.Name;
document.getElementById('inputClick').children[0].style.color = '#800';
document.getElementById('inputlat').value = feature.geometry.coordinates[1];
document.getElementById('inputlon').value = feature.geometry.coordinates[0];
currentParameters.lat = feature.geometry.coordinates[1]
currentParameters.lon = feature.geometry.coordinates[0];
document.getElementById('inputExName').value = feature.properties.Notes__ex_name_;
document.getElementById('inputOffice').value = feature.properties.Office_Size;
document.getElementById('inputCategory').value = feature.properties.Category;
document.getElementById('inputWebsite').value = feature.properties.Website;
document.getElementById('inputFocus').value = feature.properties.Focus;
document.getElementById('inputCountry').value = feature.properties.Country;
document.getElementById('inputCity').value = feature.properties.City;
document.getElementById('inputAddress').value = feature.properties.Address;
document.getElementById('inputImage').value = feature.properties.Logo;
const e = new Event("change");
document.getElementById('inputImage').dispatchEvent(e);
currentParameters.id = feature.properties.id;
inputSubmit.onclick = submitComment
}
}
function suggestEditButton(){
let spanClick = document.createElement('center');
spanClick.classList.add('form-span')
let labelClick = document.createElement('label');
labelClick.innerHTML = `</br><b>Suggest edits:</b></br>`;
let openEditControl = document.createElement('button');
openEditControl.type = 'button';
openEditControl.className = 'open-edit-button';
openEditControl.id = 'openEditControl';
openEditControl.innerHTML = '<i class="fg-map-edit fg-2x"></i> ';
spanClick.append(labelClick,document.createElement('br'),openEditControl)
return spanClick.outerHTML
}
function ToggleForm(){
if(map.hasControl(addCompanyControl)){
map.removeControl(addCompanyControl)
}else{
map.addControl(addCompanyControl)
}
}
function getMapclick(e){
document.getElementsByClassName('share-control')[0].innerHTML = '<i class="fg-map-share fg-2x" style="color:#fff;"></i>';
// if after use of add point button, then get coords and open form
if(waitForClick===1){
waitForClick=0;
currentLngLat = e.lngLat;
currentParameters.lat = currentLngLat.lat
inputlat.value = currentParameters.lat
currentParameters.lon = currentLngLat.lng
inputlon.value = currentParameters.lon
if(isMobile){
let forms = document.getElementsByClassName('company-form')
if(forms.length > 0){
let form = forms[0]
form.style.display = 'block'
}
}
let inputClick = document.getElementById('inputClick');
inputClick.classList.remove('fg-spin');
inputClick.children[0].style.color = '#800';
};
};
function addPointLocation(){
// tell map to wait for next click
let inputClick = document.getElementById('inputClick');
inputClick.classList.add('fg-spin');
if(isMobile){
let forms = document.getElementsByClassName('company-form')
if(forms.length > 0){
let form = forms[0]
form.style.display = 'none'
}
}
waitForClick=1
}
function buildForm(){
let form = document.createElement('form');
form.className = 'company-form'
let spanName = document.createElement('span');
spanName.classList.add('form-span')
let labelName = document.createElement('label');
labelName.innerHTML = `<b>${fieldNames['name']}:</b>`;
let inputName = document.createElement('input');
inputName.type = 'text';
inputName.id = 'inputName';
spanName.append(labelName,document.createElement('br'),inputName)
form.append(spanName,document.createElement('br'))
let spanClick = document.createElement('center');
spanClick.classList.add('form-span')
let labelClick = document.createElement('label');
labelClick.innerHTML = `<b>Location:</b>`;
let inputClick = document.createElement('button');
inputClick.type = 'button';
inputClick.id = 'inputClick';
inputClick.innerHTML = '<i class="fg-pushpin fg-rotate20 fg-2x"></i> ';
inputClick.onclick = addPointLocation
spanClick.append(labelClick,document.createElement('br'),inputClick)
form.append(document.createElement('br'),spanClick,document.createElement('br'))
let spanlat = document.createElement('span');
spanlat.classList.add('form-span')
let labellat = document.createElement('label');
labellat.innerHTML = `<b>${fieldNames['lat']}:</b>`;
let inputlat = document.createElement('input');
inputlat.type = 'text';
inputlat.id = 'inputlat';
inputlat.disabled = true;
spanlat.append(labellat,document.createElement('br'),inputlat,document.createElement('br'))
form.append(spanlat,document.createElement('br'))
let spanlon = document.createElement('span');
spanlon.classList.add('form-span')
let labellon = document.createElement('label');
labellon.innerHTML = `<b>${fieldNames['lon']}:</b>`;
let inputlon = document.createElement('input');
inputlon.type = 'text';
inputlon.id = 'inputlon';
inputlon.disabled = true;
spanlat.append(labellon,document.createElement('br'),inputlon)
form.append(spanlon,document.createElement('br'))
let spanExName = document.createElement('span');
spanExName.classList.add('form-span')
let labelExName = document.createElement('label');
labelExName.innerHTML = `<b>${fieldNames['ex_name']}:</b>`;
let inputExName = document.createElement('input');
inputExName.type = 'text';
inputExName.id = 'inputExName';
spanExName.append(labelExName,document.createElement('br'),inputExName)
form.append(spanExName,document.createElement('br'))
let spanOffice = document.createElement('span');
spanOffice.classList.add('form-span')
let labelOffice = document.createElement('label');
labelOffice.innerHTML = `<b>${fieldNames['office_Size']}:</b>`;
let inputOffice = document.createElement('select');
inputOffice.name = 'inputOffice';
inputOffice.id = 'inputOffice';
let optionL = document.createElement('option');
optionL.value = 'L'
optionL.innerText = 'L (100 < employees)'
let optionLB = document.createElement('option');
optionLB.value = 'L (B)'
optionLB.innerText = 'L (100 < employees) - Branch'
let optionLH = document.createElement('option');
optionLH.value = 'L (H)'
optionLH.innerText = 'L (100 < employees) - Headquarters'
let optionM = document.createElement('option');
optionM.value = 'M'
optionM.innerText = 'M (20-100 employees)'
let optionMB = document.createElement('option');
optionMB.value = 'M (B)'
optionMB.innerText = 'M (20-100 employees) - Branch'
let optionMH = document.createElement('option');
optionMH.value = 'M (H)'
optionMH.innerText = 'M (20-100 employees) - Headquarters'
let optionS = document.createElement('option');
optionS.value = 'S'
optionS.innerText = 'S (20 > employees)'
let optionSB = document.createElement('option');
optionSB.value = 'S (B)'
optionSB.innerText = 'S (20 > employees) - Branch'
let optionSH = document.createElement('option');
optionSH.value = 'S (H)'
optionSH.innerText = 'S (20 > employees) - Headquarters'
inputOffice.append(optionS,optionSB,optionSH,
optionM,optionMB,optionMH,
optionL,optionLB,optionLH)
spanOffice.append(labelOffice,document.createElement('br'),inputOffice)
form.append(spanOffice,document.createElement('br'))
let spanCategory = document.createElement('span');
spanCategory.classList.add('form-span')
let labelCategory = document.createElement('label');
labelCategory.innerHTML = `<b>${fieldNames['category']}:</b>`;
let inputCategory = document.createElement('select');
inputCategory.name = 'select';
inputCategory.id = 'inputCategory';
let option1 = document.createElement('option');
option1.value = 'Digital Farming'
option1.innerText = 'Digital Farming'
let option2 = document.createElement('option');
option2.value = 'Earth Observation'
option2.innerText = 'Earth Observation'
let option3 = document.createElement('option');
option3.value = 'GIS / Spatial Analysis'
option3.innerText = 'GIS / Spatial Analysis'
let option4 = document.createElement('option');
option4.value = 'Satellite Operator'
option4.innerText = 'Satellite Operator'
let option5 = document.createElement('option');
option5.value = 'UAV / Aerial'
option5.innerText = 'UAV / Aerial'
let option6 = document.createElement('option');
option6.value = 'Webmap / Cartography'
option6.innerText = 'Webmap / Cartography'
inputCategory.append(option1,option2,option3,option4,option5,option6)
spanCategory.append(labelCategory,document.createElement('br'),inputCategory)
form.append(spanCategory,document.createElement('br'))
let spanWebsite = document.createElement('span');
spanWebsite.classList.add('form-span')
let labelWebsite = document.createElement('label');
labelWebsite.innerHTML = `<b>${fieldNames['website']}:</b>`;
let inputWebsite = document.createElement('input');
inputWebsite.type = 'text';
inputWebsite.id = 'inputWebsite';
spanWebsite.append(labelWebsite,document.createElement('br'),inputWebsite)
form.append(spanWebsite,document.createElement('br'))
let spanFocus = document.createElement('span');
spanFocus.classList.add('form-span')
let labelFocus = document.createElement('label');
labelFocus.innerHTML = `<b>${fieldNames['focus']}:</b>`;
let inputFocus = document.createElement('input');
inputFocus.type = 'text';
inputFocus.id = 'inputFocus';
spanFocus.append(labelFocus,document.createElement('br'),inputFocus)
form.append(spanFocus,document.createElement('br'))
let spanCountry = document.createElement('span');
spanCountry.classList.add('form-span')
let labelCountry = document.createElement('label');
labelCountry.innerHTML = `<b>${fieldNames['country']}:</b>`;
let inputCountry = document.createElement('input');
inputCountry.type = 'text';
inputCountry.id = 'inputCountry';
spanCountry.append(labelCountry,document.createElement('br'),inputCountry)
form.append(spanCountry,document.createElement('br'))
let spanCity = document.createElement('span');
spanCity.classList.add('form-span')
let labelCity = document.createElement('label');
labelCity.innerHTML = `<b>${fieldNames['city']}:</b>`;
let inputCity = document.createElement('input');
inputCity.type = 'text';
inputCity.id = 'inputCity';
spanCity.append(labelCity,document.createElement('br'),inputCity)
form.append(spanCity,document.createElement('br'))
let spanAddress = document.createElement('span');
spanAddress.classList.add('form-span')
let labelAddress = document.createElement('label');
labelAddress.innerHTML = `<b>${fieldNames['address']}:</b>`;
let inputAddress = document.createElement('input');
inputAddress.type = 'text';
inputAddress.id = 'inputAddress';
spanAddress.append(labelAddress,document.createElement('br'),inputAddress)
form.append(spanAddress,document.createElement('br'))
let spanImage = document.createElement('span');
spanImage.classList.add('form-span');
let labelImage = document.createElement('label');
labelImage.innerHTML = `<b>Logo URL:</b>`;
let inputImage = document.createElement("input");
inputImage.type = "text";
inputImage.id = "inputImage";
inputImage.pattern = "https?://.+"; // regex to match valid URLs
const imgPreview = document.createElement("div");
imgPreview.className = "imgPreview form-span"
inputImage.addEventListener("change", async () => {
// check if the input value is a valid URL
if (!inputImage.validity.valid) return;
try {
// check if the URL returns an image
//const res = await fetch(inputImage.value);
//if (!res.headers.get("content-type").startsWith("image/")) return;
// create an image element and set its src to the URL
const img = document.createElement("img");
img.src = inputImage.value;
// clear the imgPreview div and append the new image
imgPreview.innerHTML = "";
imgPreview.style.height = "100px";
imgPreview.appendChild(img);
imgPreview.appendChild(document.createElement('br'));
} catch (err) {
// handle error
}
});
spanImage.append(labelImage,document.createElement('br'),inputImage)
form.append(spanImage,imgPreview)
let spanSubmit = document.createElement('center');
spanSubmit.classList.add('form-span')
let inputSubmit = document.createElement('input');
inputSubmit.type = 'button';
inputSubmit.id = 'inputSubmit';
inputSubmit.value = 'Submit';
inputSubmit.onclick = submitForm
spanSubmit.append(inputSubmit)
form.append(document.createElement('br'),spanSubmit,document.createElement('br'))
return form
}
function buildDescription(){
let description = ''
description += currentParameters.ex_name.length > 0 ? `Notes (ex-name): ${currentParameters.ex_name}<br>` : '';
description += currentParameters.office_Size.length > 0 ? `Office Size: ${currentParameters.office_Size}<br>` : '';
description += currentParameters.country.length > 0 ? `Country: ${currentParameters.country}<br>` : '';
description += currentParameters.category.length > 0 ? `Category: ${currentParameters.category}<br>` : '';
description += currentParameters.focus.length > 0 ? `Focus: ${currentParameters.focus}<br>` : '';
description += currentParameters.website.length > 0 ? `Website: <a href="${currentParameters.website}"${currentParameters.website}</a><br>` : '';
description += currentParameters.city.length > 0 ? `City: ${currentParameters.city}<br>` : '';
description += currentParameters.address.length > 0 ? `Address: ${currentParameters.address}<br>` : '';
return description
}
function buildShareSpan(){
let container = document.createElement('span');
let twitterButton = document.createElement('a');
twitterButton.href = 'https://twitter.com/intent/tweet?text=Geospatial%20Companies%20Map%0D%0Ahttps://bogind.github.io/Geospatial-Companies/';
twitterButton.target="_blank" ;
twitterButton.rel="noopener noreferrer";
twitterButton.title = "Share to Twitter";
let twitterImage = document.createElement('img');
twitterImage.src = 'icons/Twitter social icons - circle - white.png';
twitterButton.append(twitterImage)
let facebookButton = document.createElement('a');
facebookButton.href = 'https://www.facebook.com/sharer/sharer.php?u=https://bogind.github.io/Geospatial-Companies/&t=Geospatial%20Companies%20Map';
facebookButton.target="_blank" ;
facebookButton.rel="noopener noreferrer";
facebookButton.title = "Share to Facebook";
let facebookImage = document.createElement('img');
facebookImage.src = 'icons/f_logo_RGB-White_58.png';
facebookButton.append(facebookImage)
let whatsappButton = document.createElement('a');
whatsappButton.href = 'https://wa.me?text=Geospatial%20Companies%20Map%0D%0Ahttps://bogind.github.io/Geospatial-Companies/"';
whatsappButton.target="_blank" ;
whatsappButton.rel="noopener noreferrer";
whatsappButton.title = "Share to Whatsapp";
let whatsappImage = document.createElement('img');
whatsappImage.src = 'icons/Digital_Glyph_White.png';
whatsappButton.append(whatsappImage)
let copyURLButton = document.createElement('i');
//copyURLButton.type = 'button'
copyURLButton.onclick = function(){
navigator.clipboard.writeText("https://bogind.github.io/Geospatial-Companies/")
}
copyURLButton.title = "Copy to clipboard";
let copyURLImage = document.createElement('img');
copyURLImage.src = 'icons/icons8-copy-24.png';
copyURLButton.append(copyURLImage)
container.append(twitterButton,facebookButton,whatsappButton,copyURLButton)
return container
}
function toggleShare(e){
let control = document.getElementsByClassName('share-control')[0];
/*if(e.type == 'mouseover'){
control.innerHTML = ''
control.append(buildShareSpan())
}else if(e.type == 'mouseout'){
control.innerHTML = '<i class="fg-map-share-alt fg-2x" style="color:#fff;"></i>';
}else if(e.type == 'click'){*/
if(control.value == 0){
control.innerHTML = ''
control.append(buildShareSpan())
}else{
control.innerHTML = '<i class="fg-map-share-alt fg-2x" style="color:#fff;"></i>';
}
//}
}
function submitForm(){
currentParameters.type = 'add';
currentParameters.name = document.getElementById('inputName').value;
currentParameters.lon = currentLngLat.lng ? currentLngLat.lng : 0.0;
currentParameters.lat = currentLngLat.lat ? currentLngLat.lat : 0.0;
currentParameters.ex_name = document.getElementById('inputExName').value;
currentParameters.office_Size = document.querySelector('#inputOffice').value;
currentParameters.category = document.querySelector('#inputCategory').value;
currentParameters.website = document.getElementById('inputWebsite').value;
currentParameters.focus = document.getElementById('inputFocus').value;
currentParameters.country = document.getElementById('inputCountry').value;
currentParameters.city = document.getElementById('inputCity').value;
currentParameters.address = document.getElementById('inputAddress').value;
currentParameters.description = buildDescription()
currentParameters.logo_url = document.getElementById('inputImage').value
let urlParams = "?";
for (var key in currentParameters) {
if (urlParams != "") {
urlParams += "&";
}
urlParams += (key + "=" + encodeURIComponent(currentParameters[key]));
}
let url = layerUrl + urlParams
fetch(url, {
method: 'POST',
redirect: 'follow'
})
if(map.hasControl(addCompanyControl)){
map.removeControl(addCompanyControl);
refreshData()
}
}
function submitComment(){
currentParameters.type = "comment";
currentParameters.name = document.getElementById('inputName').value;
currentParameters.ex_name = document.getElementById('inputExName').value;
currentParameters.office_Size = document.querySelector('#inputOffice').value;
currentParameters.category = document.querySelector('#inputCategory').value;
currentParameters.website = document.getElementById('inputWebsite').value;
currentParameters.focus = document.getElementById('inputFocus').value;
currentParameters.country = document.getElementById('inputCountry').value;
currentParameters.city = document.getElementById('inputCity').value;
currentParameters.address = document.getElementById('inputAddress').value;
currentParameters.description = buildDescription();
currentParameters.logo_url = document.getElementById('inputImage').value
let urlParams = "?";
urlParams += `id=${currentParameters.id}&`;
urlParams += 'type=comment&';
urlParams += `comment=${JSON.stringify(currentParameters)}`;
let url = layerUrl + urlParams
fetch(url, {
method: 'POST',
redirect: 'follow'
})
if(map.hasControl(addCompanyControl)){
map.removeControl(addCompanyControl);
refreshData()
}
}
function createFilterForm() {
// create a div element to hold the filter control
var filterControl = document.createElement('div');
// create a close button
var closeButton = document.createElement('button');
closeButton.innerHTML = 'X';
closeButton.onclick = ToggleFilter
/*closeButton.addEventListener('click', function() {
// hide the filter control when the close button is clicked
//filterControl.style.display = 'none';
});*/
// add the close button to the filter control
filterControl.appendChild(closeButton);
// position the close button in the top right corner of the filter control
closeButton.style.position = 'absolute';
closeButton.style.top = 0;
closeButton.style.right = 0;
// create a small header
var header = document.createElement('h3');
header.innerHTML = 'Filter';
filterControl.appendChild(header);
// create input elements for name, country, and category
var nameInput = document.createElement('input');
nameInput.id = "nameInput";
nameInput.type = 'text';
nameInput.placeholder = 'Name';
filterControl.appendChild(nameInput);
var countryInput = document.createElement('input');
countryInput.id = "countryInput";
countryInput.type = 'text';
countryInput.placeholder = 'Country';
filterControl.appendChild(countryInput);
var categorySelect = document.createElement('select');
categorySelect.id = "categorySelect";
categorySelect.multiple = true;
categorySelect.size = 6;
categorySelect.addEventListener('change', function() {
let categoryFilter = getCategoriesFilter()
filterPoints(nameInput.value, countryInput.value, categoryFilter);
});
// create options for the select element
var digitalFarmingOption = document.createElement('option');
digitalFarmingOption.innerHTML = 'Digital Farming';
digitalFarmingOption.value = 'Digital Farming';
categorySelect.appendChild(digitalFarmingOption);
var earthObservationOption = document.createElement('option');
earthObservationOption.innerHTML = 'Earth Observation';
earthObservationOption.value = 'Earth Observation';
categorySelect.appendChild(earthObservationOption);
var gisSpatialAnalysisOption = document.createElement('option');
gisSpatialAnalysisOption.innerHTML = 'GIS / Spatial Analysis';
gisSpatialAnalysisOption.value = 'GIS / Spatial Analysis';
categorySelect.appendChild(gisSpatialAnalysisOption);
var satelliteOperatorOption = document.createElement('option');
satelliteOperatorOption.innerHTML = 'Satellite Operator';
satelliteOperatorOption.value = 'Satellite Operator';
categorySelect.appendChild(satelliteOperatorOption);
var uavAerialOption = document.createElement('option');
uavAerialOption.innerHTML = 'UAV / Aerial';
uavAerialOption.value = 'UAV / Aerial';
categorySelect.appendChild(uavAerialOption);
var webmapCartographyOption = document.createElement('option');
webmapCartographyOption.innerHTML = 'Webmap / Cartography';
webmapCartographyOption.value = 'Webmap / Cartography';
categorySelect.appendChild(webmapCartographyOption);
// add the select element to the filter control
filterControl.appendChild(categorySelect);
// hide the filter control by default
//filterControl.style.display = 'none';
// add event listeners to the name and country input elements to handle autocomplete functionality
nameInput.addEventListener('input', function() {
// filter the suggestions based on the input value
let filteredNameSuggestions = filterNameSuggestions(nameInput.value);
let categoryFilter = getCategoriesFilter()
// show the filtered suggestions
if(nameInput.value.length >= 2){
showSuggestions(nameInput, filteredNameSuggestions);
filterPoints(nameInput.value, countryInput.value, categoryFilter);
}else if(nameInput.value.length < 2){
suggestionsDiv = document.querySelector('.autocomplete-suggestions');
if(suggestionsDiv){
suggestionsDiv.parentElement.removeChild(suggestionsDiv);
}
map.setFilter('companies',null)
}
});
countryInput.addEventListener('input', function() {
// filter the suggestions based on the input value
let filteredCountrySuggestions = filterCountrySuggestions(countryInput.value);
let categoryFilter = getCategoriesFilter()
// show the filtered suggestions
if(countryInput.value.length >= 2){
showSuggestions(countryInput, filteredCountrySuggestions);
filterPoints(nameInput.value, countryInput.value, categoryFilter);
}else if(countryInput.value.length < 2){
suggestionsDiv = document.querySelector('.autocomplete-suggestions');
if(suggestionsDiv){
suggestionsDiv.parentElement.removeChild(suggestionsDiv);
}
map.setFilter('companies',null)
}
});
// create a small "clear" button
var clearButton = document.createElement('button');
clearButton.innerHTML = 'Clear';
// add an event listener to the "clear" button to clear the input elements
clearButton.onclick = clearFilterAndSuggestions;
// append the "clear" button to the filter control
filterControl.appendChild(clearButton);
return filterControl;
}
function clearFilterAndSuggestions(){
nameInput.value = '';
countryInput.value = '';
categorySelect.selectedIndex = -1;
suggestionsDiv = document.querySelector('.autocomplete-suggestions');
if(suggestionsDiv){
suggestionsDiv.parentElement.removeChild(suggestionsDiv);
}
map.setFilter('companies',null)
}
function getCategoriesFilter(){
let selected = document.querySelectorAll('#categorySelect option:checked');
let values = Array.from(selected).map(el => el.value);
categoryFilter = ['any']
values.forEach(category => {
categoryFilter.push(['==','Category',category])
})
return categoryFilter
}
function filterPoints(name, country, categoryFilter) {
// get the name, country, and category filter values
var nameFilter = ['==', 'Name', name];
var countryFilter = ['==', 'Country', country];
// combine the filters
var filters = ['all']//, nameFilter, countryFilter, categoryFilter];
if(name.length > 0){
filters.push(nameFilter)
}
if(country.length > 0){
filters.push(countryFilter)
}
if(categoryFilter.length > 1){
filters.push(categoryFilter)
}
console.log(filters)
// apply the filters to the point layer
map.setFilter('companies', filters);
}
// create arrays to hold the name and country suggestions
var nameSuggestions = [];
var countrySuggestions = [];
// create a function to populate the suggestions arrays with name and country values from a geojson feature collection
function populateSuggestions(geojson) {
geojson.features.forEach(function(feature) {
// add the name and country values to the suggestions arrays
nameSuggestions.push(feature.properties.Name.trim());
countrySuggestions.push(feature.properties.Country.trim());
});
nameSuggestions = [...new Set(nameSuggestions)];
countrySuggestions = [...new Set(countrySuggestions)];
}
// create a function to filter the name suggestions array based on the input value
function filterNameSuggestions(inputValue) {
return nameSuggestions.filter(function(suggestion) {
// return suggestions that contain the input value
return suggestion.toLowerCase().indexOf(inputValue.toLowerCase()) !== -1;
});
}
// create a function to filter the country suggestions array based on the input value
function filterCountrySuggestions(inputValue) {
return countrySuggestions.filter(function(suggestion) {
// return suggestions that contain the input value
return suggestion.toLowerCase().indexOf(inputValue.toLowerCase()) !== -1;
});
}
// create a function to show the autocomplete suggestions
function showSuggestions(input, suggestions) {
// check if the suggestions div already exists
var suggestionsDiv = input.parentNode.querySelector('.autocomplete-suggestions');
// if the suggestions div doesn't exist, create it
if (!suggestionsDiv) {
suggestionsDiv = document.createElement('div');
// add a class to the suggestions div to style it
suggestionsDiv.classList.add('autocomplete-suggestions');
// create a div element to hold the list of suggestions
var suggestionsList = document.createElement('div');
// add a class to the suggestions list to style it
suggestionsList.classList.add('autocomplete-suggestions-list');
// add the suggestions list to the suggestions div
suggestionsDiv.appendChild(suggestionsList);
}
// get the suggestions list within the suggestions div
var suggestionsList = suggestionsDiv.querySelector('.autocomplete-suggestions-list');
// empty the suggestions list
suggestionsList.innerHTML = '';
// add the suggestions to the suggestions list
suggestions.forEach(function(suggestion, index) {
// only show up to 5 suggestions
if (index < 5) {
// create a button element for the suggestion
var button = document.createElement('input');
button.type = 'button'
// set the inner HTML of the button to the suggestion
button.value = suggestion;
button.onclick = function(e){
input.value = e.target.value;
suggestionsDiv = document.querySelector('.autocomplete-suggestions');
suggestionsDiv.parentElement.removeChild(suggestionsDiv);
let name = document.getElementById('nameInput').value;
let country = document.getElementById('countryInput').value;