-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscripts.js
129 lines (106 loc) · 2.96 KB
/
scripts.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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
var defaultMap = "2017";
var leafletMap;
window.onload = function(){
//check hash for map name
//todo: layer parameter
var initMap = window.location.hash ? window.location.hash.split('#')[1] : defaultMap;
mapInit(initMap);
window.addEventListener("hashchange", function () {
mapInit(window.location.hash.split('#')[1]);
});
};
var mapLayers = [
{
"Name": "2017",//folder in tiles-layers/
"Base": {
"Collage for the year": "collage"
}
},
{
"Name": "2016",
"Base": {
"Collage for the year": "collage"
}
},
{
"Name": "2015",
"Base": {
"Collage for the year": "collage"
}
},
{
"Name": "2014",
"Base": {
"Collage for the year": "collage"
}
}
];
var mapLayersLookup = {};
for (var i = 0; i < mapLayers.length; i++) {
mapLayersLookup[mapLayers[i].Name] = mapLayers[i];
}
function mapInit(mapName) {
if(!mapName || !mapLayersLookup[mapName]) {
mapName = defaultMap;
}
var layers = mapLayersLookup[mapName];
if(leafletMap) {
leafletMap.off();
leafletMap.remove();
}
leafletMap = L.map('map', {zoomAnimation: true, minZoom: 3, maxZoom: 5, crs: L.CRS.Simple}).setView([-125, 0], 3);
var path;
//base layers
var baseMaps = {};
for (layer in layers["Base"]) {
path = 'tiles-layers/'+mapName+'/'+layers["Base"][layer]+'/{z}/{x}/{y}.png';
baseMaps[layer] = new L.tileLayer(path, {
attribution: '© <a href="http://tauceti.ru/">TauCeti.ru</a>',
errorTileUrl: 'images/space.png'
});
};
//overlays (optional)
var overlayMaps;
if(layers["Overlay"]) {
overlayMaps = {};
for (layer in layers["Overlay"]) {
path = 'tiles-layers/'+mapName+'/'+layers["Overlay"][layer]+'/{z}/{x}/{y}.png';
if(layer=="Titles"){
overlayMaps[layer] = new L.tileLayer(path, {opacity: 0.75});
} else {
overlayMaps[layer] = new L.tileLayer(path);
};
};
};
//custom control - map switch
var mapSwitch = L.control({position: 'topright'});
mapSwitch.onAdd = function(){
var container = L.DomUtil.create('select', 'leaflet-bar leaflet-control leaflet-map-switch');
var options = "";
for (var i = 0; i < mapLayers.length; i++) {
if(mapLayers[i].Name==mapName) {
options += '<option value="'+mapLayers[i].Name+'" selected>'+mapLayers[i].Name+'</option>';
} else {
options += '<option value="'+mapLayers[i].Name+'">'+mapLayers[i].Name+'</option>';
};
};
container.innerHTML = options;
container.onchange = function(){
mapInit(this.value);
};
return container;
}
leafletMap.addLayer(baseMaps["Collage for the year"]);
window.location.hash = mapName;
var lcontrol;
if(overlayMaps) {
lcontrol = L.control.layers(baseMaps, overlayMaps);
} else {
lcontrol = L.control.layers(baseMaps);
}
var southWest = leafletMap.unproject([0, 8160], leafletMap.getMaxZoom());
var northEast = leafletMap.unproject([8160, 0], leafletMap.getMaxZoom());
leafletMap.setMaxBounds(new L.LatLngBounds(northEast, southWest));
leafletMap.addControl(mapSwitch);
leafletMap.addControl(lcontrol);
};