forked from stamen/la
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
498 lines (444 loc) · 19.7 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
<html>
<head>
<script src="https://d3js.org/d3.v4.min.js"></script>
<link rel="stylesheet" href="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/themes/css/cartodb.css" />
<script src="https://cartodb-libs.global.ssl.fastly.net/cartodb.js/v3/3.15/cartodb.js"></script>
<script src="vendor/leaflet-hash.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet-geocoder-mapzen/1.4.1/leaflet-geocoder-mapzen.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet-geocoder-mapzen/1.4.1/leaflet-geocoder-mapzen.js"></script>
<!--[if lte IE 8]>
<link rel="stylesheet" href="http://libs.cartocdn.com/cartodb.js/v2/themes/css/cartodb.ie.css" />
<![endif]-->
<style>
html, body {width:100%; height:100%; padding: 0; margin: 0; background: deepskyblue;}
#cartodb-map { width: 100%; height:100%; background: transparent;}
#label-control {
font-family: 'Helvetica Neue', Helvetica, sans-serif;
font-weight: 400;
font-size: 14px;
line-height: normal;
display: block;
}
</style>
<script>
var map;
function init(){
var showLabels = false;
var showBuildings = true;
var showParcels = true;
// Parse query parameters:
var search_values = location.search.replace('\?','').split('&');
search_values.forEach(function(param) {
key_value = param.split("=");
if (key_value.length == 2) { // skip if it doesn't parse well
if (key_value[0] == "labels" && key_value[1] == "true") {
showLabels = true;
}
if (key_value[0] == "background" && key_value[1].match(/^\w+$/)) { // make sure no weird characters
if (d3.color(key_value[1])) { // see if d3 parses it as a CSS color
d3.select("body").style("background-color", key_value[1]);
}
if (d3.color('#' + key_value[1])) { // see if d3 parses it as a hex value
d3.select("body").style("background-color", '#' + key_value[1]);
}
}
}
});
// initiate leaflet map
map = new L.Map('cartodb-map', {
center: [48.76,-122.49],
zoom: 14
})
var parcels_style = [
"#lacounty_parcels{",
" polygon-fill: #F7F7F7;",
" polygon-opacity: 1;",
" line-color: #FFF;",
" line-width: 0;",
" line-opacity: 1;",
"}",
"#lacounty_parcels [ shape_area <= 38391045] {",
" polygon-fill: #252525;",
"}",
"#lacounty_parcels [ shape_area <= 42721] {",
" polygon-fill: #525252;",
"}",
"#lacounty_parcels [ shape_area <= 17019] {",
" polygon-fill: #737373;",
"}",
"#lacounty_parcels [ shape_area <= 11144] {",
" polygon-fill: #969696;",
"}",
"#lacounty_parcels [ shape_area <= 8633] {",
" polygon-fill: #BDBDBD;",
"}",
"#lacounty_parcels [ shape_area <= 6654] {",
" polygon-fill: #D9D9D9;",
"}",
"#lacounty_parcels [ shape_area <= 4998] {",
" polygon-fill: #F7F7F7;",
"}"
].join('\n');
var buildings_style = [
"#lariac_buildings_2008{",
" polygon-fill: #252525;",
" polygon-opacity: 1;",
" line-color: #FFF;",
" line-width: 0;",
" line-opacity: 1;",
"}",
"#lariac_buildings_2008 [ shape_area <= 915602] {",
" polygon-fill: #F7F7F7;",
"}",
"#lariac_buildings_2008 [ shape_area <= 2997] {",
" polygon-fill: #D9D9D9;",
"}",
"#lariac_buildings_2008 [ shape_area <= 2276] {",
" polygon-fill: #BDBDBD;",
"}",
"#lariac_buildings_2008 [ shape_area <= 1831] {",
" polygon-fill: #969696;",
"}",
"#lariac_buildings_2008 [ shape_area <= 1440] {",
" polygon-fill: #737373;",
"}",
"#lariac_buildings_2008 [ shape_area <= 1045] {",
" polygon-fill: #525252;",
"}",
"#lariac_buildings_2008 [ shape_area <= 508] {",
" polygon-fill: #252525;",
"}"
].join('\n');
var parcels_style_1 = [
"#lacounty_parcels{",
" polygon-fill: #252525;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var parcels_style_2 = [
"#lacounty_parcels{",
" polygon-fill: #525252;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var parcels_style_3 = [
"#lacounty_parcels{",
" polygon-fill: #737373;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var parcels_style_4 = [
"#lacounty_parcels{",
" polygon-fill: #969696;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var parcels_style_5 = [
"#lacounty_parcels{",
" polygon-fill: #BDBDBD;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var parcels_style_6 = [
"#lacounty_parcels{",
" polygon-fill: #D9D9D9;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var parcels_style_7 = [
"#lacounty_parcels{",
" polygon-fill: #F7F7F7;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_1 = [
"#lariac_buildings_2008{",
" polygon-fill: #252525;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_2 = [
"#lariac_buildings_2008{",
" polygon-fill: #525252;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_3 = [
"#lariac_buildings_2008{",
" polygon-fill: #737373;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_4 = [
"#lariac_buildings_2008{",
" polygon-fill: #969696;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_5 = [
"#lariac_buildings_2008{",
" polygon-fill: #BDBDBD;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_6 = [
"#lariac_buildings_2008{",
" polygon-fill: #D9D9D9;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var buildings_style_7 = [
"#lariac_buildings_2008{",
" polygon-fill: #F7F7F7;",
" polygon-opacity: 1;\nline-color: #FFF;\nline-width: 0;\nline-opacity: 1;",
"}"
].join('\n');
var mapLayers = {};
// Add parcels layer
cartodb.createLayer(map, {
user_name: 'mappingmashups',
type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM bellingham_parcels AS lacounty_parcels",
cartocss: parcels_style
}]
}, {
cartodb_logo:false,
}).addTo(map).done(function(layer) { mapLayers['parcels'] = layer; layer.setZIndex(2); })
/*
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area > 18749.219",
cartocss: parcels_style_1
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area > 9615.766 AND shape_area <= 18749.219",
cartocss: parcels_style_2
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area > 7550.610 AND shape_area <= 9615.766",
cartocss: parcels_style_3
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area > 6661.997 AND shape_area <= 7550.610",
cartocss: parcels_style_4
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area > 5924.238 AND shape_area <= 6661.997",
cartocss: parcels_style_5
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area > 5043.577 AND shape_area <= 5924.238",
cartocss: parcels_style_6
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lacounty_parcels WHERE shape_area <= 5043.577",
cartocss: parcels_style_7
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(1); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area <= 437.622",
cartocss: buildings_style_1
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area > 437.622 AND shape_area <= 830.578",
cartocss: buildings_style_2
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area > 830.578 AND shape_area <= 1424.776",
cartocss: buildings_style_3
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area > 1424.776 AND shape_area <= 1904.961",
cartocss: buildings_style_4
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area > 1904.961 AND shape_area <= 2379.882",
cartocss: buildings_style_5
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area > 2379.882 AND shape_area <= 3074.368",
cartocss: buildings_style_6
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
cartodb.createLayer(map, { user_name: 'stamen-org', type: 'cartodb',
sublayers: [{
sql: "SELECT * FROM lariac_buildings_2008 WHERE code = 'Building' AND shape_area > 3074.368",
cartocss: buildings_style_7
}]
}, { cartodb_logo:false, }).addTo(map).done(function(layer) { layer.setZIndex(2); })
*/
// Add buildings layer
cartodb.createLayer(map, {
user_name: 'mappingmashups',
type: 'cartodb',
sublayers: [{
sql: "SELECT *, shape_star AS shape_area FROM bellingham_buildings AS lariac_buildings_2008",
cartocss: buildings_style
}]
}, {
cartodb_logo:false,
}).addTo(map).done(function(layer) { mapLayers['buildings'] = layer; layer.setZIndex(3); })
// then finally add the full thing to get the correct blending effects
var layerUrl = 'https://stamen.carto.com/u/stamen-org/api/v2/viz/ea17c2c0-961c-11e4-97a4-f23c91504230/viz.json';
cartodb.createLayer(map, layerUrl, {
cartodb_logo:false,
}).addTo(map).done(function(layer) { mapLayers['everything'] = layer; layer.setZIndex(4); })
var labelLayer = L.tileLayer('http://{s}.tile.stamen.com/toner-labels/{z}/{x}/{y}.png', {id: 'labelLayer', zIndex: 100});
if (showLabels) // off by default
labelLayer.addTo(map);
// scale bar
L.control.scale().addTo(map);
// Add URL hash for zoom/lat/lon
var hash = new L.Hash(map);
map.attributionControl.setPrefix('Map by <a href="https://stamen.com">Stamen Design</a> (<a href="https://hi.stamen.com/using-open-data-to-learn-about-los-angeles-5b30192a68b0">about</a>)');
// Mapzen geocoder
L.control.geocoder('search-hNyVAbJ').addTo(map);
d3.select("#label-control")
.append("div")
.append("label")
.text("show map labels")
.append("input")
.property("checked", showLabels)
.attr("type", "checkbox")
.on("change", function(evt) {
if (this.checked) {
map.addLayer(labelLayer);
var location_string = location.href;
if (location_string.match("labels=false")) {
history.pushState({},null,location_string.replace("labels=false","labels=true"));
} else {
// if it's not in the URL
// then there might not be a '?' either:
if (location_string.match("\\?")) // means there's already a search query
history.pushState({},null,location_string.replace("#","&labels=true#"));
else
history.pushState({},null,location_string.replace("#","?labels=true#"));
}
} else {
map.removeLayer(labelLayer);
var location_string = location.href;
if (location_string.match("labels=true")) {
history.pushState({},null,location_string.replace("labels=true","labels=false"));
} else {
// if it's not in the URL
// then there might not be a '?' either:
if (location_string.match("\\?")) // means there's already a search query
history.pushState({},null,location_string.replace("#","&labels=false#"));
else
history.pushState({},null,location_string.replace("#","?labels=false#"));
}
}
// update the URL location
//var location_string = location;
});
d3.select("#label-control")
.append("div")
.append("label")
.text("show buildings")
.append("input")
.property("checked", showBuildings)
.attr("type", "checkbox")
.on("change", function(evt) {
if (this.checked) {
map.addLayer(mapLayers['buildings']);
if (showParcels)
map.addLayer(mapLayers['everything']);
} else {
map.removeLayer(mapLayers['buildings']);
if (showParcels)
map.removeLayer(mapLayers['everything']);
}
});
d3.select("#label-control")
.append("div")
.append("label")
.text("show parcels")
.append("input")
.property("checked", showParcels)
.attr("type", "checkbox")
.on("change", function(evt) {
if (this.checked) {
map.addLayer(mapLayers['parcels']);
if (showBuildings)
map.addLayer(mapLayers['everything']);
} else {
map.removeLayer(mapLayers['parcels']);
if (showBuildings)
map.removeLayer(mapLayers['everything']);
}
});
}
</script>
</head>
<body onload="init()">
<!-- copied from the default CARTO overlays -->
<div class="cartodb-overlay overlay-text desktop" style="z-index: 4; max-width: 500px; margin-left: 0px; margin-top: 0px; top: 55px; left: 66px; right: auto; bottom: auto; display: block; background-color: rgba(0, 0, 0, 0.701961);">
<div class="content">
<div class="text widget_text" style="z-index: 4; color: rgb(255, 255, 255); text-align: left; font-size: 20px;"><strong>
Bellingham buildings and parcels
</strong></div>
</div>
</div>
<div class="cartodb-overlay overlay-text desktop" style="z-index: 4; max-width: 300px; margin-left: 0px; margin-top: 0px; top: 119px; left: 66px; right: auto; bottom: auto; display: block; background-color: rgba(0, 0, 0, 0.701961);">
<div class="content">
<div class="text widget_text" style="z-index: 4; color: rgb(255, 255, 255); text-align: left; font-size: 14px;">
Small buildings are dark, and larger buildings are lighter in color.
<br>Parcels are the reverse: small parcels are light and larger parcels are darker
</div>
</div>
</div>
<div class="cartodb-overlay overlay-text desktop content text widget_text" style="z-index: 4; margin-left: 0px; margin-top: 0px; top: 55px; right: 60px; left: auto: bottom: auto; display: block; background-color: rgba(0, 0, 0, 0.701961);">
<div class="content">
<div id="label-control" class="text widget_text" style="z-index: 4; color: rgb(255, 255, 255); text-align: left; font-size: 14px;">
</div>
</div>
</div>
<div id='cartodb-map'></div>
<!-- cut and paste legend from the one on CARTO. Will rebuild it later -->
<!--
<div class="cartodb-legend-stack" style="display: block;"><div class="cartodb-legend choropleth" style="display: block;">
<div class="legend-title">Building Area</div><ul><li class="min"> 437.62</li><li class="max"> 1507358.02</li><li class="graph count_441"> <div class="colors">
<div class="quartile" style="background-color:#252525"></div>
<div class="quartile" style="background-color:#525252"></div>
<div class="quartile" style="background-color:#737373"></div>
<div class="quartile" style="background-color:#969696"></div>
<div class="quartile" style="background-color:#BDBDBD"></div>
<div class="quartile" style="background-color:#D9D9D9"></div>
<div class="quartile" style="background-color:#F7F7F7"></div>
</div></li></ul></div><div class="cartodb-legend choropleth" style="display: block;">
<div class="legend-title">Parcel Area</div><ul><li class="min"> 5043.58</li><li class="max"> 183259633.85</li><li class="graph count_441"> <div class="colors">
<div class="quartile" style="background-color:#F7F7F7"></div>
<div class="quartile" style="background-color:#D9D9D9"></div>
<div class="quartile" style="background-color:#BDBDBD"></div>
<div class="quartile" style="background-color:#969696"></div>
<div class="quartile" style="background-color:#737373"></div>
<div class="quartile" style="background-color:#525252"></div>
<div class="quartile" style="background-color:#252525"></div>
</div></li></ul></div></div>
-->
</body>
</html>