-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
514 lines (411 loc) · 12.9 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
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
<!DOCTYPE html>
<html>
<head>
<title>ATL Child Well-Being Explorer</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="https://fastcdn.org/Papa-Parse/4.1.2/papaparse.min.js"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- Bootstrap Drawer -->
<link rel="stylesheet" type="text/css" href="bootstrap-drawer.min.css">
<style>
html, body {
height:100%;
width:100%;
padding:0px;
margin:0px;
}
#mapid {
height:92%;
width:100%;
padding:0px;
margin:0px;
}
#legend {
width: 300px;
height: 72px;
position: absolute;
bottom: 0px;
left:0px;
right:0px;
margin: 19px auto;
background-color: white;
border-radius: 5px;
box-shadow: 1px 1px 1px rgba(0,0,0,0.4);;
z-index: 100000000;
opacity: 0.9;
color:gray;
}
.box {
display: inline-block;
width: 18%;
height: 22px;
}
.cutoff {
display: inline-block;
text-align: center;
width: 18%;
}
.drawerstyle {
z-index: 1000000000;
}
.zipLabel {
color: gray;
}
.header {
display:table;
background: linear-gradient(#10167f , #06093e);
background-color: #10167f;
box-shadow: 2px 2px 2px rgba(0,0,0,0.4);;
height: 50px;
width:100%;
}
.headerTitle {
display: table-cell;
color:white;
text-align:center;
width:100%;
height:100%;
vertical-align: middle;
font-size:150%;
font-family: 'Roboto', sans-serif;
}
</style>
</head>
<body class="has-drawer">
<div id="drawerExample" class="drawer dw-xs-8 dw-sm-5 dw-md-3 fold drawerstyle" aria-labelledby="drawerExample">
<div class="drawer-controls">
<a href="#drawerExample" data-toggle="drawer" aria-foldedopen="false" aria-controls="drawerExample" class="btn btn-warning btn-sm">Layers</a>
</div>
<div class="drawer-contents">
<div class="drawer-heading">
<h3 class="drawer-title">Layers</h3>
</div>
<ul class="drawer-nav">
<li role="presentation" class="active"><a href="#">Home</a></li>
<li role="presentation"><a href="#">Profile</a></li>
<li role="presentation"><a href="#">Messages</a></li>
</ul>
</div>
</div>
<div class="header">
<div class="headerTitle">
<img src="logoSmall.png" style="width:34px;height:34px;margin-right:5px"></img>
<img src="Perspective.png" style="width:251px;height:23px;margin-top:5px"></img>
</div>
</div>
<div id="mapid">
<div id = "legend">
<div id = "legendHeader" style="text-align:center; height:26px; line-height: 22px;"><b> Child Well Being Index </b></div>
<div class = "box" style="margin-left:16px;"></div><div class = "box"></div><div class = "box"></div><div class = "box"></div><div class = "box"></div>
<div class = "cutoff" style="margin-left:42px;">10</div><div class = "cutoff">20</div><div class = "cutoff">30</div><div class = "cutoff">40</div>
</div>
</div>
<script src="drawer.min.js"></script>
<script>
var map, areas, indicators, indicatorNames = [], cutoffs, agencies;
// let colors = ["#ffffb2", "#fecc5c", "#fd8d3c", "#f03b20", "#bd0026"]; //all red (try it!)
let colors = ["#0E5051", "#4FB6A1", "#E2DCB0", "#E69241", "#CF2E1D"] //green to red
var currentIndicator = "";
var focusAreas = ["Health", "Basic Needs", "Income", "Education", "Homelessness", "Miscellaneous"];
var activeFocusAreas = [];
setupMap();
getAreas();
getAgencies();
function setupMap() {
map = L.map('mapid', {
zoomControl:false,
fullscreenControl: true
}).setView([33.76, -84.37], 9);
map.on('click', function() {
hideDrawer()
});
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token=pk.eyJ1IjoibWFwYm94IiwiYSI6ImNpandmbXliNDBjZWd2M2x6bDk3c2ZtOTkifQ._QA7i5Mpkd_m30IGElHziw', {
maxZoom: 18,
attribution: "",
id: 'mapbox.light'
}).addTo(map);
L.control.zoom({
position: 'topright'
}).addTo(map);
if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
$('.btn-warning').css('margin-top',50+'px')
}
}
function hideDrawer() {
if($('#drawerExample').hasClass('open')) {
$('#drawerExample').drawer('hide');
}
}
function showDrawer() {
// if($('#drawerExample').hasClass('open')) {
$('#drawerExample').drawer('show');
// }
}
function getAreas() {
$.get("Indicators.csv", function (data) {
var csvdata = Papa.parse(data, {header:true,dynamicTyping:true});
indicators = csvdata["data"]
indicators.forEach(function(indicator) {
indicatorNames.push(indicator["Indicator"])
});
setupDrawer()
});
$.get("CWBIndex2.csv", function (data) {
var csvdata = Papa.parse(data, {header:true,dynamicTyping:true});
areas = csvdata["data"]
setIndicator(indicatorNames[0])
getAreaGeometries()
});
}
function getAreaGeometries() {
$.getJSON("zipCodeGeometry.json", function(zipCodeGeometries) {
zipCodeGeometries.forEach(function(zipCodeGeometry) {
areas.forEach(function(area) {
if(area["ZipCode"] == zipCodeGeometry["properties"]["ZIP"]) {
addGeometryToMapForArea(area, zipCodeGeometry);
}
});
});
});
}
function addGeometryToMapForArea(area, geometry) {
area["geojson"] = L.geoJSON(geometry, {
onEachFeature: function(feature, layer) {
// feature.bindTooltip("pooop").openTooltip();
// var tt = L.tooltip({
// sticky:true
// }, feature).addTo(map)
// tt.setText("poops")
}
}).addTo(map);
drawHeatForArea(area)
}
function redrawHeat() {
areas.forEach(function(area) {
drawHeatForArea(area)
});
}
function setIndicator(indicatorName) {
currentIndicator = indicatorName
indicators.forEach(function(indicator) {
if(currentIndicator == indicator["Indicator"]) { //damn, poor naming dude, but its crunch time, this is a hackathon!
updateHeat(currentIndicator,indicator["higherBetter"])
updateLegend(indicator["type"])
}
});
}
function updateHeat(indicator, higherBetter) {
var min=10000,max=-10000;
areas.forEach(function(area) {
if(area[indicator] < min) {
min = area[indicator]
}
if(area[indicator] > max) {
max = area[indicator]
}
});
updateCutoffs(min,max,higherBetter);
areas.forEach(function(area) {
let normalizedIndicator = (area[indicator] - min)/(max - min) //between 0 and 1
if(higherBetter == true) {
area["heat"] = 1 - normalizedIndicator
} else {
area["heat"] = normalizedIndicator
}
});
}
function updateCutoffs(min,max,higherBetter) {
let range = max-min;
let numCutoffs = 6.0;
let increment = range/numCutoffs;
cutoffs = []
for (i=1; i<numCutoffs-1; ++i) {
cutoffs.push(min+i*increment)
}
if(higherBetter) {
cutoffs.reverse();
}
}
function drawHeatForArea(area) {
//heat is always normalized from 0-1
let color = colorForHeat(area["heat"])
area["geojson"].setStyle({
"weight": 2,
"color": color, //stroke
"opacity": 0.6, //stroke
"fillColor": color,
"fillOpacity": 0.6
});
}
function colorForHeat(heat) {
let index = Math.ceil(heat*5)-1;
return colors[index];
}
function updateLegend(type) {
$("#legendHeader").html("<b>" + currentIndicator + "</b>")
var boxes = $(".box")
boxes.each(function(i,box) {
box.style.backgroundColor = colors[i]
})
$(".cutoff").each(function(i,cutoff) {
let value = Math.round( cutoffs[i] * 10) / 10;
if(type == "percent") {
cutoff.innerHTML = value + "%"
} else {
cutoff.innerHTML = value
}
})
}
function setupDrawer() {
var html = "<h4>Focus Areas</h4>";
for (i=0; i<focusAreas.length; ++i) {
html += '<li role="presentation" class = "focusArea"><a href="#">' + focusAreas[i] + '</a></li>';
}
html += "<h4>Child Well Being Index</h4>"
for (i=0; i<indicatorNames.length; ++i) {
html += '<li role="presentation" class = "indicator"><a href="#">' + indicatorNames[i] + '</a></li>';
}
$(".drawer-nav").html(html)
$(".focusArea").click(function() {
toggleFocusArea(event.target.text);
updateCheckMarks();
})
$(".indicator").click(function() {
setIndicator(event.target.text)
redrawHeat()
})
showDrawer()
}
function updateCheckMarks() {
$('.focusArea').each(function(i,obj) {
let focusArea = $(obj).text()
if(focusAreaIsShowing(focusArea)) {
$(obj).html('<li role="presentation" class = "focusArea"><a href="#">' + focusArea + '<span class="glyphicon glyphicon-ok checkmark pull-right"></span></a></li>')
} else {
$(obj).html('<li role="presentation" class = "focusArea"><a href="#">' + focusArea + '</a></li>')
}
})
}
function getAgencies() {
$.getJSON("Agencies.json", function(agenciesJson) {
agencies = agenciesJson;
agencies.forEach(function(agency) {
agency["Marker"] = null;
})
updateCheckMarks();
});
}
function toggleFocusArea(focusArea) {
if(focusAreaIsShowing(focusArea)) {
hideFocusArea(focusArea);
} else {
showFocusArea(focusArea);
}
}
function focusAreaIsShowing(focusArea) {
var isShowing = false;
activeFocusAreas.forEach(function(activeFA) {
if(focusArea == activeFA) {
isShowing = true
}
})
return isShowing;
}
function showFocusArea(focusArea) {
activeFocusAreas.push(focusArea);
var agenciesToShow = getAgenciesForFocusArea(focusArea);
showAgencies(agenciesToShow, focusArea);
}
function hideFocusArea(focusArea) {
let index = activeFocusAreas.indexOf(focusArea)
if (index > -1) {
activeFocusAreas.splice(index, 1);
}
var agenciesToHide = getAgenciesForFocusArea(focusArea);
hideAgencies(agenciesToHide);
}
function getAgenciesForFocusArea(focusArea) {
var agenciesToReturn = [];
agencies.forEach(function(agency) {
agency["FocusAreas"].forEach(function(FA) {
if(FA == focusArea) {
agenciesToReturn.push(agency);
}
});
});
return agenciesToReturn;
}
function iconForFocusArea(focusArea) {
let index = focusAreas.indexOf(focusArea)
var icon = L.icon({
iconUrl: 'markers/' + index + '.png',
iconSize: [26*0.7, 29*0.7],
});
return icon;
}
function showAgencies(agenciesToShow, focusArea) {
for(i=0; i<agenciesToShow.length; ++i) {
let agency = agenciesToShow[i];
if(!agency["Marker"]) {
let lat = agency["Lat"];
let lon = agency["Lon"];
let popup = popupForAgency(agency,lat,lon);
agency["Marker"] = L.marker([lat, lon], {
icon: iconForFocusArea(focusArea)
}).addTo(map).on('click', function onClick(e) {
popup.openOn(map);
});
}
}
}
function hideAgencies(agenciesToHide) {
for(i=0; i<agenciesToHide.length; ++i) {
let agency = agenciesToHide[i];
if(agency["Marker"]) {
map.removeLayer(agency["Marker"]);
agency["Marker"] = null;
}
}
}
function popupForAgency(agency,lat,lon) {
var html ='<div style="font-size:120%;"><b>' + agency["Agency"] + "</b></div>";
html+=agency["Address"] + "<br>" + agency["City"] + ", GA " + agency["ZipCode"] + "<br><br>"
html += "<b>Services</b><br>";
agency["Services"].forEach(function(service) {
html += service + "<br>"
})
html += "<br><b>Focus Areas</b><br>";
agency["FocusAreas"].forEach(function(FA) {
html += FA + "<br>"
})
var popup = L.popup({
maxHeight:220,
maxWidth:220
}).setLatLng([lat,lon]).setContent(html)
return popup;
}
//http://stackoverflow.com/questions/5767325/how-to-remove-a-particular-element-from-an-array-in-javascript
Array.prototype.indexOf || (Array.prototype.indexOf = function(d, e) {
var a;
if (null == this) throw new TypeError('"this" is null or not defined');
var c = Object(this),
b = c.length >>> 0;
if (0 === b) return -1;
a = +e || 0;
Infinity === Math.abs(a) && (a = 0);
if (a >= b) return -1;
for (a = Math.max(0 <= a ? a : b - Math.abs(a), 0); a < b;) {
if (a in c && c[a] === d) return a;
a++
}
return -1
});
</script>
</body>
</html>