-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathht-map-251023.html
More file actions
3745 lines (3312 loc) · 141 KB
/
ht-map-251023.html
File metadata and controls
3745 lines (3312 loc) · 141 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
<html lang="en">
<head>
<meta charset="utf-8" />
<title>CMRPC H+T Map</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<!-- Tailwind CSS -->
<script src="https://cdn.tailwindcss.com"></script>
<!-- Mapbox GL JS -->
<script src="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.js"></script>
<link href="https://api.mapbox.com/mapbox-gl-js/v2.15.0/mapbox-gl.css" rel="stylesheet" />
<!--Material UI icons-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons+Outlined" rel="stylesheet">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!-- Roboto font -->
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;600;700&display=swap" rel="stylesheet">
<style>
/* Additional styling to match the original SVG appearance */
.material-icons-outlined {
font-size: 1.25rem;
/* Equivalent to h-5 w-5 */
width: 1.25rem;
height: 1.25rem;
}
/* Critical CSS for performance */
html {
scroll-behavior: smooth;
}
body {
font-display: swap;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
.mapboxgl-popup {
max-width: 150px;
font-family: 'Roboto', sans-serif;
font-size: 0.875rem; /* Tailwind's text-sm */
}
.mapboxgl-popup-content {
background: white;
border-radius: 0.3rem; /* rounded-lg */
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
padding: 1rem;
color: #1f2937; /* text-gray-800 */
}
.mapboxgl-popup-close-button {
font-size: 1.2rem;
top: 0.5rem;
right: 0.5rem;
}
.popup-header {
font-weight: 600; /* font-semibold */
margin-bottom: 0.5rem;
}
.popup-content p {
margin: 0;
line-height: 1.4;
}
#layer-select {
white-space: normal;
height: auto;
min-height: 2.25rem;
line-height: 1.4;
padding-top: 0.5rem;
padding-bottom: 0.5rem;
}
</style>
</head>
<body class="overflow-hidden">
<div class="flex h-screen w-screen">
<!-- Sidebar -->
<div id="sidebar" class="w-80 bg-white border-r border-gray-300 shadow-xl p-4 overflow-y-auto z-10">
<div class="flex flex-col h-full">
<h2 class="text-xl font-semibold mb-5">Central Massachusetts Regional Housing and Transportation Study</h2> <!--set dynamically?-->
<div class="overflow-y-auto flex-grow">
<!-- Layer toggle - add all layers that will be in the dropdown menu -->
<div class="mb-4">
<select id="layer-select" class="w-full border border-gray-300 rounded px-2 py-1">
<option value="" disabled selected>Select layer</option>
<optgroup label="Housing and People">
<option value="ctysds-pctHH">Recent growth (change in households, 2015-2023)</option>
<option value="tracts-medIncome">Median annual household income</option>
<option value="zip-currentZHVI">Typical home price by zip code (2025)</option>
<option value="zip-chZHVI">Change in typical home price by zip code (2020-2025)</option>
<option value="tracts-pctCostBurdenedOwners">Percent of homeowners cost burdened</option>
<option value="tracts-pctCostBurdenedRenters">Percent of renters cost burdened</option>
<option value="tracts-rdAge">Displacement risk of seniors</option>
<option value="tracts-rdRace">Displacement risk of non-white populations</option>
<option value="parcels-landuse">Land use (property class)</option>
<option value="parcels-density">Actual residential density (units per acre)</option>
<option value="tracts-mva">Neighborhood conditions</option>
</optgroup>
<optgroup label="Transportation">
<option value="bg-transport-diversity-layer">Transportation diversity</option>
</optgroup>
<optgroup label="Cost Analysis">
<option value="bg-costs-ownership">Monthly ownership costs</option>
<option value="bg-costs-rental">Monthly rental costs</option>
<option value="bg-costs-transport">Average household monthly transportation costs</option>
<option value="bg-costs-HT-owner">Monthly housing + transportation costs (homeowners)</option>
<option value="bg-costs-HT">Monthly housing + transportation costs (renters)</option>
</optgroup>
<optgroup label="Illustrative Personas">
<option value="bg-costs-2veh-owner">Persona: Costs for a family of 3</option>
</optgroup>
<optgroup label="Suitability Analysis">
<option value="buildable-land">Land without environmental constraints</option>
</optgroup>
<optgroup label="Other">
<option value="admin-layer">Massachusetts tracts</option>
</optgroup>
<!-- <option value="parcels-pctLV">Land Value as Percent of Assessed Value</option>
<option value="parcels-value">Parcel Value Per Acre</option>-->
</select>
</div>
<!-- Legend -->
<div id="legend" class="mt-4 pb-4">
<h3 id="legend-title" class="font-medium mb-2"></h3>
<div id="legend-content" class="space-y-1 text-sm text-gray-700 mb-2">
</div>
<button id="layer-info" class="flex items-center text-sm"><span class="material-icons text-base mr-1">info</span>About this layer</button>
<p id="layer-description" class="mt-1 text-xs text-gray-600 hidden"></p>
</div>
</div>
<!-- Collapsible Overlays Section -->
<div id="overlay-wrapper" class="border-t border-gray-300 w-full mt-auto">
<!-- Header -->
<button
id="overlay-toggle"
class="w-full px-2 py-2 flex items-center justify-between hover:bg-gray-50 text-sm font-medium"
>
<span class="flex items-center gap-1">
<span class="material-icons align-text-bottom">layers</span>
Overlays
</span>
<svg id="overlay-arrow" class="w-4 h-4 transition-transform transform" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
</svg>
</button>
<!-- Hidden content -->
<div id="overlay-content" class="hidden px-2 py-2 space-y-2 bg-white">
<!-- Boundaries Section -->
<div class="text-xs font-semibold text-gray-600 uppercase tracking-wide mt-2 mb-1">Boundaries</div>
<label class="flex items-start text-sm text-gray-700"> <!--for single line overlay labels, please use this label class. Preserves spacing and is slightly different than multi-line labels-->
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="town-layer" checked/>
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">CMRPC community boundaries</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="subregion-central" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Central subregion</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="subregion-north" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">North subregion</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="subregion-northeast" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Northeast subregion</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="subregion-west" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">West subregion</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="subregion-southwest" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Southwest subregion</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="subregion-southeast" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Southeast subregion</span>
</label>
<!-- Transportation Section -->
<div class="text-xs font-semibold text-gray-600 uppercase tracking-wide mt-3 mb-1">Transportation</div>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="bus-stops-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Bus stops</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="train-stops-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Rail stops</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="fair-ped-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Pedestrian quality: fair</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="good-ped-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Pedestrian quality: good</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="fair-transit-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Transportation access: fair</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="good-transit-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Transportation access: good</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="transit-diversity-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Transportation diversity
<button id="transit-diversity-info-btn" class="ml-1 text-gray-500 hover:text-gray-700" style="font-size: 10px;">ⓘ</button>
</span>
</label>
<!-- Zoning Section -->
<div class="text-xs font-semibold text-gray-600 uppercase tracking-wide mt-3 mb-1">Zoning</div>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="mf-byright-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Multifamily allowed by-right</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="mf-specialpermit-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Multifamily allowed by special permit/review</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="exceeds-capacity-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Exceeds zoned density
<button id="exceeds-capacity-info-btn" class="ml-1 text-gray-500 hover:text-gray-700" style="font-size: 10px;">ⓘ</button>
</span>
</label>
<label class="flex items-start text-sm text-gray-700">
<div class="relative">
<input type="checkbox" class="sr-only overlay-toggle peer" value="excess-capacity-layer" />
<div class="w-6 h-3.5 bg-gray-300 rounded-full peer-checked:bg-gray-600 transition-colors"></div>
<div class="absolute top-[2px] left-[2px] w-2.5 h-2.5 bg-white border border-gray-400 rounded-full transition-transform peer-checked:translate-x-[10px]"></div>
</div>
<span class="leading-snug ms-2">Excess capacity by zoning
<button id="excess-capacity-info-btn" class="ml-1 text-gray-500 hover:text-gray-700" style="font-size: 10px;">ⓘ</button>
</span>
</label>
</label>
<!-- Transportation diversity info text -->
<div id="transit-diversity-info" class="hidden mt-3 pt-3 border-t border-gray-200">
<p class="text-xs text-gray-700" style="font-family: Roboto, sans-serif;">
Areas with stronger transportation diversity, shown here, are areas where some everyday trips don't require a car and can be completed on foot, on a bike, or by using transit.
</p>
</div>
<!-- Excess capacity info text -->
<div id="excess-capacity-info" class="hidden mt-3 pt-3 border-t border-gray-200">
<p class="text-xs text-gray-700" style="font-family: Roboto, sans-serif;">
This area either allows multi-family development by-right or by special permit/special review. Current development does not exceed three units per acre. There may be excess capacity for additional units should there be interest in further development or redevelopment.
</p>
</div>
<!-- Exceeds capacity info text -->
<div id="exceeds-capacity-info" class="hidden mt-3 pt-3 border-t border-gray-200">
<p class="text-xs text-gray-700" style="font-family: Roboto, sans-serif;">
This area does not allow multi-family development. Current development patterns, however, exceed a three unit/acre density. It may be worth up-zoning this area should relatively dense development trends continue.
</p>
</div>
</div>
</div>
<!-- Basemap settings toggle - relocate this in the scrollable part (but still have the panel open towards the top)?? -->
<div id="basemap-toggle" class="border-t border-gray-300 pt-2">
<button
class="w-full flex items-center justify-between px-2 py-2 hover:bg-gray-50 text-sm font-medium"
onclick="toggleBasemapSettings()"
>
<span class="flex items-center gap-1">
<span class="material-icons align-text-bottom">settings</span>
Map settings
</span>
<svg id="basemap-arrow" class="w-4 h-4 transform transition-transform" xmlns="http://www.w3.org/2000/svg" fill="none"
viewBox="0 0 24 24" stroke="currentColor">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 9l-7 7-7-7" />
</svg>
</button>
</div>
<!-- Basemap settings panel -->
<div id="basemap-settings" class="hidden mt-2 space-y-3 text-sm text-gray-700">
<div>
<label for="opacity" class="block text-sm font-medium text-gray-700 mb-1">Data layer opacity</label>
<input
id="opacity"
type="range"
min="0"
max="1"
step="0.33"
value="0.66"
class="w-full"
onchange="setLayerOpacity(this.value)"
/>
</div>
<div>
<div>
<label class="block mb-1 font-medium">Basemap style</label>
<div id="basemap-style-thumbnails" class="flex gap-2">
<button data-style="communityscale/cmgicidwh007k01qdauae93b0" class="px-3 py-1 bg-black text-white text-xs rounded hover:bg-gray-800">
Gray
</button>
<button data-style="communityscale/cmgidsjne002c01qne3nf930s" class="px-3 py-1 bg-black text-white text-xs rounded hover:bg-gray-800">
Satellite
</button>
<button data-style="communityscale/cmgidu19b00n301sb0jcihsuk" class="px-3 py-1 bg-black text-white text-xs rounded hover:bg-gray-800">
Light Satellite
</button>
</div>
</div>
</select>
</div>
</div>
<footer class="border-t border-gray-300 px-4 py-3 text-sm text-gray-700 flex items-center gap-3">
<a href="https://communityscale.io" target="_blank" rel="noopener noreferrer">
<img
src="https://communityscale.io/wp-content/uploads/2024/01/white-on-black-with-edges-150x150.png"
alt="CommunityScale logo"
class="h-10 w-10 object-contain rounded"
/>
</a>
<div>
<p class="font-medium">CommunityScale</p>
<p class="text-xs text-gray-500">Scaling community innovation.</p>
</div>
</footer>
</div>
</div>
<!--zoom controls-->
<div id="zoom-controls" class="absolute top-4 right-4 z-10 flex flex-col bg-white shadow rounded overflow-hidden">
<button id="zoom-in" class="p-2 text-xl hover:bg-gray-100 focus:outline-none">+</button>
<button id="zoom-out" class="p-2 text-xl hover:bg-gray-100 focus:outline-none">−</button>
<div class="border-t border-gray-300"></div>
<button id="zoom-home" class="p-2 hover:bg-gray-100 focus:outline-none" onclick="zoomToFullRegion()">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="5" y="7" width="14" height="10" stroke="currentColor" stroke-width="1.5" fill="none"/>
</svg>
</button>
<button id="clear-map" class="p-2 hover:bg-gray-100 focus:outline-none"><span class="material-icons">refresh</span></button>
</div>
<!-- map -->
<div id="map" class="flex-grow"></div>
</div>
<script>
const INITIAL_LOC = [-71.81, 42.21]
const INITIAL_ZOOM = 10 //set initial zoom (zoom levels 9-12 best for cities depending on size)(this is set to 13 to accomodate the tileset that will need to be uploaded via CLI)
const communityScaleGray = "#425A70" //could replace with different accent color, I personally like this branding
//Place specific constants!!
const regionOfInterest = [ //all study area munis/communities
'BARRE',
'BOYLSTON',
'BROOKFIELD',
'BERLIN',
'BLACKSTONE',
'DUDLEY',
'CHARLTON',
'DOUGLAS',
'EAST BROOKFIELD',
'HARDWICK',
'MILLVILLE',
'NORTH BROOKFIELD',
'OXFORD',
'RUTLAND',
'SOUTHBRIDGE',
'SPENCER',
'STURBRIDGE',
'UXBRIDGE',
'WARREN',
'WEBSTER',
'WEST BROOKFIELD',
'AUBURN',
'GRAFTON',
'LEICESTER',
'HOLDEN',
'HOPEDALE',
'MILLBURY',
'MENDON',
'NEW BRAINTREE',
'PRINCETON',
'NORTHBOROUGH',
'NORTHBRIDGE',
'OAKHAM',
'PAXTON',
'SHREWSBURY',
'SUTTON',
'UPTON',
'WEST BOYLSTON',
'WESTBOROUGH',
'WORCESTER'
]
//layer constants/arrays to use later
const dataLayers = [ // all fill data layers need to be listed here
'tracts-medIncome',
'tracts-pctCostBurdenedRenters',
'tracts-pctCostBurdenedOwners',
'bg-costs-HT',
'bg-costs-HT-owner',
'bg-costs-2veh-owner',
'bg-costs-ownership',
'bg-costs-rental',
'bg-costs-transport',
'tracts-rdAge',
'tracts-rdRace',
'ctysds-pctHH',
'zip-currentZHVI',
'zip-chZHVI',
'parcels-landuse',
'buildable-land',
//'parcels-pctLV',
//'parcels-value',
'parcels-density',
"bg-transport-diversity-layer"
//'admin-layer' //not sure if admin layer should be included here
];
const overlayLayers = [ // all overlay layers need to be listed here
"towns-layer",
"bus-stops-layer",
"train-stops-layer",
"transit-diversity-layer",
"fair-transit-layer",
"fair-ped-layer",
"good-transit-layer",
"good-ped-layer",
"subregion-southeast",
"subregion-northeast",
"subregion-central",
"subregion-west",
"subregion-north",
"subregion-southeast",
"mf-byright-layer",
"mf-specialpermit-layer",
"excess-capacity-layer",
"exceeds-capacity-layer"
];
//all palettes here!!
const medIncomePalette = [ //Sequential colorBrewer Purple/Red ramp
'#BFD7FF',
'#9BB1FF',
'#8795F3',
'#4956C5',
'#071A43'
]
const affordabilityPalette = [ //Custom blue-orange-red ramp for affordability
'#82ac21', // Blue for <45%
'#fff290', // Orange for 45-60%
'#ecd731' // Red for >60%
]
// const cbRentersPalette = [ //Sequential colorBrewer GrnBlu ramp
// '#f6eff7',
// '#bdc9e1',
// '#67a9cf',
// '#1c9099',
// '#016c59'
// ]
// const cbOwnersPalette = [ //Sequential colorBrewer BluPur ramp
// '#edf8fb',
// '#b3cde3',
// '#8c96c6',
// '#8856a7',
// '#810f7c'
// ]
const pricePalette = [
'#f1eef6',
'#bdc9e1',
'#74a9cf',
'#2b8cbe',
'#045a8d'
]
const chPricePalette = [
'#ffffcc',
'#c2e699',
'#78c679',
'#31a354',
'#006837'
]
const hhChangePalette = [ //Diverging colorBrewer PurGre ramp
'#762a83',
'#af8dc3',
'#e7d4e8',
'#f7f7f7',
'#d9f0d3',
'#7fbf7b',
'#1b7837'
]
const riskDisplacementPalette = [ //Purple-blue color palette as used in Apex
'#edf8fb',
'#b3cde3',
'#8c96c6',
'#8856a7',
'#810f7c'
]
const landUsePalette = [ //only set this up for custom legends unless there is a way to set inner html of breaks/stops dynamically??
{ key: "R-L", color: "#fffbd7", label: "Low density residential" },
{ key: "R-M", color: "#fff8bf", label: "Medium density residential" },
{ key: "R-H", color: "#fff17f", label: "High density residential" },
{ key: "R-O", color: "#ffab3c", label: "Other housing" },
{ key: "MU-R", color: "#d899dd", label: "Mixed use with residential" },
{ key: "COMM", color: "#df2d83", label: "Commercial" },
{ key: "GR", color: "#d4f088", label: "Greenspace" },
{ key: "IND", color: "#767676", label: "Industrial" },
{ key: "IMP", color: "#f0f420", label: "Improved land" },
{ key: "DEV-R", color: "#cf820f", label: "Developable as residential"},
{ key: "UND", color: "#d5d5d5", label: "Undevelopable"},
{ key: "EXE", color: "#425A70", label: "Exempt" },
{ key: "UNK", color: "#bdc9e1", label: "Unknown" }
]
const buildablePalette = [
{ key: "noSew Built noExempt", color: "#000000", label: "Existing development" },
{ key: "noSew noBuilt noExempt", color: "#ecd731", label: "Buildable, no sewer" },
{ key: "Sew unBuilt noExempt", color: "#6e79dd", label: "Buildable, sewer" }
]
const palettesByLayer = { //leave empty if not needed
'parcels-landuse': landUsePalette,
'buildable-land': buildablePalette,
// 'parcels-ownership': taxCreditPalette,
'tracts-rdAge': [
{ value: 0, color: '#edf8fb', label: 'Relatively low displacement risk' },
{ value: 0.23, color: '#b3cde3', label: 'Somewhat low' },
{ value: 0.46, color: '#8c96c6', label: 'Moderate' },
{ value: 0.71, color: '#8856a7', label: 'Somewhat high' },
{ value: 0.94, color: '#810f7c', label: 'Higher displacement risk' }
],
'tracts-rdRace': [
{ value: 0, color: '#edf8fb', label: 'Relatively low displacement risk' },
{ value: 0.23, color: '#b3cde3', label: 'Somewhat low' },
{ value: 0.46, color: '#8c96c6', label: 'Moderate' },
{ value: 0.71, color: '#8856a7', label: 'Somewhat high' },
{ value: 0.94, color: '#810f7c', label: 'Higher displacement risk' }
],
'bg-costs-2veh-owner': [
{ value: 0, color: '#dce18b', label: 'Likely to spend <45% of income on housing and transportation costs' },
{ value: 0.45, color: '#f97316', label: '45-60% of income' },
{ value: 0.60, color: '#ef4444', label: '>60% of income' }
]
// //best way to match palettes to their respective layers ?? particularly for categorical layers
};
function batchSetFeatureStates({ //batching experiment
data,
source,
sourceLayer,
batchSize = 1000,
delay = 50,
propertyParser = (f) => ({
density: Number(f["DUA"]),
useCode: f["use"],
SiteAddress: f["SiteAddress"],
description: f["UseDesc"]
})
}) {
let i = 0;
function processNextBatch() {
const batch = data.slice(i, i + batchSize);
batch.forEach(f => {
const id = f.LOC_ID?.toString();
if (!id || !f["DUA"]) return; // Skip invalid or missing data
map.setFeatureState(
{ source, sourceLayer, id },
propertyParser(f)
);
});
i += batchSize;
if (i < data.length) {
setTimeout(processNextBatch, delay); // Yield to keep UI responsive
} else {
console.log(`✅ Finished setting feature state for ${data.length} features.`);
}
}
processNextBatch();
}
//let layerSelect; //global definition
mapboxgl.accessToken = 'pk.eyJ1IjoiY29tbXVuaXR5c2NhbGUiLCJhIjoiY21hZ3Y4azlmMDU5YTJqb2NqbzRsa3psbSJ9.eJlBVHcMSB88Czl3ti2i5g';
let map;
const BASEMAP_STYLES = {
gray: 'mapbox://styles/communityscale/cmgicidwh007k01qdauae93b0',
satellite: 'mapbox://styles/communityscale/cmgidsjne002c01qne3nf930s',
lightSatellite: 'mapbox://styles/communityscale/cmgidu19b00n301sb0jcihsuk'
};
function initializeMap(styleKey = 'gray') {
map = new mapboxgl.Map({
container: 'map',
style: BASEMAP_STYLES[styleKey],
center: INITIAL_LOC,
zoom: INITIAL_ZOOM
});
// UTILITY FUNCTIONS
function waitForSourcesToLoad(sourceIds, callback) {
let loadedSources = new Set();
function checkSourceLoaded(e) {
if (sourceIds.includes(e.sourceId)) {
loadedSources.add(e.sourceId);
if (loadedSources.size === sourceIds.length) {
map.off('sourcedata', checkSourceLoaded);
callback();
}
}
}
map.on('sourcedata', checkSourceLoaded);
}
function adjustMapSize() { //idk if needed!!
const sidebarWidth = document.getElementById('sidebar').width;
const mapContainer = document.getElementById('map');
mapContainer.style.marginLeft = `${sidebarWidth}px`;
map.resize();
}
function addSources () {
map.addSource("tracts", {
type: "vector",
url: 'mapbox://communityscale.tracts-2020', //update to stream json source + join!!
promoteId: "GEOID"
})
map.addSource("parcels", {
type: "vector",
url: 'mapbox://communityscale.csy6z5wg', //update to stream json source + join!!
promoteId: "LOC_ID"
})
map.addSource("zips", {
type: 'vector',
url: 'mapbox://emtzot01.963cu3b9',
promoteId: 'ZCTA5'
})
map.addSource("towns", {
type: "vector",
url: "mapbox://emtzot01.4s34saee",
promoteId: "TOWN_ID"
})
map.addSource("communityboundaries", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/communityboundaries.geojson'
})
map.addSource("subregions", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_Tigerlines_Regions_FromCytsds_250820.geojson',
promoteId: "TOWN_ID"
})
map.addSource("bus-stops", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/bus_stops.geojson' //replace with re-projected version??
})
map.addSource("train-stops", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_RailStations_251017.geojson'
})
map.addSource("transit-diversity", {
type: 'geojson',
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/parcels_transportation_diversity_marg_onlytrue_diss.geojson',
promoteId: 'loc_id'
})
map.addSource("ped-quality", {
type: 'geojson',
data: 'CMRPC_ped_quality_dissolved_select_qualities_251020.geojson',
promoteId: 'loc_id'
})
map.addSource("transit-quality-2", {
type: 'geojson',
data: 'CMRPC_transit_quality_dissolved_selected_qualities_251020.geojson',
promoteId: 'loc_id'
})
map.addSource("transit-quality", {
type: 'geojson',
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_transit_quality_dissolved_selected_qualities_251020.geojson',
promoteId: 'fid'
})
map.addSource("mf-byright", {
type: 'geojson',
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_MFByRight_251009.geojson'
})
map.addSource("mf-specialpermit", {
type: 'geojson',
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_MFBySpecialPermit_SpecialReview_251009.geojson'
})
map.addSource("bg-costs", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_bg_costs.geojson',
promoteId: 'GEO_ID_clean'
})
map.addSource("bg-transport-diversity", {
type: 'geojson',
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_bg_transportation_diverse_marg.geojson',
promoteId: 'geoid'
})
map.addSource("buildable", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/buildable6.geojson'
})
map.addSource("excess-capacity", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_DissolvedParcels_ExcessCapacity_251017.geojson'
})
map.addSource("exceeds-capacity", {
type: "geojson",
data: 'https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CMRPC_DissolvedParcels_ExceedsCapacity_251017.geojson'
})
map.addSource("ctysds", {
type: "vector",
url: "mapbox://emtzot01.7fsgy5ln",
promoteId: 'GEOID'
})
// Load median income data without filtering
fetch('https://raw.githubusercontent.com/emtzot/mapSources/main/mass_basicHNA_2023acs_250620.json')
.then(response => response.json())
.then(data => {
data.forEach(f => {
const id = f.GEOID.toString();
map.setFeatureState(
{
source: 'tracts',
sourceLayer: 'tracts',
id: id
},
{
medIncome: f["medIncome"]
}
);
});
});
fetch('https://raw.githubusercontent.com/CommunityScale/CMRPC/main/CMRPC_Parcels_Use_Residensity_251008.json') //batching experiment!
.then(response => response.json())
.then(data => {
batchSetFeatureStates({
data,
source: 'parcels',
sourceLayer: 'CMRPC_Parcels_Cleaned_NoData_251008',
batchSize: 1000, // adjustable
delay: 50, // ms delay between batches
});
})
.catch(err => console.error("Failed to load parcel density data:", err));
// Load CTfilter2 to get valid tract GEOIDs for filtering displacement risk data
let validTractsRD = new Set();
fetch('https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/CTfilter2.geojson')
.then(response => response.json())
.then(filterData => {
console.log('CTfilter2 loaded for displacement risk filtering');
// Build set of valid tract GEOIDs from CTfilter2
const features = filterData.features || filterData;
features.forEach(f => {
const geoid = f.properties?.GEOID || f.GEOID;
if (geoid) {
validTractsRD.add(geoid.toString());
}
});
console.log('Valid tracts for displacement risk:', validTractsRD.size);
// Now load displacement risk data and filter to valid tracts only
return fetch('https://raw.githubusercontent.com/CommunityScale/CMRPC/refs/heads/main/rd_tracts_250731.json');
})
.then(response => response.json())
.then(data => {
let matchedRD = 0;
data.forEach(f => {
const id = f.GEOID.toString(); // Ensure id is a string to match with geometry's geoid
// Only set feature state for valid tracts from CTfilter2
if (validTractsRD.has(id)) {
matchedRD++;
map.setFeatureState(
{
source: 'tracts',
sourceLayer: 'tracts',
id: id
},
{
rd_seniors: Number(f["rd_seniors"]),
rd_nonwhitePops: Number(f["rd_nonWhitePops"])
}
);
}
});
console.log('Displacement risk data loaded for', matchedRD, 'tracts from CTfilter2');
})
.catch(err => console.error('Error loading displacement risk data:', err));
fetch('https://raw.githubusercontent.com/CommunityScale/CMRPC/adc9df09b39883512a5175738efe5ace91ad2917/CMRPC_Tracts_MVA_CostBurden_250828.json')
.then(response => response.json())
.then(data => {
data.forEach(f => {
const id = f.geoid.toString(); // Ensure id is a string to match with geometry's geoid
map.setFeatureState(
{
source: 'tracts',
sourceLayer: 'tracts',
id: id
},
{
pctowned30_23: Number(f["pctowned30_23"]),
pctrent30_23: Number(f["pctrent30_23"]),
mva: (f["class"])
}
)
});
});
}
async function computeStatsFromSource(source_url, property) {
try {
const response = await fetch(source_url);
const data = await response.json();
// Determine structure
let features;
if (data.type === "FeatureCollection" && Array.isArray(data.features)) {
features = data.features;
} else if (Array.isArray(data)) {
// JSON as array of objects (not GeoJSON)
features = data.map(d => ({ properties: d }));
} else if (data.data && Array.isArray(data.data)) {
// Nested JSON with .data
features = data.data.map(d => ({ properties: d }));
} else {
console.warn("Unsupported data format or source is a vector tileset.");
return null;
}
// Extract numeric values
const values = features
.map(f => Number(f.properties[property]))
.filter(v => !isNaN(v))
.sort((a, b) => a - b);
if (values.length < 5) {
console.warn("Not enough valid values to compute breaks.");
return null;
}
// Quantile function
function quantile(arr, q) {
const pos = (arr.length - 1) * q;
const base = Math.floor(pos);
const rest = pos - base;
return arr[base + 1] !== undefined
? arr[base] + rest * (arr[base + 1] - arr[base])
: arr[base];
}
const Q1 = quantile(values, 0.25);
const median = quantile(values, 0.5);
const Q3 = quantile(values, 0.75);
const IQR = Q3 - Q1;
return [median - 1.5 * IQR, Q1, median, Q3, median + 1.5 * IQR];
} catch (err) {
console.error("Failed to compute stats:", err);
return null;
}