-
Notifications
You must be signed in to change notification settings - Fork 2
/
frame.js
100 lines (85 loc) · 2.46 KB
/
frame.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
function init() {
var map = L.map('map');
var cleanText = function (text) {
return text.replace(/<br><br>/gi, '#').replace(/<br>/gi, ' ').replace(/#/g, '<br><br>');
}
var width = map.getSize().x;
if (width < 740) {
polygon1.title = cleanText(polygon1.title);
polygon1.title2 = cleanText(polygon1.title2);
polygon2.title = cleanText(polygon2.title);
startCoordinates[0] -= 5e-4;
startCoordinates[1] -= (polygon1.b.x-polygon1.a.x)/2;
}
map.setView(startCoordinates, 16)
L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png',{
//L.tileLayer('http://tiles.odcdn.de/planet/{z}/{x}/{y}.png', {
maxZoom: 18,
attribution: 'Map data © <a href="https://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>',
zoomAnimation: true
}).addTo(map);
L.polygon([
[polygon1.a.y, polygon1.a.x],
[polygon1.b.y, polygon1.a.x],
[polygon1.b.y, polygon1.b.x],
[polygon1.a.y, polygon1.b.x]
], {
color: '#000',
weight: 2,
fillColor: '#000',
fillOpacity: 0.6
}).addTo(map);
L.polygon([
[polygon2.a.y, polygon2.a.x],
[polygon2.b.y, polygon2.a.x],
[polygon2.b.y, polygon2.b.x],
[polygon2.a.y, polygon2.b.x]
], {
color: '#000',
weight: 2,
fillColor: '#000',
fillOpacity: 0.6
}).addTo(map);
var label1 = new L.Label({offset:[0,5], className:'left', clickable:true, noHide:true});
label1.setContent(polygon1.title);
label1.setLatLng([polygon1.b.y, polygon1.a.x]);
map.showLabel(label1);
label1.on('click', function () {
map.setView(startCoordinates, 16);
})
var label2 = new L.Label({offset:[0,5], className:'right', clickable:true, noHide:true});
label2.setContent(polygon2.title);
label2.setLatLng([polygon2.b.y, polygon2.a.x]);
map.showLabel(label2);
if (width < 740) {
w = Math.floor(width/2-100);
label1._container.style.width = w+'px';
label2._container.style.width = w+'px';
label1._container.style.whiteSpace = 'normal';
label2._container.style.whiteSpace = 'normal';
}
var interval = false;
label2.on('click', function () {
zoomStep();
interval = setInterval(zoomStep, 1000);
});
var zoomStep = function () {
if (map.getZoom() > 3) {
map.zoomOut(1, {animate:true});
} else {
stopZoom();
}
}
var stopZoom = function () {
if (interval) {
clearInterval(interval);
interval = false;
}
}
map.on('mousedown', stopZoom);
map.on('zoomend', function () {
if (map.getZoom() < 16) {
label1.setContent(polygon1.title2);
}
});
}