-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
124 lines (112 loc) · 3.34 KB
/
main.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
var localStorage = window.localStorage;
function update_ancor(map) {
zoom = map.getZoom();
pos = map.getCenter();
srv = ""
if (show_server) {
srv="&show_server"
}
var hash = 'map=' + zoom + '/' + pos.lat + '/' + pos.lng + '&style=' + cur_style + srv;
window.location.hash = (hash);
localStorage.setItem("pos", hash);
return true;
}
//function do_map(new_scene) {
var map = L.map('map');
//}
//var map = do_map('streetcomplete-mapstyle/streetcomplete-light-style.yaml');
var hash = window.location.hash.split('#', 2)[1];
var cur_style = 'cinnabar';
var styles = {
'cinnabar': 'map-styles/cinnabar.yaml',
'streetcomplete-light': 'map-styles/streetcomplete-mapstyle/streetcomplete-light-style.yaml',
'streetcomplete-dark': 'map-styles/streetcomplete-mapstyle/streetcomplete-dark-style.yaml'
};
function set_style(name, sceene) {
sceene.load(styles[name]);
cur_style = name
}
console.log(hash);
if (hash === undefined || hash === '') {
hash = localStorage.getItem("pos")
}
var show_server = false;
var map_position = false;
if (hash !== undefined && hash !== '' && hash !== null) {
fields = hash.split('&');
for (var i in fields) {
var field = fields[i].split('=');
switch (field[0]) {
case 'map':
zpos = field[1].split('/');
map.setView([zpos[1], zpos[2]], zpos[0]);
map_position = true;
break;
case 'style':
console.log('Style: ' + field[1]);
cur_style = field[1];
break;
case 'show_server':
show_server=true;
break;
default:
console.log('unkown argument: ' + field[0]);
break
}
}
}
if (!map_position)
{
map.setView([53.5575437, 10.019788742], 13);
}
map.on('zoomend', function (ev) {
update_ancor(map)
});
map.on('moveend', function (ev) {
update_ancor(map)
});
var layer = Tangram.leafletLayer({
scene: styles[cur_style],
attribution: '<a href="https://mapzen.com/tangram" target="_blank">Tangram</a> | © OSM contributors'
});
layer.addTo(map);
//return map;
var scene = layer.scene;
//set_style(cur_style, scene);
geojson = cur_tiles;
var servers;
function show_servers() {
servers = L.geoJSON(geojson, {
style: function (feature) {
switch (feature.properties.current) {
case 'active':
return {
color: "#55aa55", "weight": 2,
"opacity": 0.65
};
case 'passive':
return {
color: "#dddd55", "weight": 2,
"opacity": 0.65
};
case 'none':
return {
color: "#aa5555", "weight": 2,
"opacity": 0.65
};
}
},
onEachFeature: function (feature, layer) {
var label = L.marker(layer.getBounds().getCenter(), {
icon: L.divIcon({
className: 'label',
html: feature.properties.tile,
iconSize: [100, 40]
})
}).addTo(map);
}
}).addTo(map);
}
if (show_server){
show_servers()
}