-
Notifications
You must be signed in to change notification settings - Fork 26
/
MinZoomIndicator.js
95 lines (69 loc) · 1.78 KB
/
MinZoomIndicator.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
import L from 'leaflet';
const MinZoomIndicator = L.Control.extend({
options: {},
_layers: {},
initialize(options) {
L.Util.setOptions(this, options);
this._layers = {};
},
_addLayer(layer) {
let minZoom = 15;
if (layer.options.minZoom) {
minZoom = layer.options.minZoom;
}
this._layers[layer._leaflet_id] = minZoom;
this._updateBox(null);
},
_removeLayer(layer) {
this._layers[layer._leaflet_id] = null;
this._updateBox(null);
},
_getMinZoomLevel() {
let minZoomLevel = -1;
for (const key in this._layers) {
if (this._layers[key] !== null && this._layers[key] > minZoomLevel) {
minZoomLevel = this._layers[key];
}
}
return minZoomLevel;
},
_updateBox(event) {
const minZoomLevel = this._getMinZoomLevel();
if (event !== null) {
L.DomEvent.preventDefault(event);
}
if (minZoomLevel == -1) {
this._container.innerHTML = this.options.minZoomMessageNoLayer;
} else {
this._container.innerHTML = this.options.minZoomMessage
.replace(/CURRENTZOOM/, this._map.getZoom())
.replace(/MINZOOMLEVEL/, minZoomLevel);
}
if (this._map.getZoom() >= minZoomLevel) {
this._container.style.display = 'none';
} else {
this._container.style.display = 'block';
}
},
onAdd(map) {
this._map = map;
this._map.zoomIndicator = this;
this._container = L.DomUtil.create(
'div',
'leaflet-control-minZoomIndicator'
);
this._map.on('moveend', this._updateBox, this);
this._updateBox(null);
return this._container;
},
onRemove(map) {
map.off(
{
moveend: this._updateBox
},
this
);
}
});
L.Control.MinZoomIndicator = MinZoomIndicator;
export default MinZoomIndicator;