-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayers.html
212 lines (177 loc) · 5.78 KB
/
layers.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
<!doctype html>
<html class="no-js" lang="">
<head>
<meta charset="utf-8">
<meta http-equiv="x-ua-compatible" content="ie=edge">
<title></title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="apple-touch-icon" href="apple-touch-icon.png">
<style>
#mapid { height: 600px; }
.info { background: rgba(255, 255, 255, 0.7); }
</style>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.2.0/dist/leaflet.css"
integrity="sha512-M2wvCLH6DSRazYeZRIm1JnYyh22purTM+FDB5CsyxtQJYeKq83arPe5wgbNmcFXGqiSH2XR8dT/fJISVA1r/zQ=="
crossorigin=""/>
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet@1.2.0/dist/leaflet.js"
integrity="sha512-lInM/apFSqyy1o6s89K4iQUKg6ppXEgsVxT35HbzUupEVRh2Eu9Wdl4tHj7dZO0s1uvplcYGmt3498TtHq+log=="
crossorigin=""></script>
</head>
<body>
<div id="mapid"></div>
<!-- Geojson data layer, created with qGIS, loads as javascript var buildingsWYears -->
<script type="text/javascript" src="buildingsWYears.js"></script>
<script>
var mymap = L.map('mapid').setView([44.48, -73.21], 16);
L.tileLayer('https://api.tiles.mapbox.com/v4/{id}/{z}/{x}/{y}.png?access_token={accessToken}', {
maxZoom: 18,
id: 'mapbox.dark',
accessToken: 'pk.eyJ1IjoiZnJpbmdlZGdlbnRpYW4iLCJhIjoiY2o2NnAxOXBkMmZvcDJ3cTdhaDRmazE2dyJ9.RFzxwRRu5jeFggeuVzW12w'}).addTo(mymap);
//Create one layer for each segment of data using the filter option and display on map
var over2000 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#ffffcc',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt >= 2000
}
}).addTo(mymap);
var bldg1980 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#ffeda0',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt >= 1980
&& feature.properties.YearBlt < 2000
}
}).addTo(mymap);
var bldg1960 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#fed976',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt >= 1960
&& feature.properties.YearBlt < 1980
}
}).addTo(mymap);
var bldg1940 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#feb24c',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt >= 1940
&& feature.properties.YearBlt < 1960
}
}).addTo(mymap);
var bldg1920 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#fd8d3c',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt >= 1920
&& feature.properties.YearBlt < 1940
}
}).addTo(mymap);
var bldg1900 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#fc4e2a',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt >= 1900
&& feature.properties.YearBlt < 1920
}
}).addTo(mymap);
var pre1900 = L.geoJson(buildingsWYears, {
style: {
fillColor: '#e31a1c',
weight: 1,
opacity: 1,
color: 'white',
dashArray: '',
fillOpacity: 0.8},
onEachFeature: onEachFeature,
filter: function(feature) {
return feature.properties.YearBlt < 1900
}
}).addTo(mymap);
//Functions used above to highlight buildings on hover and update info
function onEachFeature(feature, layer) {
layer.on({
mouseover: highlightFeature,
mouseout: resetHighlight
});
}
function highlightFeature(e) {
var layer = e.target;
layer.setStyle({
color: '#666',
});
info.update(layer.feature.properties);
}
function resetHighlight(e) {
var layer = e.target;
layer.setStyle({
color: 'white',
});
info.update();
}
//Create Leaflet control to display title and year information on hover
var info = L.control();
info.onAdd = function (mymap) {
this._div = L.DomUtil.create('div', 'info'); // create a div with a class "info"
this.update();
return this._div;
};
// update the control based on feature properties passed
info.update = function (props) {
this._div.innerHTML = '<h4>Age of Burlington Buildings</h4>' + (props ?
'Built in ' + props.YearBlt
: 'Hover over a building');
};
info.addTo(mymap);
//Add each Layer to a Leaflet control to allow toggling on and off
var overlayMaps = {
"<span style='background-color: #e31a1c'>Before 1900</span>": pre1900,
"<span style='background-color: #fc4e2a'>1900-1919</span>": bldg1900,
"<span style='background-color: #fd8d3c'>1920-1939</span>": bldg1920,
"<span style='background-color: #feb24c'>1940-1959</span>": bldg1940,
"<span style='background-color: #fed976'>1960-1979</span>": bldg1960,
"<span style='background-color: #ffeda0'>1980-1999</span>": bldg1980,
"<span style='background-color: #ffffcc'>over 2000</span>": over2000
}
L.control.layers(null, overlayMaps, {collapsed: false, position: 'bottomright'}).addTo(mymap);
</script>
</body>
</html>