-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
237 lines (228 loc) · 6.36 KB
/
index.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
<html><head>
<title>COVID19 by county</title>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script src="counties.json"></script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<style>
.loading-label {
background-color: transparent;
border: transparent;
box-shadow: none;
font-size: 32px;
text-align: center;
}
</style>
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-161411893-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-161411893-1');
</script>
<script src="leaflet-slider.js"></script>
<link rel="stylesheet" href="leaflet-slider.css"/>
</head><body>
<div id="map" style="height: 100%"></div>
<script language="javascript">
var map = L.map('map').setView([38, -95], 5);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
L.Control.Watermark = L.Control.extend({
onAdd: function(map) {
var theDiv = L.DomUtil.create('div');
theDiv.style.fontSize = "14px";
theDiv.innerHTML = "<strong>COVID19 cases by county</strong><br><a href=\"https://github.com/SciFiDryer/COVID19ByCounty\">Project page</a><br>County data from <a href=\"https://coronadatascraper.com\">coronadatascraper.com</a><br>Visualization by Matt Jamesson<br><span style=\"font-size: 10px; font-style: italic;\">Accuracy of data not guaranteed</span>";
theDiv.style.backgroundColor = "#ffffff";
theDiv.style.opacity = ".75";
theDiv.style.padding = "5px";
theDiv.align = "center";
return theDiv;
},
});
var loading = new L.Marker([40, -100], {
icon: new L.DivIcon({
html: 'Loading data for past and present cases<br>this may take a while',
iconSize: L.point(600,50),
className: "loading-label"
})
});
loading.addTo(map);
var loadingVisible = true;
L.control.watermark = function(opts) {
return new L.Control.Watermark(opts);
}
L.control.watermark({ position: 'topright' }).addTo(map);
var xhr = new XMLHttpRequest();
xhr.open('GET', "https://coronadatascraper.com/timeseries-byLocation.json", true);
xhr.responseType = 'json';
var dateArr = [];
var firstRun = true;
var markerGroup = L.layerGroup().addTo(map);
var countiesTmp = null;
xhr.onload = function()
{
var status = xhr.status;
if (status === 200)
{
var i = 0;
countycases = xhr.response;
getDates();
slider = L.control.slider(function(value) {
showCasesOnDate(dateArr[value]);
}, {
max: dateArr.length-1,
value: dateArr.length-2,
step: 1,
size: '300px',
orientation:'horizontal',
id: 'slider',
position: "topright",
increment: true,
logo: "Spread History",
getValue: function(value){
return dateArr[value];
}
}).addTo(map);
}
};
xhr.send();
function getDates()
{
for (x in countycases)
{
for (y in countycases[x])
{
if (y == "countryName" && countycases[x][y] == "United States")
{
if (countycases[x].level == "state")
{
for (date in countycases[x].dates)
{
lastDate = date;
dateArr.push(date);
}
}
}
}
if (countycases[x].countryName == "United States" && countycases[x].state != null && countycases[x].county != null)
{
if (firstRun)
{
firstRun = false;
for (date in countycases[x].dates)
{
lastDate = date;
dateArr.push(date);
}
}
}
}
}
function showCasesOnDate(theDate)
{
markerGroup.clearLayers();
lastDate = theDate;
countiesTmp = counties.features.slice();
for (x in countycases)
{
if (countycases[x].countryName == "United States" && countycases[x].dates[lastDate] != undefined)
{
var fips = countycases[x].locationID.substring(countycases[x].locationID.indexOf("fips"));
addCountyCases(fips, countycases[x].dates[lastDate].cases);
}
//fixes shannon county glitch
/*addCountyCases("fips:46113", 0);
if (countycases[x].country == "United States")
{
if (countycases[x].dates[lastDate] != undefined && countycases[x].featureId != undefined)
{
addCountyCases(countycases[x].featureId, countycases[x].dates[lastDate].cases);
}
}*/
}
if (loadingVisible)
{
map.removeLayer(loading);
}
}
function addCountyCases(fips, numCases)
{
var i;
for (i = 0; i < countiesTmp.length; i++)
{
var fipsId = fips.substring(5);
if (fipsId == countiesTmp[i].properties.GEO_ID.substring(9))
{
var properties = generateProperties(countiesTmp[i].properties.NAME + " " + countiesTmp[i].properties.LSAD, numCases);
var theStyle = {"color" : properties.color, "weight" : 0};
var marker = L.geoJSON(countiesTmp[i], {style: theStyle, onEachFeature: function onEachFeature(feature, layer){
layer.on('click', function(e) {
window.open("county.html?" + fipsId, "_blank");
});
}});
marker.bindTooltip(properties.popupContent);
//marker.addTo(map);
marker.addTo(markerGroup);
countiesTmp.splice(i,1);
}
}
}
function generateProperties(countyName, numCases)
{
var popupContent = countyName + ": no reported cases";
var color = "#00ff00";
if (numCases >= 1)
{
popupContent = countyName + ": " + numCases + " reported case";
}
//make plurl if needed
if (numCases > 1)
{
popupContent = popupContent + "s";
}
if (numCases >= 1)
{
popupContent = popupContent + "<br><i>Click to view detailed historic stats for county</i>";
}
if (numCases > 0 && numCases <= 5)
{
color = "#ddff00";
}
if (numCases > 5 && numCases <= 10)
{
color = "#ffdd00";
}
if (numCases > 10 && numCases <= 20)
{
color = "#ffaa00";
}
if (numCases > 20 && numCases <= 50)
{
color = "#ff7500";
}
if (numCases > 50 && numCases <= 100)
{
color = "#ff4000";
}
if (numCases > 100 && numCases <= 500)
{
color = "#ff2500";
}
if (numCases > 500 && numCases <=1000)
{
color = "#ff1500";
}
if (numCases > 1000)
{
color = "#850000";
}
return {"color" : color, "popupContent": popupContent};
}
</script>
</body>