-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
320 lines (295 loc) · 11.3 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
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
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://cdn.jsdelivr.net/gh/ismyrnow/leaflet-groupedlayercontrol@gh-pages/dist/leaflet.groupedlayercontrol.min.js"></script>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/ismyrnow/leaflet-groupedlayercontrol@gh-pages/dist/leaflet.groupedlayercontrol.min.css"/>
<style>
html, body {
height: 100%;
padding: 0;
margin: 0;
}
#map {
width: 100%;
height: 100%;
}
</style>
<style>
.legend {
padding: 4px 6px;
font: 12px Arial, Helvetica, sans-serif;
border-left:2px solid #666666;
border-right:2px solid #666666;
border-top:2px solid #666666;
border-bottom:2px solid #666666;
background: white;
background: rgba(255, 255, 255, 0.8);
line-height: 22px;
color: #555;
}
.legend h4 {
text-align: center;
font-size: 14px;
margin: 2px 12px 8px;
color: #777;
}
.legend span {
position: relative;
bottom: 3px;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin: 0 8px 0 0;
opacity: 1;
}
.legend i.icon {
background-size: 18px;
background-color: rgba(255, 255, 255, 1);
}
.box{
position: absolute;
font: 18px Arial, Helvetica, sans-serif;
top: 0;
z-index: 9999;
text-align: center;
width: 255px;
left: 50%;
margin-left: -75px; /* half of the width */
background-color:white;
}
.note {
padding: 2px 4px;
font: 12px Arial, Helvetica, sans-serif;
border-left:2px solid #666666;
border-right:2px solid #666666;
border-top:2px solid #666666;
border-bottom:2px solid #666666;
background: white;
background: rgba(255, 255, 255, 0.8);
line-height: 22px;
color: #555;
}
.note h4 {
text-align: left;
font-size: 12px;
margin: 2px 12px 8px;
color: #777;
}
</style>
</head>
<body>
<div class="box">Layer loading may be delayed after selection due to large files</div>
<div id="map"></div>
<script type="text/javascript">
//Carto tiles attribution and URL
var osmLink = '<a href="http://openstreetmap.org">OpenStreetMap</a>';
var osmAttrib = '© ' + osmLink;
var cartoLink = '<a href="http://cartodb.com/attributions">CartoDB</a>';
var cartoURL = 'https://{s}.basemaps.cartocdn.com/light_all/{z}/{x}/{y}{r}.png';
//publication placeholder
var placeholderLink = '<a href="http://openstreetmap.org">Placeholder link to publication</a>';
var cartoAttrib = '© ' + osmLink + ' © ' + cartoLink + ' ' + placeholderLink;
//USGS tiles attribution and URL
var USGSURL = 'https://basemap.nationalmap.gov/arcgis/rest/services/USGSImageryOnly/MapServer/tile/{z}/{y}/{x}';
var USGSAttrib = 'Tiles courtesy of the <a href="https://usgs.gov/">U.S. Geological Survey</a>' + placeholderLink;
//Creation of map tiles
var cartoMap = L.tileLayer(cartoURL, {attribution: cartoAttrib});
var USGSMap = L.tileLayer(USGSURL, {attribution: USGSAttrib,
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'});
//geojson files
var pc16Url = 'https://spatialepidemiology.github.io/SACData/assets/pc_tr16_tr.json';
var pc19Url = 'https://spatialepidemiology.github.io/SACData/assets/pc_tr19_tr.json';
var sc16Url = 'https://spatialepidemiology.github.io/SACData/assets/sc_tr16_tr.json';
var sc19Url = 'https://spatialepidemiology.github.io/SACData/assets/sc_tr19_tr.json';
// choropleth styles
function getColor1(d) {
return d > 300 ? '#fde725' :
d > 250 ? '#90d743' :
d > 200 ? '#35b779' :
d > 150 ? '#21918c' :
d > 100 ? '#31688e':
d > 50 ? '#443983':
d >= 0 ? '#440154':
'#666666';
}
function style1(feature) {
return {
fillColor: getColor1(feature.properties.Composite_P2P_Ratio_2016),
color: 'black',
opacity: 0.3,
weight: 0.3,
fillOpacity: 0.5
};
}
function style2(feature) {
return {
fillColor: getColor1(feature.properties.Composite_P2P_Ratio_2019),
color: 'black',
opacity: 0.3,
weight: 0.3,
fillOpacity: 0.5
};
}
function getColor2(d) {
return d > 300 ? '#fde725' :
d > 250 ? '#90d743' :
d > 200 ? '#35b779' :
d > 150 ? '#21918c' :
d > 100 ? '#31688e':
d > 50 ? '#443983':
d >= 0 ? '#440154':
'#666666';
}
function style3(feature) {
return {
fillColor: getColor2(feature.properties.Car_P2P_Ratio_2016),
color: 'black',
opacity: 0.3,
weight: 0.3,
fillOpacity: 0.5
};
}
function style4(feature) {
return {
fillColor: getColor2(feature.properties.Car_P2P_Ratio_2019),
color: 'black',
opacity: 0.3,
weight: 0.3,
fillOpacity: 0.5
};
}
//adding map
var map = L.map('map',{layers: [cartoMap]}).setView([41.4, -81.7], 8.5);
//defining geojson layers
var pc16LayerComp = L.geoJson(null,{style:style1, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var pc19LayerComp = L.geoJson(null,{style:style2, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var sc16LayerComp = L.geoJson(null,{style:style1, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var sc19LayerComp = L.geoJson(null,{style:style2, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var pc16LayerCar = L.geoJson(null,{style:style3, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var pc19LayerCar = L.geoJson(null,{style:style4, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var sc16LayerCar = L.geoJson(null,{style:style3, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
var sc19LayerCar = L.geoJson(null,{style:style4, onEachFeature: function (f, l) {
l.bindPopup('<pre>'+JSON.stringify(f.properties,null,' ').replace(/[\{\}"]/g,'')+'</pre>');
}});
//adding geojsons to map
$.getJSON(pc16Url, function(data) {
pc16LayerComp.addData(data);
});
$.getJSON(pc19Url, function(data) {
pc19LayerComp.addData(data);
});
$.getJSON(sc16Url, function(data) {
sc16LayerComp.addData(data);
});
$.getJSON(sc19Url, function(data) {
sc19LayerComp.addData(data);
});
$.getJSON(pc16Url, function(data) {
pc16LayerCar.addData(data);
});
$.getJSON(pc19Url, function(data) {
pc19LayerCar.addData(data);
});
$.getJSON(sc16Url, function(data) {
sc16LayerCar.addData(data);
});
$.getJSON(sc19Url, function(data) {
sc19LayerCar.addData(data);
});
//creating grouped overlayers
var groupedOverlays = {
"Primary Care": {
"2016 Composite": pc16LayerComp,
"2019 Composite": pc19LayerComp,
"2016 Car": pc16LayerCar,
"2019 Car": pc19LayerCar
},
"Specialty Care": {
"2016 Composite": sc16LayerComp,
"2019 Composite": sc19LayerComp,
"2016 Car": sc16LayerCar,
"2019 Car": sc19LayerCar
}
};
//defining base layers for control
var baseLayers = {
"Carto Light": cartoMap,
"USGS Imagery": USGSMap
};
//options for base and grouped layers
var options = {
exclusiveGroups: ["Primary Care", "Specialty Care"],
groupCheckboxes: true,
collapsed: false
};
//layer control
var layers = L.control.groupedLayers(baseLayers, groupedOverlays, options);
layers.addTo(map);
var selectedOverlay = null;
function updateSelectedOverlay(layer) {
setTimeout(function() {
if (selectedOverlay) map.removeLayer(selectedOverlay);
selectedOverlay = layer;
}, 1);
}
map.on('overlayadd', function(event) {
updateSelectedOverlay(event.layer)
});
map.on('overlayremove', function(event) {
selectedOverlay = null;
});
//scale control
L.control.scale({imperial: true, metric: true}).addTo(map);
//legend options
var legend = L.control({ position: "bottomright"});
//adding legend to map
legend.onAdd = function(map) {
var div = L.DomUtil.create("div", "legend");
div.innerHTML += "<h4>Spatial provider-to-population ratio</h4>";
div.innerHTML += '<i style="background: #440154"></i><span><50 per 100k population</span><br>';
div.innerHTML += '<i style="background: #443983"></i><span>50-99 per 100k population</span><br>';
div.innerHTML += '<i style="background: #31688e"></i><span>100-149 per 100k population</span><br>';
div.innerHTML += '<i style="background: #21918c"></i><span>150-199 per 100k population</span><br>';
div.innerHTML += '<i style="background: #35b779"></i><span>200-249 per 100k population</span><br>';
div.innerHTML += '<i style="background: #90d743"></i><span>250-299 per 100k population</span><br>';
div.innerHTML += '<i style="background: #fde725"></i><span>300+ per 100k population</span><br>';
div.innerHTML += '<i style="background: #666666"></i><span>Missing (code:-9999)</span><br>';
return div;
};
legend.addTo(map);
//note
var note = L.control({ position: "bottomleft"});
//adding note to map
note.onAdd = function(map) {
var div2 = L.DomUtil.create("div", "note");
div2.innerHTML += "<h4>Note: Missingness due to zero population in tract<br>(e.g., national/state parks, airports, lakes, etc.)</h4>";
return div2;
};
note.addTo(map);
</script>
</body>
</html>