-
Notifications
You must be signed in to change notification settings - Fork 0
/
mapping.js
117 lines (99 loc) · 3.95 KB
/
mapping.js
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
// var OpenStreetMap_BlackAndWhite = L.tileLayer('https://{s}.tiles.wmflabs.org/bw-mapnik/{z}/{x}/{y}.png', {
// maxZoom: 18,
// attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>'
// });
var Stamen_Watercolor = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 1,
maxZoom: 16,
ext: 'png'
});
var Stamen_Toner = L.tileLayer('https://stamen-tiles-{s}.a.ssl.fastly.net/toner/{z}/{x}/{y}.{ext}', {
attribution: 'Map tiles by <a href="http://stamen.com">Stamen Design</a>, <a href="http://creativecommons.org/licenses/by/3.0">CC BY 3.0</a> — Map data © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>',
subdomains: 'abcd',
minZoom: 0,
maxZoom: 20,
ext: 'png'
});
var OpenTopoMap = L.tileLayer('https://{s}.tile.opentopomap.org/{z}/{x}/{y}.png', {
maxZoom: 17,
attribution: 'Map data: © <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>, <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>)'
});
// popdns - layer to show Population Density
var popdns = new L.layerGroup();
// rnweng - layer to show Renewable Energy Goals
var rnweng = new L.layerGroup();
// quake - layer to show quakes
var quake = new L.layerGroup();
var map = L.map('map', {
center: [37.8, -96],
zoom: 4,
// layers: [OpenStreetMap_BlackAndWhite]
layers: [OpenTopoMap]
});
var baseLayers = {
// "OSM B&W" : OpenStreetMap_BlackAndWhite,
"Stamen Toner" : Stamen_Toner,
"Stamen Watercolor" : Stamen_Watercolor,
"Terrain Tiles" : OpenTopoMap
};
var overlays = {
"Population Density": popdns,
"State Renewable" : rnweng,
"Earthquakes" : quake
};
var options = {
"position" : 'topright',
"collapsed" : false,
"autoZIndex" : true
};
L.control.layers(baseLayers, overlays, options).addTo(map);
// ----------------------- Map Control Event Handling ------------------------------
map.on('overlayadd', function (eventLayer) {
// Switch to the Population legendPopDensity...
switch(eventLayer.name) {
case 'Population Density':
infoPopDensity.addTo(this);
legendPopDensity.addTo(this);
geojson.addTo(this);
map.attributionControl.addAttribution(censusAttrib);
break;
case 'State Renewable':
infoRnwEng.addTo(this);
geojsonRnwEng.addTo(this);
legendRnwEng.addTo(this);
map.attributionControl.addAttribution(rnwengAttrib);
break;
case 'Earthquakes':
// ql is a GeoJSON layer created during page load...
ql.addTo(this);
map.attributionControl.addAttribution(quakeAttrib);
break;
default:
break;
}
});
map.on('overlayremove', function (eventLayer) {
// Switch to the Population legendPopDensity...
switch(eventLayer.name) {
case 'Population Density':
this.removeControl(infoPopDensity);
this.removeControl(legendPopDensity);
this.removeControl(geojson);
map.attributionControl.removeAttribution(censusAttrib);
break;
case 'State Renewable':
this.removeControl(infoRnwEng);
this.removeControl(geojsonRnwEng);
this.removeControl(legendRnwEng);
map.attributionControl.removeAttribution(rnwengAttrib);
break;
case 'Earthquakes':
this.removeControl(ql);
map.attributionControl.removeAttribution(quakeAttrib);
break;
default:
break;
}
});