-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmap.js
More file actions
1352 lines (1230 loc) · 49.9 KB
/
map.js
File metadata and controls
1352 lines (1230 loc) · 49.9 KB
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
// map colour template https://colorbrewer2.org/#type=diverging&scheme=RdGy&n=6
const allPlaces = {
// ----------------below is hospital------------
'type': 'FeatureCollection',
'features': [
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'West Glasgow Ambulatory Care Hospital',
'description': 'Dalnair Street, Yorkhill, Glasgow, G3 8SJ',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2938739471248937,55.867256985521522]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'Glasgow Royal Infirmary',
'description': '84 Castle Street Glasgow, G4 0SF',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2356463582927404,55.864024756437402]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'Lightburn Hospital',
'description': '966 Carntyne Road Glasgow, G32 6NB',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.1655381667529241,55.86063283653624]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'Stobhill Hospital',
'description': '133 Balornock Road, Glasgow G21 3UW',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2198419991089509,55.892890610013694]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'Queen Elizabeth University Hospital',
'description': '1345 Govan Road, Glasgow, G51 4TF',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3381034300292072,55.862640821216985]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'Gartnavel General Hospital',
'description': '1053 Great Western Road, Glasgow, G12 0YN',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3127174194733016,55.883216859970162]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'hospital',
'title': 'New Victoria Hospital',
'description': '55 Grange Road, Glasgow, G42 9LL',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2633809258889528,55.828412820195524]
}
},
// ----------------below is clinic---------------------
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Baillieston Health Centre',
'description': '20 Muirside Road Glasgow, G69 7AD',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.1161653981145605,55.849487588781244]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Bridgeton Health Centre',
'description': '201 Abercromby Street Glasgow, G40 2DA',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2278003615973603,55.852648320863352]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Castlemilk Health Centre',
'description': '71 Dougrie Dr, Glasgow G45 9AW',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2349393130987778,55.805745704800472]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Govan Health Centre',
'description': '5 Drumoyne Road Glasgow, G51 4BJ',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3264733829402076,55.860305482412116]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Govanhill Health Centre',
'description': '233 Calder St, Glasgow G42 7DR',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.258361870703709,55.83730541461324]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Maryhill Health and Care Centre',
'description': '51 Gairbraid Avenue Maryhill Glasgow G20 8FB',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2928819004793013,55.890035506233687]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'New Gorbals Health and Care Centre',
'description': '2 Sandiefield Road Glasgow G5 9AB',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2529930098194768,55.848399491843111]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Parkhead Health Centre',
'description': '1251 Duke St, Parkhead, Glasgow, G31 5NZ',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.1934693216518326,55.85224133177212]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Pollok Health Centre',
'description': '21 Cowglen Road Glasgow, G53 6EQ',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3462211640754163,55.822249109708707]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Possilpark Health and Care Centre',
'description': '99 Saracen Street, Glasgow, G22 5AP',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.254685568084426,55.881177092348992]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Shettleston Health Centre',
'description': '420 Old Shettleston Road Glasgow, G32 7JZ',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.1698317370450013,55.852737587569663]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Possilpark Health and Care Centre',
'description': '99 Saracen Street, Glasgow, G22 5AP',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.254685568084426,55.881177092348992]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Shields Health and Care Centre',
'description': '80 McCulloch Street, Glasgow, G41 1NX',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2709318757054575,55.844939484269844]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Springburn Health Centre',
'description': '200 Springburn Way Glasgow, G21 1TR',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2286562382947182,55.882682398274142]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Townhead Health Centre',
'description': '16 Alexandra Parade, Glasgow G31 2ES',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2342350009444658,55.866257756890036]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Woodside Health and Care Centre',
'description': '891 Garscube Rd, Glasgow G20 7ET',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2709489951999444,55.87970153060121]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Pollokshaws Clinic',
'description': '35 Well Grn, Shawlands, Glasgow G43 1RR',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2960784606523816,55.826179529261935]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Netherton LD Assessment Centre',
'description': '19 Blackwood Street, Anniesland Glasgow, G13 1AL',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3313438890092471,55.894387164635987]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Sandy Road Clinic',
'description': '547 Dumbarton Rd, Glasgow G11 6HU',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3150962126200625,55.870535703260146]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Glenkirk Resource Centre',
'description': '129 Drumchapel Road Glasgow, G15 6PX',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.3585084986682432,55.905805273894316]
}
},
{
'type': 'Feature',
'properties': {
'icon': 'clinic',
'title': 'Fernbank St Clinic',
'description': '194 Fernbank Street Glasgow G22 6BD',
},
'geometry': {
'type': 'Point',
'coordinates': [-4.2340758659084372,55.886764255565993]
}
},
]
};
// Map initialization
mapboxgl.accessToken = 'pk.eyJ1IjoienlwaGVyMTEwNCIsImEiOiJjbWF5OWg0bGUwNjFzMmxxemo4enM0NWIzIn0.OSmBViJ_-9Hu8EBdqkE6xA';
const isMobile = window.innerWidth <= 768;
const defaultzoom = isMobile ? 8.5 : 10;
const map = new mapboxgl.Map({
container: 'map', // container ID
style: 'mapbox://styles/zypher1104/cmc4xqeom020h01qw3day5uki', // style URL
center: [-4.255578834832815,55.851466907382745], // starting position
zoom: defaultzoom// starting zoom
});
// Add FullscreenControl
map.addControl(new mapboxgl.FullscreenControl(),'bottom-left');
// Add geocoder
map.addControl(
new MapboxGeocoder({
accessToken: mapboxgl.accessToken,
mapboxgl: mapboxgl
}),
'top-left'
);
// Layer configuration - including polygons
const layerConfig = {
'hospital': { name: 'Hospitals',
iconUrl: 'images/hospital.png',
type: 'symbol'},
'clinic': {
name: 'Clinics',
type: 'circle',
color: '#f76659'
},
'Drive_Acc': {
name: 'Index (Driving Mode)',
type: 'polygon',
fillColor: '#88c999',
strokeColor: '#111'
},
'Drive_Service': {
name: 'Driving Service Area',
type: 'polygon',
fillColor: '#999999',
strokeColor: '#111',
defaultVisible: false // layer is turned off when the web page first loads
},
'Walk_Acc': {
name: 'Index (Walking Mode)',
type: 'polygon',
fillColor: '#88c999',
strokeColor: '#111',
},
'Walk_Service': {
name: 'Walking Service Area',
type: 'polygon',
fillColor: '#999999',
strokeColor: '#111',
defaultVisible: false
},
'Inaccess': {
name: 'Underserved Area (Ai=0)',
type: 'polygon',
fillColor: '#E74C3C',
strokeColor: '#111',
defaultVisible: false
},
};
// Function to load polygon GeoJSON (Drive Access)
async function loadPolygonData() {
try {
// Replace 'polygons.geojson' with your actual file name
const response = await fetch('layers/Drive_Access.geojson');
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const polygonData = await response.json();
return polygonData;
} catch (error) {
console.error('Error loading polygon data:', error);
return null;
}
}
// Load my second polygon GeoJSON (service area (Driving mode))
async function loadDriveServiceData() {
try {
const response = await fetch('layers/Drive_servicearea.geojson');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return await response.json();
} catch (error) {
console.error('Error loading Drive_Service polygon data:', error);
return null;
}
}
// Load walking access polygon GeoJSON
async function loadWalkAccData() {
try {
const response = await fetch('layers/Walk_Access.geojson');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return await response.json();
} catch (error) {
console.error('Error loading Walk_Acc polygon data:', error);
return null;
}
}
// Load walking service area polygon GeoJSON
async function loadWalkServiceData() {
try {
const response = await fetch('layers/Walk_servicearea.geojson');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return await response.json();
} catch (error) {
console.error('Error loading Walk_Service polygon data:', error);
return null;
}
}
// Load neighbourhood with 0 accessibility index polygon
async function loadUnderservedData() {
try {
const response = await fetch('layers/Inaccess.geojson');
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
return await response.json();
} catch (error) {
console.error('Error loading Inaccess polygon data:', error);
return null;
}
}
map.on('load', async () => {
// Load custom images for each marker type
const imageUrls = {
'hospital': 'images/hospital.png',
'clinic': 'images/hospital2.png',
'music': './images/music-icon.png'
};
// Load all images
const imagePromises = Object.keys(imageUrls).map(iconType => {
return new Promise((resolve) => {
map.loadImage(imageUrls[iconType], (error, image) => {
if (error) {
console.error(`Failed to load ${iconType} image:`, error);
resolve(null);
} else {
map.addImage(`${iconType}-icon`, image);
resolve(iconType);
}
});
});
});
// Load all polygon data
const driveAccData = await loadPolygonData();
const driveServiceData = await loadDriveServiceData();
const walkAccData = await loadWalkAccData();
const walkServiceData = await loadWalkServiceData();
const UnderservedData = await loadUnderservedData();
// Wait for all images to load, then add layers
Promise.all(imagePromises).then(() => {
// Add point data source
map.addSource('places', {
'type': 'geojson',
'data': allPlaces
});
// Add driving polygon data sources and layers
if (driveAccData) {
map.addSource('drive-acc-polygon-areas', {
'type': 'geojson',
'data': driveAccData
});
const polygonConfig = layerConfig['Drive_Acc'];
// polygon layer (fill colour)
map.addLayer({
'id': 'drive-acc-polygons-fill',
'type': 'fill',
'source': 'drive-acc-polygon-areas',
'paint': {
'fill-color': [
'interpolate',
['linear'],
['get', 'Ai'],
0.000083, '#7b3294',
0.000602, '#c2a5cf',
0.004616, '#e7d4e8',
0.005803, '#a6dba0',
0.022, '#008837'
],
// polygon opacity
'fill-opacity': 0.4
},
'layout': {
'visibility': 'visible'
}
});
// 1st polygon stroke
map.addLayer({
'id': 'drive-acc-polygons-stroke',
'type': 'line',
'source': 'drive-acc-polygon-areas',
'paint': {
'line-color': '#111',
'line-width': 0.3,
'line-opacity': 0.2
},
'layout': {
'visibility': 'visible'
}
});
}
// 2nd polygon (service area (driving)) setting - HIDDEN BY DEFAULT
if (driveServiceData) {
const serviceConfig = layerConfig['Drive_Service'];
map.addSource('drive-service-polygon-areas', {
'type': 'geojson',
'data': driveServiceData
});
map.addLayer({
'id': 'drive-service-polygons-fill',
'type': 'fill',
'source': 'drive-service-polygon-areas',
'paint': {
'fill-color': serviceConfig.fillColor,
'fill-opacity': 0.5
},
'layout': {
'visibility': 'none' // Changed from 'visible' to 'none'
}
});
}
// Add walking access polygon layers
if (walkAccData) {
map.addSource('walk-acc-polygon-areas', {
'type': 'geojson',
'data': walkAccData
});
const walkConfig = layerConfig['Walk_Acc'];
// Walking polygon layer (fill colour) - HIDDEN BY DEFAULT
map.addLayer({
'id': 'walk-acc-polygons-fill',
'type': 'fill',
'source': 'walk-acc-polygon-areas',
'paint': {
'fill-color': [
'interpolate',
['linear'],
['get', 'Walk_Ai'],
0, '#7b3294',
0.000338, '#c2a5cf',
0.000668, '#e7d4e8',
0.005018, '#a6dba0',
0.085, '#008837'
],
'fill-opacity': 0.4
},
'layout': {
'visibility': 'none' // Hidden by default to avoid overlap with driving
}
});
// Walking polygon stroke
map.addLayer({
'id': 'walk-acc-polygons-stroke',
'type': 'line',
'source': 'walk-acc-polygon-areas',
'paint': {
'line-color': '#111',
'line-width': 0.3,
'line-opacity': 0.2
},
'layout': {
'visibility': 'none' // Hidden by default
}
});
}
// Add walking service area polygon layers - HIDDEN BY DEFAULT
if (walkServiceData) {
const walkServiceConfig = layerConfig['Walk_Service'];
map.addSource('walk-service-polygon-areas', {
'type': 'geojson',
'data': walkServiceData
});
map.addLayer({
'id': 'walk-service-polygons-fill',
'type': 'fill',
'source': 'walk-service-polygon-areas',
'paint': {
'fill-color': walkServiceConfig.fillColor,
'fill-opacity': 0.5
},
'layout': {
'visibility': 'none' // Hidden by default
}
});
}
if (UnderservedData) {
map.addSource('underserved-polygon-areas', {
'type': 'geojson',
'data': UnderservedData
});
const walkConfig = layerConfig['Inaccess.geojson'];
// underserved polygon layer (fill colour) - HIDDEN BY DEFAULT
map.addLayer({
'id': 'underserved-polygons-fill',
'type': 'fill',
'source': 'underserved-polygon-areas',
'paint': {
'fill-color': [
'interpolate',
['linear'],
['get', 'Inaccess'],
0, '#a6dba0',
1, '#E74C3C'
],
'fill-opacity': 0.4
},
'layout': {
'visibility': 'none' // Hidden by default to avoid overlap with driving
}
});
// underserved polygon stroke
map.addLayer({
'id': 'underserved-polygons-stroke',
'type': 'line',
'source': 'underserved-polygon-areas',
'paint': {
'line-color': '#111',
'line-width': 0.3,
'line-opacity': 0.2
},
'layout': {
'visibility': 'none' // Hidden by default
}
});
}
// Create point layers
Object.keys(layerConfig).forEach(iconType => {
const config = layerConfig[iconType];
const layerId = `${iconType}-markers`;
if (config.type === 'symbol') {
map.addLayer({
'id': layerId,
'type': 'symbol',
'source': 'places',
'filter': ['==', 'icon', iconType],
'layout': {
'icon-image': `${iconType}-icon`,
'icon-size': [
'interpolate',
['linear'],
['zoom'],
10, 0.4,
16, 0.8
],
'icon-anchor': 'bottom',
'icon-allow-overlap': true,
'visibility': 'visible'
}
});
} else if (config.type === 'circle') {
map.addLayer({
'id': layerId,
'type': 'circle',
'source': 'places',
'filter': ['==', 'icon', iconType],
'paint': {
'circle-radius': 5,
'circle-color': config.color || '#FF0000',
'circle-opacity': 0.8,
'circle-stroke-color': '#000000',
'circle-stroke-width': 1
}
});
}
});
setupLayerControls();
setupPopupEvents();
fitMapToBounds(polygonData);
});
function setupLayerControls() {
// This function is now handled by the LayerToggleControl class below
}
function setupPopupEvents() {
// Add click events for point markers
Object.keys(layerConfig).forEach(iconType => {
if (layerConfig[iconType].type !== 'polygon') {
const layerId = `${iconType}-markers`;
map.on('click', layerId, (e) => {
const coordinates = e.features[0].geometry.coordinates.slice();
const { title, description } = e.features[0].properties;
while (Math.abs(e.lngLat.lng - coordinates[0]) > 180) {
coordinates[0] += e.lngLat.lng > coordinates[0] ? 360 : -360;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(`
<div class="popup-title">${title}</div>
<div class="popup-description">${description}</div>
`)
.addTo(map);
});
map.on('mouseenter', layerId, () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', layerId, () => {
map.getCanvas().style.cursor = '';
});
}
});
// Add click events for driving polygons
if (map.getSource('drive-acc-polygon-areas')) {
map.on('click', 'drive-acc-polygons-fill', (e) => {
const coordinates = e.lngLat;
const properties = e.features[0].properties;
// Create popup content showing only selected fields
let popupContent = '<div class="popup-title">Driving Access Area</div>';
if (properties.Post_block !== undefined) {
popupContent += `<div class="popup-description"><strong>Post Block:</strong> ${properties.Post_block}</div>`;
}
if (properties.Shape_Area !== undefined) {
popupContent += `<div class="popup-description"><strong>Shape Area:</strong> ${properties.Shape_Area}</div>`;
}
if (properties.Ai !== undefined) {
popupContent += `<div class="popup-description"><strong>AI Value:</strong> ${properties.Ai}</div>`;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(popupContent)
.addTo(map);
});
map.on('mouseenter', 'drive-acc-polygons-fill', () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'drive-acc-polygons-fill', () => {
map.getCanvas().style.cursor = '';
});
}
// Add click events for walking polygons
if (map.getSource('walk-acc-polygon-areas')) {
map.on('click', 'walk-acc-polygons-fill', (e) => {
const coordinates = e.lngLat;
const properties = e.features[0].properties;
// Create popup content showing only selected fields
let popupContent = '<div class="popup-title">Walking Access Area</div>';
if (properties.Post_block !== undefined) {
popupContent += `<div class="popup-description"><strong>Post Block:</strong> ${properties.Post_block}</div>`;
}
if (properties.Shape_Area !== undefined) {
popupContent += `<div class="popup-description"><strong>Shape Area:</strong> ${properties.Shape_Area}</div>`;
}
if (properties.Walk_Ai !== undefined) {
popupContent += `<div class="popup-description"><strong>Walk AI Value:</strong> ${properties.Walk_Ai}</div>`;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(popupContent)
.addTo(map);
});
map.on('mouseenter', 'walk-acc-polygons-fill', () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'walk-acc-polygons-fill', () => {
map.getCanvas().style.cursor = '';
});
}
// new here !!!!!!!!!!!!!!!!
if (map.getSource('underserved-polygon-areas')) {
map.on('click', 'underserved-polygons-fill', (e) => {
const coordinates = e.lngLat;
const properties = e.features[0].properties;
// Create popup content showing only Post_block
let popupContent = '<div class="popup-title">Underserved Area</div>';
if (properties.Post_block !== undefined) {
popupContent += `<div class="popup-description"><strong>Post Block:</strong> ${properties.Post_block}</div>`;
}
new mapboxgl.Popup()
.setLngLat(coordinates)
.setHTML(popupContent)
.addTo(map);
});
map.on('mouseenter', 'underserved-polygons-fill', () => {
map.getCanvas().style.cursor = 'pointer';
});
map.on('mouseleave', 'underserved-polygons-fill', () => {
map.getCanvas().style.cursor = '';
});
}
}
function fitMapToBounds(polygonData) {
// Fit map to show all features
const bounds = new mapboxgl.LngLatBounds();
// Add point features to bounds
allPlaces.features.forEach(feature => {
bounds.extend(feature.geometry.coordinates);
});
// Add polygon features to bounds
if (polygonData && polygonData.features) {
polygonData.features.forEach(feature => {
if (feature.geometry.type === 'Polygon') {
feature.geometry.coordinates[0].forEach(coord => {
bounds.extend(coord);
});
} else if (feature.geometry.type === 'MultiPolygon') {
feature.geometry.coordinates.forEach(polygon => {
polygon[0].forEach(coord => {
bounds.extend(coord);
});
});
}
});
}
map.fitBounds(bounds, {
padding: { top: 50, bottom: 50, left: 250, right: 50 }
});
}
// Compact Mobile-Friendly Layer Toggle Control
class LayerToggleControl {
constructor() {
this.isExpanded = false;
}
onAdd(map) {
this._map = map;
this._container = document.createElement('div');
this._container.className = 'mapboxgl-ctrl mapboxgl-ctrl-group';
// Check if mobile device
const isMobile = window.innerWidth <= 768;
// Container styling
this._container.style.background = 'rgba(255, 255, 255, 0.95)';
this._container.style.backdropFilter = 'blur(10px)';
this._container.style.borderRadius = '8px';
this._container.style.boxShadow = '0 2px 8px rgba(0,0,0,0.15)';
this._container.style.border = '1px solid rgba(0,0,0,0.1)';
this._container.style.overflow = 'hidden';
this._container.style.transition = 'all 0.3s ease';
if (isMobile) {
this._container.style.maxWidth = '180px';
this._container.style.minWidth = '48px';
this._container.style.width = '48px';
} else {
this._container.style.minWidth = '200px';
this._container.style.width = '240px';
}
// Create header with toggle button
const header = document.createElement('div');
header.style.display = 'flex';
header.style.alignItems = 'center';
header.style.justifyContent = 'space-between';
header.style.padding = '8px 16px';
header.style.background = 'rgba(248, 249, 250, 0.8)';
header.style.borderBottom = '1px solid rgba(0,0,0,0.1)';
header.style.cursor = 'pointer';
header.style.userSelect = 'none';
// Title (hidden on mobile when collapsed)
const title = document.createElement('span');
title.innerHTML = 'Layers';
title.style.fontSize = '14px';
title.style.fontWeight = '600';
title.style.color = '#333';
title.style.whiteSpace = 'nowrap';
const toggleIcon = document.createElement('span');
const cogImage = document.createElement('img');
cogImage.src = 'images/cogwheel.png';
cogImage.style.width = '16px';
cogImage.style.height = '16px';
cogImage.style.display = 'block';
toggleIcon.appendChild(cogImage);
toggleIcon.style.fontSize = '16px';
if (isMobile) {
header.appendChild(toggleIcon);
title.style.display = 'none';
this.titleElement = title;
} else {
header.appendChild(title);
header.appendChild(toggleIcon);
this.isExpanded = true;
}
this.toggleIcon = toggleIcon;
this._container.appendChild(header);
// Create collapsible content
const content = document.createElement('div');
content.style.transition = 'all 0.3s ease';
content.style.overflow = 'hidden';
if (isMobile) {
content.style.maxHeight = '0';
content.style.opacity = '0';
} else {