-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
427 lines (341 loc) · 13.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
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
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Tobacco- & Smoke-free Schools</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
<script src="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.js"></script>
<script src="http://maps.stamen.com/js/tile.stamen.js"></script>
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.5/leaflet.css" />
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<style>
body {
margin: 0;
padding: 0;
background: whitesmoke;
font-family: Lato, sans-serif;
color: #0D0000;
}
header {
padding: 6px 10%;
}
h1 {
position: absolute;
z-index: 100;
top: 10px;
left: 60px;
padding: 8px 15px;
margin: 0;
color: whitesmoke;
font-size: 1.5em;
background: rgba(25, 25, 25, 0.8);
border-radius: 5px;
}
#map {
position: absolute;
width: 100%;
top: 0;
bottom: 0;
}
footer {
padding: 6px 10%;
width: 80%;
}
p {
font-size: 1em;
color: #001323;
}
.legend {
padding: 6px 8px;
font-size: 1em;
background: rgba(75, 75, 75, 0.8);
color: whitesmoke;
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
border-radius: 5px;
width: 160px;
}
.legend h3 {
padding: 5px 0px;
font-size: 1.1em;
font-weight: bold;
line-height: 1em;
color: whitesmoke;
margin: 0;
}
.legend ul {
padding: 0;
}
.legend li {
list-style-type: none;
height: 22px;
}
.legend span {
width: 30px;
height: 20px;
float: left;
margin-right: 10px;
}
#ui-controls {
width: 176px;
padding: 8px 15px 8px 15px;
background: rgba(75, 75, 75, 0.8);
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
border-radius: 5px;
color: whitesmoke;
}
.year-slider {
width: 100%;
}
#ui-controls .min {
float: left;
}
#ui-controls .max {
float: right;
}
label {
font-size: 1.1em;
font-weight: bold;
}
.info {
padding: 6px 8px;
font-size: 1em;
background: rgba(255, 255, 255, 0.8);
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
border-radius: 5px;
text-align: right;
}
.info h3 {
margin: 0;
}
</style>
</head>
<body>
<header>
<h1>Tobacco- & Smoke-free Schools DRAFT</h1>
</header>
<div id='map'></div>
<div id="ui-controls">
<label><span class="min">2008</span><span class="max">2015</span>
<input type="range" min="2008" , max="2015" , value="2015" , step="1" , class="year-slider"></input>
</label>
</div>
</div>
<script src="CollegeCampuses.js"></script>
<script src='K12schools.js'></script>
<script src='ky-counties.js'></script>
<script>
var map = L.map('map', {
center: [37.836, -85.794],
zoom: 7,
minZoom: 6,
maxZoom: 15,
zoomControl: true,
dragging: true,
});
// var basemaplayer =new L.StamenTileLayer("toner-lite");
var basemaplayer = L.tileLayer('http://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
});
map.addLayer(basemaplayer);
// Load KY counties into map
/////////////////////////////////////////////////////
$.getJSON("ky-counties.json", function (counties) {
}).fail(function () {
// the data file failed to load
console.log("Ruh roh! An error has occurred.");
}); // end of $.getJSON()
drawCounties(counties);
function drawCounties(counties){
dataLayer = L.geoJson(counties, {
style: function (feature) {
return {
color: '#FFFFFF',
weight: 2,
fillOpacity: .35,
fillColor: '#C0C0C0',
clickable: false
}
}
}).addTo(map);
}
/////////////////////////////////////////////////////
createSliderUI();
// Add time slider
/////////////////////////////////////////////////////
// declare global variables
var attribute = "2015";
// create a Leaflet control object and store a reference to it in a variable
var sliderControl = L.control({
position: 'bottomleft'
});
// when we add this control object to the map
sliderControl.onAdd = function (map) {
// select an existing DOM element with an id of "ui-controls"
var slider = L.DomUtil.get("ui-controls");
// when the user clicks on the slider element
L.DomEvent.addListener(slider, 'mousedown', function (e) {
// prevent the click event from bubbling up to the map
L.DomEvent.stopPropagation(e);
});
// return the slider from the onAdd method
return slider;
}
// add the control object containing our slider element to the map
sliderControl.addTo(map);
// Function to createSliderUI
/////////////////////////////////////////////////////
function createSliderUI() {
$(".year-slider")
.on('input', function () {
attribute = $(this).val();
updateMap();
});
}
// Adding and symbolizing K-12 Schools
/////////////////////////////////////////////////////
var k12SchoolData = L.geoJson(k12schools, {
pointToLayer: function (feature, latlng) {
return L.circleMarker(latlng, {
radius: 7,
fillColor: "green",
width: 0.2,
fillOpacity: 0.7
});
},
onEachFeature: function (feature, layer) {
// layer.setStyle(
// style2(feature)
// )
var props = layer.feature.properties;
// console.log(layer.feature.properties.Zip);
layer.bindPopup("<b>" + props.School_Dis + " School District" + "</b>");
}
}).addTo(map);
// Adding and symbolizing Colleges as Square Icons
/////////////////////////////////////////////////////
var redIcon = L.icon({
iconUrl: 'icondesignred.png',
iconSize: [18, 18],
iconAnchor: [18, 18],
popupAnchor: [-9, -17]
});
var blueIcon = L.icon({
iconUrl: 'icondesignblue.png',
iconSize: [15, 15],
iconAnchor: [15, 15],
popupAnchor: [-7, -14]
});
var tfSchoolData = L.geoJson(campus, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: redIcon
});
},
filter: function (feature) {
// console.log(feature.properties.ImpYear);
if (feature.properties.Policy == 'TF') {
return feature;
}
},
onEachFeature: function (feature, layer) {
// layer.setStyle(
// style(feature)
// )
var props = layer.feature.properties;
// console.log(layer.feature.properties.University);
layer.bindPopup("<b>" + props.University + "</b>" + "<br>" + "<b style='color:rgb(255,34,34)'>" + "Tobacco-free since: " + "</b>" + props.ImpYear);
}
}).addTo(map);
var sfSchoolData = L.geoJson(campus, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: blueIcon
});
},
filter: function (feature) {
// console.log(feature.properties.ImpYear);
if (feature.properties.Policy == 'SF') {
return feature;
}
},
onEachFeature: function (feature, layer) {
// layer.setStyle(
// style(feature)
// )
var props = layer.feature.properties;
// console.log(layer.feature.properties.University);
layer.bindPopup("<b>" + props.University + "</b>" + "<br>" + "<b style='color:#4957A6'>" + "Smoke-free since: " + "</b>" + props.ImpYear);
}
}).addTo(map);
map.removeLayer(k12SchoolData);
// Add control element - clickable legend
/////////////////////////////////////////////////////
var sourcesLabels = {
"<b style='color:green'>Tobacco-free K-12 School District</b><br><b style='color:rgb(255,34,34)'>Tobacco-free Colleges and Universities</b><br><b style='color:#4957A6'>Smoke-free Colleges and Universities</b><br>": k12SchoolData,
// "<b style='color:#B22222'>Tobacco-free College</b>": tfSchoolData
// "<b style='color:rgb(255,34,34)'>Tobacco-free College</b>": tfSchoolData,
// "<b style='color:rgb(255,255,38)'>Tobacco-free College</b>": sfSchoolData
};
L.control.layers(null, sourcesLabels, {
collapsed: false
}).addTo(map);
/////////////////////////////////////////////////////
// Update Map after Time Slider Event
/////////////////////////////////////////////////////
function updateMap() {
// console.log(attribute);
map.removeLayer(tfSchoolData);
map.removeLayer(sfSchoolData);
drawNewMap();
}
function drawNewMap() {
tfSchoolData = L.geoJson(campus, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: redIcon
});
},
filter: function (feature) {
if ((feature.properties.Policy == 'TF') && (feature.properties.ImpYear <= attribute)) {
// console.log(feature.properties.ImpYear)
return feature;
}
},
onEachFeature: function (feature, layer) {
// layer.setStyle(
// style(feature)
// )
var props = layer.feature.properties;
// console.log(layer.feature.properties.University);
layer.bindPopup("<b>" + props.University + "</b>" + "<br>" + "<b style='color:rgb(255,34,34)'>" + "Tobacco-free since: " + "</b>" + props.ImpYear);
}
}).addTo(map);
sfSchoolData = L.geoJson(campus, {
pointToLayer: function (feature, latlng) {
return L.marker(latlng, {
icon: blueIcon
});
},
filter: function (feature) {
// console.log(feature.properties.ImpYear);
if ((feature.properties.Policy == 'SF') && (feature.properties.ImpYear <= attribute)) {
return feature;
}
},
onEachFeature: function (feature, layer) {
// layer.setStyle(
// style(feature)
// )
var props = layer.feature.properties;
// console.log(layer.feature.properties.University);
layer.bindPopup("<b>" + props.University + "</b>" + "<br>" + "<b style='color:#4957A6'>" + "Smoke-free since: " + "</b>" + props.ImpYear);
}
}).addTo(map);
// console.log(attribute);
};
/////////////////////////////////////////////////////
</script>
</body>
</html>