-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwnvSlevMap.html
980 lines (849 loc) · 39.5 KB
/
wnvSlevMap.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title>West Nile Virus (WNV) and St. Louis Encephalitis (SLEV) In California's Vulnerable Communities</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<!-- Style sheet for Mapbox GL -->
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.css' rel='stylesheet' />
<!-- Style sheet for google fonts -->
<link href='//fonts.googleapis.com/css?family=Vollkorn' rel='stylesheet' type='text/css'>
<!-- Style sheet for Assembly-->
<link href="https://api.mapbox.com/mapbox-assembly/v0.23.2/assembly.min.css" rel="stylesheet">
<!-- Style sheet for JQuery UI-->
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<!-- Style sheet for Mapbox GL Geocoder-->
<link rel='stylesheet'
href='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.3.0/mapbox-gl-geocoder.css'
type='text/css' />
<style>
body {
margin: 0;
padding: 0;
background: #3f3f3f;
font-family: Sans-Serif;
}
p {
padding: 6px 10%;
margin: 0 auto;
width: 80%;
}
#map {
width: 80%;
height: 900px;
margin: 10px auto;
border: solid;
border-color: #d3d3d3;
border-width: thin;
}
header {
padding: 25px 10%;
font-size: 1.5em;
}
h1 {
text-align: center;
margin-top: 18px;
color: #d3d3d3;
font-weight: bold;
font-size: 1.25em;
}
a {
text-decoration: underline
}
footer {
padding: 6px 10%;
margin: 0 auto;
width: 80%;
color: #d3d3d3;
}
footer h1 {
font-size: 1.25em;
}
p {
font-size: 1em;
color: #d3d3d3;
margin-top: 18px;
}
/* WNV Hex Layer Radio */
#layer-radio1 {
font-family: Sans-Serif;
line-height: 20px;
}
#layer-radio1 input:checked+.radio {
color: #006d2c;
}
/* SLEV Hex Layer Radio */
#layer-radio2 {
font-family: Sans-Serif;
line-height: 25px;
margin: 10px 0 0 0;
}
#layer-radio2 input:checked+.radio {
color: #045a8d;
}
/* WNV Point Layer Switch */
#layer-switch1 {
font-family: Sans-Serif;
line-height: 20px;
}
#layer-switch1 input:checked+.switch {
background-color: #ffffb3;
border-color: #000000;
}
#layer-switch1 input:checked+.switch::after {
background-color: #000000;
}
/* SLEV Point Layer Switch */
#layer-switch2 {
font-family: Sans-Serif;
line-height: 25px;
margin: 10px 0 0 0;
}
#layer-switch2 input:checked+.switch {
background-color: #8dd3c7;
border-color: #000000;
}
#layer-switch2 input:checked+.switch::after {
background-color: #000000;
}
#wnv-hex-legend {
background-color: #d3d3d3;
border-radius: 3px;
top: 10px;
right: 10px;
font: 12px/20px 'Sans-Seriff';
padding: 10px;
position: absolute;
z-index: 1;
}
#wnv-hex-legend h4 {
margin: 0 0 10px;
font-size: 1em;
color: #000000;
text-align: center;
}
#wnv-hex-legend div span {
border-radius: 50%;
display: inline-block;
height: 10px;
margin-right: 5px;
width: 10px;
color: #000000;
}
#slev-hex-legend {
background-color: #d3d3d3;
border-radius: 3px;
top: 10px;
right: 10px;
font: 12px/20px 'Sans-Seriff';
padding: 10px;
position: absolute;
z-index: 1;
}
#slev-hex-legend h4 {
margin: 0 0 10px;
font-size: 1em;
color: #000000;
text-align: center;
}
#slev-hex-legend div span {
border-radius: 50%;
display: inline-block;
height: 10px;
margin-right: 5px;
width: 10px;
}
#year-slider {
position: absolute;
bottom: 50px;
left: 15px;
z-index: 700;
color: #d3d3de;
background-color: #d3d3d3;
}
#year-slider h2 {
font-size: 1.25em;
text-align: center;
bottom: 40px;
position: absolute;
font-family: Sans-Serif;
}
#accordion {
position: absolute;
top: 1px;
left: 5px;
font-size: 1em;
width: 12%;
z-index: 700;
}
.ui-state-active,
.ui-widget-content .ui-state-active,
.ui-widget-header .ui-state-active,
a.ui-button:active,
.ui-button:active,
.ui-button.ui-state-active:hover {
border: 1px solid #000000;
background: #545454;
}
.map-overlay {
font-family: 'Vollkorn';
background-color: #fff;
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.10);
border-radius: 3px;
position: absolute;
width: auto;
top: 500px;
left: 10px;
padding: 10px;
display: none;
z-index: 700;
}
.mapboxgl-popup {
font-family: Sans-Serif;
max-width: 250px;
}
td,
th {
text-align: center;
color: #d3d3d3;
}
caption {
color: #d3d3d3;
}
#wnv-circle {
width: 15px;
height: 15px;
border-radius: 50%;
background: #ffffb3;
border: 1px solid #000000;
margin-top: 2px;
margin-left: 7px;
}
#slev-circle {
width: 15px;
height: 15px;
border-radius: 50%;
background: #8dd3c7;
border: 1px solid #000000;
margin-top: 6px;
margin-left: 6px;
}
.footnote {
margin-top: 12px;
font-size: 80%;
line-height: 1.4em;
}
.table {
margin-top: 18px;
margin: 0 auto;
width: 60%;
}
</style>
</head>
<body>
<header>
<h1>West Nile Virus (WNV) and St. Louis Encephalitis (SLEV) In California (2003-2018)</h1>
<h2></h2>
</header>
<div id='map'>
<div id="accordion">
<h3>Hex Layers</h3>
<div>
<label id='layer-radio1' class='radio-container'>
<input name='radio-basic' id='radio1' value='wnv-hex' type='radio' checked>
<div class='radio mr6'></div>
WNV Hex Layer
</label>
<label id='layer-radio2' class='radio-container'>
<input name='radio-basic' id='radio2' value='slev-hex' type='radio'>
<div class='radio mr6'></div>
SLEV Hex Layer
</label>
</div>
<h3>Point Layers</h3>
<div>
<!-- Switch Toggle (WNV) -->
<label id='layer-switch1' class='switch-container'>
<input type='checkbox' id='switch1' value='WNV' />
<div class='switch switch--l mr6'></div>
WNV <span class='dot' id='wnv-circle'></span>
</label>
<!-- Switch Toggle (SLEV) -->
<label id='layer-switch2' class='switch-container'>
<input type='checkbox' id='switch2' value='SLEV' />
<div class='switch switch--l mr6'></div>
SLEV <span class='dot' id='slev-circle'></span>
</label>
</div>
</div>
<div id='wnv-hex-legend' class='legend'>
<h4>WNV Detections <br>2003 - 2018</h4>
<div><span style='background-color: #edf8fb'></span>1</div>
<div><span style='background-color: #ccece6'></span>18</div>
<div><span style='background-color: #99d8c9'></span>56</div>
<div><span style='background-color: #66c2a4'></span>114</div>
<div><span style='background-color: #2ca25f'></span>215</div>
<div><span style='background-color: #006d2c'></span>340</div>
</div>
<!-- SLEV Hex Legend Div -->
<div id='slev-hex-legend' class='legend'>
<h4>SLEV Detections <br>2003 - 2018</h4>
<div><span style='background-color: #edf8fb'></span>1</div>
<div><span style='background-color:#bdc9e1'></span>4</div>
<div><span style='background-color: #74a9cf'></span>12</div>
<div><span style='background-color: #2b8cbe'></span>30</div>
<div><span style='background-color: #045a8d'></span>100</div>
</div>
<div id='map-overlay' class='map-overlay'></div>
<!-- Div of slider which is disabled on first load -->
<div class='range' id=year-slider>
<h2>Positive Detections By Year: <label id='active-year'>2018</label></h2>
<input id='slider' class='row' type='range' min='2003' max='2018' step='1' value='2018' />
</div>
</div>
<h1>About The Map</h1>
<p>
This map shows the distribution of positive detections for <a target="_blank"
href="https://www.cdc.gov/westnile/index.html">West Nile Virus (WNV)</a> and <a target="_blank"
href="https://www.cdc.gov/sle/index.html">St. Louis Encephalitis Virus
(SLEV)</a> for
mosquito pool and bird specimens in California between 2003 and 2018 and was created using <a target="_blank"
href="https://docs.mapbox.com/mapbox-gl-js/overview/">
Mapbox GL JS</a>.
Hexbin layers were used to represent both viruses to show density of positive detections in
mosquito pool and bird specimens. Individual point layers for each virus are also available for display
along with information
about each point of detection. West Nile Virus (WNV) and St. Louis
encephalitis Virus (SLEV) are "arthropod-borne flaviviruses" that have a presence in Californa (Oyer,
Beckham, Tyler 433 <a target="_blank"
href='https://www.sciencedirect.com/science/article/pii/B9780444534880000201'>'Handbook of Clinical
Neurology: Chapter 20 - West Nile and St. Louis encephalitis viruses</a>, 2014). WNV is a well known
commodity at this point and typically catches local news headlines when the virus has been found in a
deceased bird or a mosquito pool has tested positive, but there has been a reemergence of SLEV in
California. This reemergence began in 2015 after a long period without detection.<sup>*</sup>
Both viruses can be found throughout California and typically cycle
between mosquitoes and birds. Infection in humans is a byproduct of living in close proximity to both
hosts (birds)
and vectors (mosquitoes) for WNV and SLEV. Most infections of WNV and SLEV in humans are asymptomatic
and result in mostly flu-like symptoms,
but in a small number of cases those infected "develop neuroinvasive infection (meningitis,
encephalitis, and myelitis)
that can cause significant illness and death" (Oyer, Beckham, Tyler).
</p>
<p class='footnote'>* Diana A. Singh, Maria L. Salas, Robert E. Snyder, Oliver Oyler, Sarah Skallet,
Tina Feisli, Chris Preas, and Jill Hacker. <i>The Reemergence of St. Louis Encephalitis Virus In
California.</i> Poster presented at California Department of Public Health, Richmond, California
</p>
<h1>About The Data</h1>
<p>
The California county boundary data comes from the Census Bureau's
<a target="_blank" href=https://www.census.gov/geographies/mapping-files/time-series/geo/tiger-line-file.html">
Tiger Line/Shape Files</a> website. West Nile Virus and St. Louis Encephalitis data were scraped from the <a
target="_blank" href="https://legacy-maps.calsurv.org/">California Vectorborne Disease Surveillance Map
Gateway</a>.
Cleaned data and Jupyter notebooks used to clean the data can be found in the map's GitHub <a target="_blank"
href="https://github.com/bazini627/wnvSlevMap">
repo</a>.
</p>
<h1>Do We See WNV and SLEV Positive Detections More In California' s Vulnerable Census Tracts?</h1>
<p>
An analysis was performed on this WNV and SLEV data to determine whether there may be higher numbers
of positive detections in California's highly vulnerable census tracts among the mosquito pool and
bird
samples collected. The CDC has released data files for 2010, 2014, and 2016 where it has determined
which census tracts
may be the most vulnerable to events such as natural disasters or disease outbreaks. A simple
point-in-polygon analysis was performed using
<a target="_blank" href="https://www.postgresql.org/">PostgreSQL</a> and <a target="_blank"
href="https://postgis.net/">PostGIS</a> within a <a target="_blank"
href="https://docs.docker.com/">Docker</a> container
to determine how many of the positive detections for given years fall within
the CDC determined vulnerable
census tracts. In order to look at the most vulnerable census tracts and what points may fall within
these
tracts, a <a target="blank" href="https://svi.cdc.gov/">CDC Social Vulnerability Index</a> value of
.75 or higher was used. All commands for the installation of a PostgreSQL/PostGIS docker container,
along
with commands used for the point-in-polygon analysis, can be found <a target="_blank"
href="https://github.com/bazini627/nmpFinalProject/blob/master/data/README.md">
here</a>.
</p>
<p>
In 2010, of the 8048 census tracts in California, 2001 had a CDC SVI value
greater than or equal to .75. This means that about a quarter of all California census tracts were deemed
highly vulnerable
according to the CDC. There were also 1041 positive detections of WNV across California in 2010 for mosquito
pools
and bird specimens. Looking at how many of these detections occurred in highly vulnerable census tracts, we
see that there were 287
positive detections within these census tracts. Given these values this means that ~28% of positive
detections for
mosquito pool and bird specimens for WNV occurred within highly vulnerable census tracts.
</p>
<p>
2014 saw the CDC determine that 2003 of California's census tracts were highly vulnerable, a slight increase
in vulnerable census tracts compared to 2010 which had 2001 highly vulnerable census tracts. Even with the
slight increase, about a quarter of California's census tracts were deemed highly vulnerable. California
also saw 3550 positive detections for WNV in 2014 for mosquito pools and bird specimens. Of these positive
detections, 528 occurred in California's highly vulnerable census tracts. With these values we see that ~15%
of California's positive detections among mosquito pools and bird specimens occurred within highly
vulnerable census tracts.
</p>
<p>
In 2016 the CDC classified 1995 of California's census tracts as highly vulnerable, which is still around a
quarter of all census tracts.Positive detections for WNV in 2016 for mosquito pool and bird specimens were
2527. Of these 2527 positive detections, 426 occurred in California's highly vulnerable census tracts. With
these values we see that ~17% of California's positive detections among mosquito pools and bird specimens
occurred within highly vulnerable census tracts.
</p>
<p>
SLEV was relatively dormant for quite some time in California until its reemergence in 2015. Since
there is no data for the previous years,
2016 is the only year we can look at for SLEV to determine whether detections fell
disproportionately in highly vulnerable census tracts.
Remember that in 2016 the CDC classified
1995 of the census tracts in California
as highly vulnerable, about a quarter of all census tracts. There were 186 positive
detections for SLEV in mosquito pools and bird
specimens in California in 2016. The number of positive detections that occurred in highly
vulnerable census tracts was 122. Of all
positive detections, ~66% occurred within census tracts that were deemed highly vulnerable by
the CDC. Without data for previous or ensuing years it's difficult to determine any sort of pattern
with regards to SLEV detections for mosquito pools and
bird specimens falling within highly vulnerable census tracts.
</p>
<p>
If we look across 2010, 2014, and 2016 for WNV in California, 2010 started with a high of ~28% of
detections occurring within highly
vulnerable census tracts with a considerable decline going into 2014 (~15% of detections) and a
slight increase in
2016 (~17% detections). What could account for
this decline? Education efforts may have been ramped up during the years following 2010, along with
greater mosquito control efforts. Could there be an environmental explanation for the decline?
In <a target="_blank" href="https://academic.oup.com/jme/article/42/2/134/878837">"Drought-Induced
Amplification and Epidemic Transmission of West Nile
Virus in Southern Florida"</a>, Shamana, Day, and Stieglitz argue that periods of prolonged
spring drought lead to greater exposure between
birds (hosts) and mosquitoes (vectors) which in turn has the potential for greater amplification of
WNV. In California, 2014 - 2016 were
exceptional <a target="_blank" href="https://www.drought.gov/drought/states/california">drought</a>
years and this environmental cause for
the decline would not seem to hold.
</p>
<table class='table'>
<caption><b>WNV Detections As % Of Total Detections By SVI Range</b></caption>
<thead>
<tr>
<th style="text-align: center; vertical-align: middle;">Year</th>
<th style="text-align: center; vertical-align: middle;">SVI 0 - .24 as % of Total Detections
</th>
<th style="text-align: center; vertical-align: middle;">
SVI .25 - .49 as % of Total Detections
</th>
<th style="text-align: center; vertical-align: middle;">
SVI .50 - .74 as % of Total Detections
</th>
<th style="text-align: center; vertical-align: middle;">
SVI >=.75 as % of Total Detections
</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: center; vertical-align: middle;">2010</td>
<td style="text-align: center; vertical-align: middle;">20.9</td>
<td style="text-align: center; vertical-align: middle;">22.9</td>
<td style="text-align: center; vertical-align: middle;">28.6</td>
<td style="text-align: center; vertical-align: middle;">27.6</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;">2014</td>
<td style="text-align: center; vertical-align: middle;">32.8</td>
<td style="text-align: center; vertical-align: middle;">31.1</td>
<td style="text-align: center; vertical-align: middle;">21.2</td>
<td style="text-align: center; vertical-align: middle;">14.9</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: middle;">2016</td>
<td style="text-align: center; vertical-align: middle;">29.3</td>
<td style="text-align: center; vertical-align: middle;">30.5</td>
<td style="text-align: center; vertical-align: middle;">23.3</td>
<td style="text-align: center; vertical-align: middle;">16.9</td>
</tr>
<tr>
</tbody>
<tfoot>
<td colspan="5">* Points that fell within census tracts with uncalculatable SVI values were
dropped (2 points
dropped for 2010, 9 points dropped for 2014, and 12 points dropped for 2016)</td>
</tfoot>
</table>
<p>
How do detections look when taking into account other census tracts within the index?
One thing that we do see across these years is that highly vulnerable census tracts do not make up
the majority of areas where positive
detections occurred. We see that those tracts that that are part of the mid to mid-high range of the
CDC's index make up a greater percentage
of the positive detections. Unfortunately, these same comparisons could not be made SLEV given its
reemergence
in 2015 and the most recent SVI data files from the CDC are for 2016. For 2014 and 2016, it's the
low to mid range census tracts that make
up the index that have the greatest percentages of WNV detections. While we may not see the majority
of positive detections for WNV in
highly vulnerable census tracts among mosquito pool and bird specimens, there is still potential
that these highly vulnerable census tracts
may be burdened with a higher percentage of the human cases of WNV that occur and is an area for
further study. Residents of highly vulnerable
census tracts may need to travel to census tracts that are less vulnerable, which may also have a
higher percentage of positive detections as seen in
2014 and 2016, and their line of work may expose them to mosquitoes more so than in their home
census tract.
With regards to SLEV, one area of possible study would be its slow creep north from 2015 - 2018
which can be seen in the map when using the year slider to
visualize the point data. It starts off in 2015 solely in Riverside county and then begins its
expansion north in the ensuing years.
</p>
<footer>
Map Authored By: <a target="_blank" href="https://bazini627.github.io">Matthew Bacinskas</a> on 6/16/19
</footer>
<!-- Mapbox GL source -->
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.45.0/mapbox-gl.js'></script>
<!-- Mapbox GL Geocoder source -->
<script src='https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-geocoder/v4.3.0/mapbox-gl-geocoder.min.js'>
</script>
<!-- Assembly source -->
<script async defer src="https://api.mapbox.com/mapbox-assembly/v0.23.2/assembly.js"></script>
<!--Source for latest jquery with subresource integrity enabled -->
<script src="https://code.jquery.com/jquery-3.4.0.min.js"
integrity="sha256-BJeo0qm959uMBGb65z40ejJYGSgR7REI4+CW1fNKwOg=" crossorigin="anonymous"></script>
<!-- Jquery UI source-->
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
$(function () {
$("#accordion").accordion();
});
mapboxgl.accessToken =
'pk.eyJ1IjoiYmF6aW5pNjI3IiwiYSI6ImNqdXhuMXFmMjBvdmMzemxqdHhsMzJvbDcifQ.gHwEMfos0CNbKkYbOtd95w'; // ¯\_(ツ)_/¯
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/dark-v9',
center: [-120.38, 37.98],
zoom: 5.5
});
// Overlay that will hold our county name
var overlay = document.getElementById('map-overlay');
// Declare popup to be used later for layers
var popUp = new mapboxgl.Popup({
closeButton: false
});
// Default to hiding SLEV Hex Layer legend since layer is inactive and slider
$('#slev-hex-legend').hide();
$('.range').hide()
map.on('load', function () {
console.log(map.getZoom())
// CA County Layer
map.addSource('Counties', {
type: 'vector',
url: 'mapbox://bazini627.cvxgh4hd'
});
map.addLayer({
'id': 'Counties',
'type': 'fill',
'source': 'Counties',
'layout': {
'visibility': 'visible'
},
'paint': {
'fill-opacity': .2,
'fill-outline-color': '#d3d3d3',
},
'source-layer': 'caCountiesNoChannelIslands-85jvh9',
});
// WNV Layer
map.addSource('WNV', {
type: 'vector',
url: 'mapbox://bazini627.cjwmn01mm0dig2ioloansfs76-6v4gr'
});
map.addLayer({
'id': 'WNV',
'type': 'circle',
'source': 'WNV',
'layout': {
'visibility': 'none',
},
'paint': {
'circle-color': '#ffffb3',
'circle-radius': [
'interpolate', ['linear'],
['zoom'],
// zoom <= 5.5 radius will be 2.5px
5.5, 2.5,
// zoom >= 8 radius will be 4px
8, 4
]
},
'source-layer': 'wnv_2003_2018_cleaned',
});
// Start off only displaying WNV data for 2018
map.setFilter('WNV', ['==', ['number', ['get', 'year']], 2018]);
// SLEV Layer
map.addSource('SLEV', {
type: 'vector',
url: 'mapbox://bazini627.cjvy2k76g02co2inf0onudfgu-8mnpi'
});
map.addLayer({
'id': 'SLEV',
'type': 'circle',
'source': 'SLEV',
'layout': {
'visibility': 'none',
},
'paint': {
'circle-color': '#8dd3c7',
'circle-radius': [
'interpolate', ['linear'],
['zoom'],
// zoom <= 5.5 radius will be 2.5px
5.5, 2.5,
// zoom >= 8 radius will be 4px
8, 4
]
},
'source-layer': 'sle_2015_2018_cleaned',
});
// Start off only displaying WNV data for 2018
map.setFilter('SLEV', ['==', ['number', ['get', 'year']], 2018])
// WNV Hex Bin Layer
map.addSource('wnv-hex', {
type: 'geojson',
data: './data/wnv2003_2018_cleaned_hex.geojson'
});
map.addLayer({
'id': 'wnv-hex',
'type': 'fill',
'source': 'wnv-hex',
'layout': {
'visibility': 'visible'
},
'paint': {
'fill-color': [
'interpolate',
['linear'],
['get', 'wnv'],
1, '#edf8fb', // Jenks breaks
18, '#ccece6',
56, '#99d8c9',
114, '#66c2a4',
215, '#2ca25f',
340, '#006d2c',
],
'fill-opacity': [
'interpolate', ['linear'],
['zoom'],
// Full opacity at <= 5.5
5.5, 1,
// Some transparency so can see below hexagon >= 6
6, .5
],
'fill-outline-color': 'black'
},
});
// SLEV Hex Bin Layer
map.addSource('slev-hex', {
type: 'geojson',
data: '/data/slev2015_2018_cleaned_hex.geojson'
});
map.addLayer({
'id': 'slev-hex',
'type': 'fill',
'source': 'slev-hex',
'layout': {
'visibility': 'none'
},
'paint': {
'fill-color': [
'interpolate',
['linear'],
['get', 'slev'], // Natural Breaks
1, '#f1eef6',
4, '#bdc9e1',
12, '#74a9cf',
30, '#2b8cbe',
100, '#045a8d',
],
'fill-opacity': [
'interpolate', ['linear'],
['zoom'],
// Full opacity zoomed out
5.5, 1,
// Some transparency so can see below hexagon
6, .5
],
'fill-outline-color': 'black'
}
});
map.addLayer({
'id': 'CountiesHighlghted',
'type': 'line',
'source': 'Counties',
'source-layer': 'caCountiesNoChannelIslands-85jvh9',
'paint': {
'line-color': 'yellow',
'line-width': 2,
'line-opacity': 1,
},
"filter": ['in', 'NAME', '']
});
// Mouse over to highlight county
map.on('mousemove', 'Counties', function (e) {
// Change to a pointer
map.getCanvas().style.cursor = 'pointer';
// Short hand for hovered feature
var feature = e.features[0];
// Filter on NAME (county) in the tileset
map.setFilter('CountiesHighlghted',
['in', "NAME", feature.properties.NAME]
);
});
// Reset things once mouse has left polygon
map.on('mouseleave', 'Counties', function () {
map.getCanvas().style.cursor = '';
map.setFilter('CountiesHighlghted', ['in', 'NAME', '']);
});
// Function within varible to get mouseenter to work with both WNV and SLEV layers to be used below with map.on
var pointerEnter = function (e) {
// Query all the rendered points in the view
var features = map.queryRenderedFeatures(e.point, {
layers: ['WNV', 'SLEV']
});
// Shorthand for hovered feature
var pointFeature = e.features[0];
// Change the cursor to a point to notify user some interactivity may be available
map.getCanvas().style.cursor = 'pointer';
// Empty overlay that will eventually hold the county name
overlay.innerHTML = '';
// Make overlay text bold
var infoContent = document.createElement('strong');
// Allow newline ('/r/n') in textContent
infoContent.setAttribute('style', 'white-space: pre;');
// Content of overlay
infoContent.textContent = 'Collection Details\r\n';
infoContent.textContent += `County: ${pointFeature.properties.county}\r\n`;
infoContent.textContent += `City: ${pointFeature.properties.city}\r\n`;
infoContent.textContent += `Specimen Type: ${pointFeature.properties.spectype}\r\n`;
infoContent.textContent += `Virus: ${pointFeature.properties.virus}\r\n`;
infoContent.textContent += `Collection Date(s): ${pointFeature.properties.date}\r\n`;
// Add the content to the overlay
overlay.appendChild(infoContent);
overlay.style.display = 'block'
}
var pointerLeave = function (e) {
// Query all the rendered points in the view
var features = map.queryRenderedFeatures(e.point, {
layers: ['WNV', 'SLEV']
});
// Change the cursor to a point to notify user some interactivity may be available
map.getCanvas().style.cursor = '';
overlay.style.display = 'none';
}
map.on('mouseenter', 'WNV', pointerEnter)
map.on('mouseenter', 'SLEV', pointerEnter)
map.on('mouseleave', 'WNV', pointerLeave)
map.on('mouseleave', 'SLEV', pointerLeave)
// Array of toggle ids to loop through
var toggleableLayerIds = ['switch1', 'switch2'];
// Loop through the toggle ids and link it to a layer
for (var i = 0; i < toggleableLayerIds.length; i++) {
var toggleElement = document.getElementById(toggleableLayerIds[i]);
toggleElement.onclick = function (e) {
// Looks at visibilty property declared above in map.addLayer'
var visibility = map.getLayoutProperty(this.value, 'visibility');
// If property is visible then a click will remove the layer from being displayed
if (visibility === 'visible') {
map.setLayoutProperty(this.value, 'visibility', 'none');
}
// If clicking a layer and the property isn't visible then it's one that was previously turned off and should be reactivated
else {
map.setLayoutProperty(this.value, 'visibility', 'visible');
if (this.value == 'WNV' || this.value == 'SLEV') {
map.setLayoutProperty('wnv-hex', 'visibility', 'none')
map.setLayoutProperty('slev-hex', 'visibility', 'none')
$('input[type=radio]').prop('checked', false);
}
}
}
}
// Switcher for the hex layer radios
$('input[type=radio]').click(function () {
if (this.value === 'wnv-hex') {
map.setLayoutProperty('slev-hex', 'visibility', 'none');
map.setLayoutProperty('wnv-hex', 'visibility', 'visible');
map.setLayoutProperty('WNV', 'visibility', 'none')
map.setLayoutProperty('SLEV', 'visibility', 'none')
$('input[id=switch2]').prop('checked', false); // WNV
$('input[id=switch3]').prop('checked', false); //SLEV
$('#wnv-hex-legend').show();
$('#slev-hex-legend').hide();
} else {
map.setLayoutProperty('wnv-hex', 'visibility', 'none');
map.setLayoutProperty('slev-hex', 'visibility', 'visible');
map.setLayoutProperty('SLEV', 'visibility', 'none')
map.setLayoutProperty('WNV', 'visibility', 'none')
$('input[id=switch2]').prop('checked', false); // WNV
$('input[id=switch3]').prop('checked', false); //SLEV
$('#slev-hex-legend').show();
$('#wnv-hex-legend').hide();
}
});
// For slider funcionality
document.getElementById('slider').addEventListener('input', function (e) {
var year = parseInt(e.target.value);
//console.log(year)
// Update map with appropriate year
map.setFilter('SLEV', ['==', ['number', ['get', 'year']], year]);
map.setFilter('WNV', ['==', ['number', ['get', 'year']], year]);
// Update year in slider
document.getElementById('active-year').innerText = year;
});
// Disable/Enable the slider depending on what header is clicked in the accordion
$("h3").on("click", function () {
var $id = $(this).attr("id");
var activeRadio = $('input[name=radio-basic]:checked');
var activeRadioValue = $('input[name=radio-basic]:checked').val();
var activeToggle = $('input[type=checkbox]:checked')
// 'ui-id-3 means the point Layer header in accordion has been clicked
if ($id == 'ui-id-3') {
// Show slider since point layer is clicked
$('.range').show();
// Hide the hex layer legend
$('#' + activeRadioValue + '-legend').hide();
// Remove the hex layer
map.setLayoutProperty(activeRadioValue, 'visibility', 'none')
// Set hex radio to unchecked
activeRadio.prop('checked', false);
// Activate the WNV layer
map.setLayoutProperty('WNV', 'visibility', 'visible')
// Switch the WNV toggle
$('input[id=switch1]').prop('checked', true);
}
// Otherwise the hex layer header has been clicked
else {
// Disable slider
$('.range').hide()
// Remove active point layer (or both if active)
map.setLayoutProperty('WNV', 'visibility', 'none')
map.setLayoutProperty('SLEV', 'visibility', 'none')
// Set toggle position to off
activeToggle.prop('checked', false);
// Activate the WNV layer
map.setLayoutProperty('wnv-hex', 'visibility', 'visible')
// Activate WNV Radio
$('input[id=radio1]').prop('checked', true);
// Add WNV Hex Legend
$('#wnv-hex-legend').show();
}
});
});
</script>
</body>
</html>