-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlab9a.html
182 lines (149 loc) · 5.59 KB
/
lab9a.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
<!DOCTYPE html>
<html lang="en">
<head>
<base target="_top">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Lab 10 - Denver Neighborhood Data</title>
<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet.css" integrity="sha256-p4NxAoJBhIIN+hmNHrzRCf9tD/miZyoHS5obTRR9BMY=" crossorigin=""/>
<script src="https://unpkg.com/[email protected]/dist/leaflet.js" integrity="sha256-20nQCchB9co0qIjJZRGuk2/Z9VM+kNiyxNV1lvTlZBo=" crossorigin=""></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<style>
html, body {
height: 100%;
margin: 0;
}
#map { width:100%; height: 70%; }
h1 { color: #3293a8;
font-family: "Garamond", serif;
font-size: 20px;
}
p { font: serif 10px;
color: #3293a8;
}
#header {
width: 100%;
margin: auto;
align: center;
}
a { text-decoration: none; color: inherit; }
.legend {
line-height: 18px;
color: #555;
background-color: #eeeeee;
padding: 2px;
}
.legend i {
width: 18px;
height: 18px;
float: left;
margin-right: 8px;
opacity: 0.8;
}
</style>
<script>
// the document ready wraps our javascript
// to make sure that everything loads in the
// right order
$(document).ready(function() {
// let's create our basemap!
map = L.map('map').setView([0, 0], 10);
// let's add three sets of background tiles - one from OSM, one from HOT OSM, and one from openTopoMap
var OSMTiles = L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map);
var HOTOSMTiles = L.tileLayer('https://{s}.tile.openstreetmap.fr/hot/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: '© OpenStreetMap contributors, Tiles style by Humanitarian OpenStreetMap Team hosted by OpenStreetMap France'});
var OpenTopoMap = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
maxZoom: 19,
attribution: 'Map data: © <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors, <a href="http://viewfinderpanoramas.org">SRTM</a> | Map style: © <a href="https://opentopomap.org">OpenTopoMap</a> (<a href="https://creativecommons.org/licenses/by-sa/3.0/">CC-BY-SA</a>)'});
// this is an object to keep track of our three basemaps
var baseMaps = { "OpenStreetMap" : OSMTiles,
"Humanitarian OSM" : HOTOSMTiles,
"OpenTopoMap" : OpenTopoMap };
// the control let's the user turn on / off layers
var layerControl = L.control.layers(baseMaps,null).addTo(map);
// function to style my choropleth map
function style1(feature) {
if (feature.properties.ENROLLED_IN_SCHOOL == 0) {
d = 0;
} else {
d = feature.properties.KINDERGARTEN / feature.properties.ENROLLED_IN_SCHOOL * 100.0;
}
answer = d > 30 ? '#800026' :
d > 20 ? '#DB0026' :
d > 15 ? '#E31A1C' :
d > 10 ? '#FC4E2A' :
d > 5 ? '#FD8D3C' :
d > 3 ? '#FEB24C' :
d > 1 ? '#FED976' :
'#FFEDA0';
styleReturn = {
fillColor : answer,
weight : 1,
opacity : 1,
color : 'white',
dashArray : '3',
fillOpacity : 0.7
};
return styleReturn;
}
// let's add the Denver ACS data
$.getJSON('./acs_denver_2021.geojson', function(data) {
// convert the file into a layer
acsDenver2021Layer = L.geoJSON(data,
{ style: style1,
onEachFeature: function(feature, layer) {
if (feature.properties.ENROLLED_IN_SCHOOL == 0) {
d = 0;
} else {
d = feature.properties.KINDERGARTEN / feature.properties.ENROLLED_IN_SCHOOL * 100.0;
}
layer.bindPopup("Percent Students in Kindergarten: " +
d + '%<br>' +
'Number of Kindergarteners: ' + feature.properties.KINDERGARTEN + '<br>');
}
}
).addTo(map);
// move the map to the area of the data
map.panTo(acsDenver2021Layer.getBounds().getCenter());
// add the layer to the layercontrol
layerControl.addOverlay(acsDenver2021Layer, "Census 2021");
});
// let's try to add some remote DRCOG data
$.getJSON('https://data.colorado.gov/api/geospatial/trm9-dm4m?method=export&format=GeoJSON', function(data) {
newLayer = L.geoJSON(data);
// add the layer to the layercontrol
layerControl.addOverlay(newLayer, "Highway Markers");
});
var legend = L.control({position: 'bottomright'});
legend.onAdd = function(map) {
var div = L.DomUtil.create('div', 'info legend');
colors = [ '#FFEDA0', '#FED976','#FEB24C' ,'#FD8D3C',
'#FC4E2A','#E31A1C','#BD0026','#800026'];
labels = [ '0-1%', '1-3%', '3-5%', '5-10%', '10-15%',
'15-20%', '20-30%', '30%+'];
div.innerHTML = '<h2>% Kindergartners</h2><br>';
for (var i = 0; i < colors.length; i++) {
div.innerHTML += '<i style="background:' + colors[i] + '"></i> ' +
labels[i] + '<br>';
}
return div;
};
legend.addTo(map);
// end document ready
});
</script>
</head>
<body>
<div id="header">
<h1><a href="https://www.census.gov/programs-surveys/acs">Denver 2021 American Community Survey (Census) data</a></h1>
<h2>Percent of Kindergarteners as percentage of enrolled students by tract.</h2>
<p>Data from <a href="https://denvergov.org/opendata/dataset/city-and-county-of-denver-american-community-survey-blk-grp-2017-2021">Denver Open Data</a></p>
</div>
<div id="map"></div>
</body>
</html>