-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
1280 lines (1137 loc) · 31.5 KB
/
index.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
mapboxgl.accessToken = 'pk.eyJ1Ijoic2hpaHdlbnd1dHciLCJhIjoiY2poZTMweWFzMHFqMjMwcGMxODB4ZnF2NSJ9.Z26UldBScU4ycC75f24TnA';
let map = new mapboxgl.Map({
container: 'map', // container id
style: 'mapbox://styles/shihwenwutw/ck1myebc70e851co3unmss075', // stylesheet location
center: [121.55244833917465, 25.03793365035355], // starting position [lng, lat]
zoom: 12,
minZoom: 10.75,
maxZoom: 16 // starting zoom
});
let nav = new mapboxgl.NavigationControl();
map.addControl(nav, 'bottom-right');
map.addControl(new mapboxgl.GeolocateControl({
positionOptions: {
enableHighAccuracy: true
},
trackUserLocation: true
}), 'bottom-right');
//Station layer
const source_layer = 'stationWithNum6';
const source_url = "mapbox://" + "shihwenwutw.2f2o2j0c"
//Route layer
const source_layer_2 = 'zzz_shapeAll'
const source_url_2 = "mapbox://" + 'shihwenwutw.9qewrzda'
//HOVER related
// Target the relevant span tags in the station info div
let stationDisplay = document.getElementById('station');
let routeDisplay = document.getElementById('routes');
//FILTER related
// Holds visible features for filtering
let stations = [];
let routes = [];
// Create a popup, but don't add it to the map yet.
let popup = new mapboxgl.Popup({
closeButton: false
});
let filterEl = document.getElementById('feature-filter');
let listingEl = document.getElementById('feature-listing');
let checkBoxEl = document.getElementById('exact');
//selected feature
let value = '';
let filtered = [];
let all_id = [];
let filt_id = [];
let res = [];
let filtered_r = [];
let all_id_r = [];
let filt_id_r = [];
let res_r = [];
//clicked feature
let access = [];
let click = false;
//match type
let exactMatch = document.getElementsByName('matchAnswer')[0].checked;
//direction feature
let direction_button = false;
//features by moveend
let features = [];
let features_routes = [];
function sortChildren(containerSelector, reverse) {
const container = document.querySelector(containerSelector);
const order = reverse ? -1 : 1;
Array.from(container.children)
.sort((a, b) => order * parseInt(a.dataset.position, 10) - order * parseInt(b.dataset.position, 10))
.forEach(element => container.appendChild(element));
// Note you could also conditionally use Array.reverse() instead of the order variable.
}
let edgeEndId = null;
let edgeStartId = null;
function renderListings(features) {
// Clear any existing listings
//console.log('!!');
listingEl.innerHTML = '';
if (radios[0].checked){
if(edgeEndId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeEndId
}, {
edge: false
});
}
if(edgeStartId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeStartId
}, {
edge: false
});
}
edgeEndId = null;
edgeStartId = null;
filteredOnRoutes.forEach(function(feature) {
let stopSeq = '';
let prop = feature.properties;
let stopInfo = prop[value].replace(/"|\[|\]/g,'')
let item = document.createElement('p');
let stopMax = ''
item.textContent = prop.station;
stopInfo.split(',').forEach(function(item){
if(item[0]==='0'){
stopSeq = item.split('-')[1]
stopMax = item.split('-')[2]
}
});
if(stopMax === stopSeq){
edgeEndId = feature.id;
}
if(stopSeq === '1'){
edgeStartId = feature.id;
}
item.setAttribute('data-position', stopSeq);
item.insertAdjacentHTML('beforeend', `<span class="sideList">${stopSeq}</span>`);
item.addEventListener('mouseover', function() {
// Highlight corresponding feature on the map
popup.setLngLat(feature.geometry.coordinates)
.setText(feature.properties.station + ' : ' + feature.properties.routes.replace(/"|\[|\]/g,'').replace(/,/g,', '))
.addTo(map);
});
item.addEventListener('mouseleave',function(){
popup.remove();
});
listingEl.appendChild(item);
});
//sortfilter
sortChildren('#feature-listing',false);
// Show the filter input
//filterEl.parentNode.style.display = 'block';
if(edgeEndId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeEndId
}, {
edge: true
});
}
if(edgeStartId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeStartId
}, {
edge: true
});
}
} else if (radios[1].checked) {
if(edgeEndId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeEndId
}, {
edge: false
});
}
if(edgeStartId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeStartId
}, {
edge: false
});
}
edgeEndId = null;
edgeStartId = null;
filteredOnRoutes.forEach(function(feature) {
let stopSeq = '';
let prop = feature.properties;
let stopInfo = prop[value].replace(/"|\[|\]/g,'')
let item = document.createElement('p');
item.textContent = prop.station;
stopInfo.split(',').forEach(function(item){
if(item[0]==='1'){
stopSeq = item.split('-')[1]
stopMax = item.split('-')[2]
}
});
if(stopMax === stopSeq){
edgeEndId = feature.id;
}
if(stopSeq === '1'){
edgeStartId = feature.id;
}
item.setAttribute('data-position', stopSeq);
item.insertAdjacentHTML('beforeend', `<span class="sideList">${stopSeq}</span>`);
item.addEventListener('mouseover', function() {
// Highlight corresponding feature on the map
popup.setLngLat(feature.geometry.coordinates)
.setText(feature.properties.station + ' : ' + feature.properties.routes.replace(/"|\[|\]/g,'').replace(/,/g,', '))
.addTo(map);
});
item.addEventListener('mouseleave',function(){
popup.remove();
});
listingEl.appendChild(item);
});
//sortfilter
sortChildren('#feature-listing',false);
// Show the filter input
//filterEl.parentNode.style.display = 'block';
if(edgeEndId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeEndId
}, {
edge: true
});
}
if(edgeStartId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeStartId
}, {
edge: true
});
}
} else if (features.length) {
features.forEach(function(feature) {
let prop = feature.properties;
let item = document.createElement('p');
item.textContent = prop.station;
//item.insertAdjacentHTML('beforeend', '<span>'+)
item.addEventListener('mouseover', function() {
// Highlight corresponding feature on the map
popup.setLngLat(feature.geometry.coordinates)
.setText(feature.properties.station + ' : ' + feature.properties.routes.replace(/"|\[|\]/g,'').replace(/,/g,', '))
.addTo(map);
});
item.addEventListener('mouseleave',function(){
popup.remove();
});
listingEl.appendChild(item);
});
if(edgeEndId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeEndId
}, {
edge: false
});
}
if(edgeStartId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeStartId
}, {
edge: false
});
}
// Show the filter input
filterEl.parentNode.style.display = 'block';
} else {
let empty = document.createElement('p');
empty.textContent = 'No results, drag or change words to populate.';
listingEl.appendChild(empty);
// remove features filter
map.setFilter('station-access', ['has', 'routes']);
if(edgeEndId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeEndId
}, {
edge: false
});
}
if(edgeStartId){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: edgeStartId
}, {
edge: false
});
}
edgeEndId = null;
edgeStartId = null;
}
}
function normalize(string) {
return string.trim().toUpperCase();
}
function getUniqueFeatures(array, comparatorProperty) {
let existingFeatureKeys = {};
// Because features come from tiled vector data, feature geometries may be split
// or duplicated across tile boundaries and, as a result, features may appear
// multiple times in query results.
let uniqueFeatures = array.filter(function(el) {
if (existingFeatureKeys[el.properties[comparatorProperty]]) {
return false;
} else {
existingFeatureKeys[el.properties[comparatorProperty]] = true;
return true;
}
});
return uniqueFeatures;
};
//Update Station Feature
function featureUpdates(value, filtered_input){
if(value){
// Filter visible features that don't match the input value.
filtered_input = stations.filter(function(feature) {
let routes = normalize(feature.properties.routes);
let station = normalize(feature.properties.station);
if(exactMatch){
//return value in feature.properties || station.indexOf(value) > -1;
//console.log(value, feature.properties);
return value in feature.properties || value === station;
} else {
return routes.indexOf(value) > -1 || station.indexOf(value) > -1;
}
});
renderListings(filtered_input);
filtered_input.forEach(function(feature){
filt_id.push(feature.id);
});
filt_id = [... new Set(filt_id)];
res = all_id.filter( function(n) { return !this.has(n) }, new Set(filt_id) );
filt_id.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: true
});
});
res.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: false
});
});
} else {
all_id.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: false
});
});
}
};
//Update Route Feature
function featureUpdates_r(value, filtered_input){
if(value){
// Filter visible features that don't match the input value.
filtered_input = routes.filter(function(feature) {
if(exactMatch){
return value === feature.properties.RouteNameZ;
} else {
let routes = normalize(feature.properties.RouteNameZ);
return routes.indexOf(value) > -1;
}
});
//renderListings(filtered);
filtered_input.forEach(function(feature){
filt_id_r.push(feature.id);
});
filt_id_r = [... new Set(filt_id_r)];
res_r = all_id_r.filter( function(n) { return !this.has(n) }, new Set(filt_id_r) );
filt_id_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
select: true
});
});
res_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
select: false
});
});
} else {
all_id_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
select: false
});
});
}
};
//Gether feature id on the map with corresponding routes
let renderListing_click = [];
function featureUpdates_click_id(value, filteredInputPoint, filteredInputLine){
//Station
filteredInputPoint = stations.filter(function(feature) {
let routes = normalize(feature.properties.routes);
let station = normalize(feature.properties.station);
//return routes.indexOf(value) > -1 || station.indexOf(value) > -1;
return value in feature.properties
});
filteredInputPoint.forEach(function(feature){
filt_id.push(feature.id);
renderListing_click.push(feature);
});
filt_id = [... new Set(filt_id)];
renderListing_click = [... new Set(renderListing_click)];
//Route
filteredInputLine = routes.filter(function(feature) {
let routes = normalize(feature.properties.RouteNameZ);
//return routes.indexOf(value) > -1;
return value === feature.properties.RouteNameZ;
});
filteredInputLine.forEach(function(feature){
filt_id_r.push(feature.id);
});
filt_id_r = [... new Set(filt_id_r)];
}
//Generate features except from featureUpdates_click_id
function featureUpdates_res_id(){
res = all_id.filter( function(n) { return !this.has(n) }, new Set(filt_id) );
res_r = all_id_r.filter( function(n) { return !this.has(n) }, new Set(filt_id_r) );
};
//Update feature status
function featureUpdates_click(){
filt_id_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
click: true
});
});
res_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
click: false
});
});
filt_id.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
click: true
});
});
res.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
click: false
});
});
};
let label_colors = document.getElementsByClassName("dir_style");
function OnChangeCheckbox (checkbox) {
if (checkbox.checked) {
//Default check 'both' direction, and black direction buttons
document.getElementById("dir2").checked = true;
for(var i=0; i<radios.length; i++) {
radios[i].disabled=false;
}
for(var i=0; i<label_colors.length; i++) {
label_colors[i].style.color = 'black';
}
//value = '';
//filterEl.value = '';
all_id = [];
filt_id = [];
all_id_r = [];
filt_id_r = [];
stations.forEach(function(feature){
all_id.push(feature.id);
});
routes.forEach(function(feature){
all_id_r.push(feature.id);
});
exactMatch = document.getElementsByName('matchAnswer')[0].checked;
featureUpdates(value,filtered);
featureUpdates_r(value,filtered_r);
}
else {
direction_button = false;
document.getElementById("dir2").checked = true;
for(var i=0; i<radios.length; i++) {
radios[i].disabled=true;
}
for(var i=0; i<label_colors.length; i++) {
label_colors[i].style.color = 'grey';
}
//value = '';
//filterEl.value = '';
all_id = [];
filt_id = [];
all_id_r = [];
filt_id_r = [];
stations.forEach(function(feature){
all_id.push(feature.id);
});
routes.forEach(function(feature){
all_id_r.push(feature.id);
});
exactMatch = document.getElementsByName('matchAnswer')[0].checked;
featureUpdates(value,filtered);
featureUpdates_r(value,filtered_r);
}
}
let radios = document.getElementsByName('direction');
let all_id_dir = [];
let filt_id_dir = [];
let res_id_dir = [];
let filteredOnRoutes = [];
function directionListGenerator(direction, filtered_input){
filteredOnRoutes = [];
filt_id_dir = [];
//Get station with direction value as 0
filtered_input.forEach(function(feature){
let routeDir_text = feature.properties[value].replace(/\[|\]|\"/g,'').split(',');
routeDir_text.forEach(function(info){
if(direction !== ''){
if(info[0]===direction){
filteredOnRoutes.push(feature)
}
} else {
filteredOnRoutes.push(feature)
filteredOnRoutes = [...new Set(filteredOnRoutes)];
}
})
});
renderListings(filteredOnRoutes);
filteredOnRoutes.forEach(function(feature){
filt_id_dir.push(feature.id);
});
res_dir = all_id_dir.filter( function(n) { return !this.has(n) }, new Set(filt_id_dir));
}
function OnChangeRadioBox(checkbox) {
if(value){
all_id_dir = [];
filt_id_dir = [];
res_id_dir = [];
direction_button = true;
stations = features;
stations.forEach(function(feature){
all_id_dir.push(feature.id);
});
let filtered_dir = stations.filter(function(feature) {
let station = normalize(feature.properties.station);
return value in feature.properties || value === station;
});
//Direction (integer, optional):
//去返程 : [0:'去程',1:'返程',2:'迴圈',255:'未知'] ,
for (var i = 0, length = radios.length; i < length; i++) {
if (radios[0].checked) {
directionListGenerator('0',filtered_dir);
break;
} else if (radios[1].checked){
directionListGenerator('1',filtered_dir);
break;
} else if (radios[2].checked){
directionListGenerator('',filtered_dir);
break;
}
}
filt_id_dir.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: true
});
});
res_dir.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: false
});
});
} else {
all_id_dir.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: false
});
});
}
}
const zoomThreshold = 12.75;
map.on('load', function(){
//Route Layer
map.addSource("routes", {
"type": "vector",
"url": source_url_2
});
map.addLayer({
'id': 'station-route',
'type': 'line',
'source': 'routes',
'layout': {
'visibility': 'visible'
},
'source-layer': source_layer_2,
'paint': {
'line-color': [
'case',
['boolean', ['feature-state', 'select'], false],
'#dd3497',
['boolean', ['feature-state', 'click'], false],
'#fd8d3c',
'rgba(0,0,0,0)'
]
}
});
//Station Layers
map.addSource("stations", {
"type": "vector",
"url": source_url
});
//Station Layer in smaller zoom
map.addLayer({
'id': 'station-origin-smallZoom',
'type': 'circle',
'source': 'stations',
'layout':{
'visibility': 'visible'
},
'source-layer': source_layer,
'maxzoom': zoomThreshold,
//'minzoom': 12,
'paint': {
'circle-radius': [
'case',
['boolean', ['feature-state', 'hover'], false],
8,
['boolean', ['feature-state', 'edge'], false],
4,
['boolean', ['feature-state', 'select'], false],
2,
['boolean', ['feature-state', 'clickMain'], false],
4,
['boolean', ['feature-state', 'click'], false],
2,
1
],
'circle-color': [
'case',
['boolean', ['feature-state', 'hover'], false],
'red',
['boolean', ['feature-state', 'edge'], false],
'orange',
['boolean', ['feature-state', 'select'], false],
'#fff700',
['boolean', ['feature-state', 'clickMain'], false],
'red',
['boolean', ['feature-state', 'click'], false],
'#f7fcb9',
'rgba(0,0,0,0)'
],
'circle-stroke-width': [
'case',
['boolean', ['feature-state', 'hover'], false],
1,
['boolean', ['feature-state', 'edge'], false],
1,
['boolean', ['feature-state', 'select'], false],
0.7,
['boolean', ['feature-state', 'clickMain'], false],
1,
['boolean', ['feature-state', 'click'], false],
0.7,
0.3
],
'circle-stroke-color':[
'case',
['boolean', ['feature-state', 'hover'], false],
'black',
['boolean', ['feature-state', 'edge'], false],
'black',
['boolean', ['feature-state', 'select'], false],
'black',
['boolean', ['feature-state', 'clickMain'], false],
'black',
['boolean', ['feature-state', 'click'], false],
'black',
'rgba(0,0,0,0.25)'
],
}
});
//Station Layer in larger zoom
map.addLayer({
'id': 'station-origin-LargeZoom',
'type': 'circle',
'source': 'stations',
'layout':{
'visibility': 'visible'
},
'source-layer': source_layer,
'minzoom': zoomThreshold,
'paint': {
'circle-radius': [
'case',
['boolean', ['feature-state', 'hover'], false],
10,
['boolean', ['feature-state', 'edge'], false],
8,
['boolean', ['feature-state', 'select'], false],
3.5,
['boolean', ['feature-state', 'clickMain'], false],
6,
['boolean', ['feature-state', 'click'], false],
3.5,
3
],
'circle-color': [
'case',
['boolean', ['feature-state', 'hover'], false],
'red',
['boolean', ['feature-state', 'edge'], false],
'orange',
['boolean', ['feature-state', 'select'], false],
'#fff700',
['boolean', ['feature-state', 'clickMain'], false],
'red',
['boolean', ['feature-state', 'click'], false],
'#f7fcb9',
'rgba(0,0,0,0)'
],
'circle-stroke-width': [
'case',
['boolean', ['feature-state', 'hover'], false],
1,
['boolean', ['feature-state', 'edge'], false],
1,
['boolean', ['feature-state', 'select'], false],
0.7,
['boolean', ['feature-state', 'clickMain'], false],
1,
['boolean', ['feature-state', 'click'], false],
0.7,
0.3
],
'circle-stroke-color':[
'case',
['boolean', ['feature-state', 'hover'], false],
'black',
['boolean', ['feature-state', 'edge'], false],
'black',
['boolean', ['feature-state', 'select'], false],
'black',
['boolean', ['feature-state', 'click'], false],
'black',
'rgba(0,0,0,0.25)'
],
}
});
//Feature Source Layer
map.addLayer({
'id': 'station-access',
'type': 'circle',
'source': 'stations',
'layout':{
'visibility': 'visible'
},
'source-layer': source_layer,
'paint': {
'circle-radius': 8,
'circle-color': 'rgba(0,0,0,0)',
'circle-stroke-width': 1,
'circle-stroke-color':'rgba(0,0,0,0)'
}
});
map.on('moveend', function() {
//Get features after 'moveend'
features = [];
features_routes = [];
features = map.queryRenderedFeatures({layers: ['station-access']});
features_routes = map.queryRenderedFeatures({layers: ['station-route']});
//Keep all feature ids in a list
stations = features;
routes = features_routes;
//Get all feature id after moveend
stations.forEach(function(feature){
all_id.push(feature.id);
});
routes.forEach(function(feature){
all_id_r.push(feature.id);
});
//call rednerListing and clean map if the radios, map clicking function
//and search value isn't active
if (features && (!radios[0].checked && !radios[1].checked && !click && !value)) {
// Populate features for the listing overlay.
renderListings(features);
//Clean map
all_id_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
select: false
});
});
all_id.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: false
});
});
all_id_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
click: false
});
});
all_id.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
click: false
});
});
//featureUpdates(value,filtered);
//featureUpdates_r(value,filtered_r);
} else if (!radios[0].checked && !radios[1].checked && !click && value) {
//Update map according to search value while moving map
featureUpdates(value,filtered);
featureUpdates_r(value,filtered_r);
}
//console.log(map.getZoom());
//Update click result only if there is no value in search box
if(!value && click === true){
//Clean map
all_id_r.forEach(function(id){
map.setFeatureState({
source: 'routes',
sourceLayer: source_layer_2,
id: id
}, {
select: false
});
});
all_id.forEach(function(id){
map.setFeatureState({
source: 'stations',
sourceLayer: source_layer,
id: id
}, {
select: false
});
});
renderListing_click = [];
access.forEach(function(routeInStation){