forked from Maps4HTML/MapML.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeolocationButton.js
61 lines (56 loc) · 1.85 KB
/
GeolocationButton.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
export var GeolocationButton = L.Control.extend({
options: {
position: 'bottomright'
},
onAdd: function (map) {
// customize locate control to focus map after start/stop, so that
// featureIndexOverlay is correctly displayed
L.Control.CustomLocate = L.Control.Locate.extend({
start: function () {
L.Control.Locate.prototype.start.call(this);
map.getContainer().focus();
},
stop: function () {
L.Control.Locate.prototype.stop.call(this);
map.getContainer().focus();
}
});
this.locateControl = new L.Control.CustomLocate({
showPopup: false,
strings: {
title: M.options.locale.btnLocTrackOff
},
position: this.options.position,
locateOptions: {
maxZoom: 16
}
}).addTo(map);
var container = this.locateControl._container;
var button = this.locateControl;
var observer = new MutationObserver(function (mutations) {
if (
container.classList.contains('active') &&
container.classList.contains('following')
) {
container.firstChild.title = M.options.locale.btnLocTrackOn;
button._marker.bindTooltip(M.options.locale.btnMyLocTrackOn, {
permanent: true
});
} else if (container.classList.contains('active')) {
container.firstChild.title = M.options.locale.btnLocTrackLastKnown;
button._marker.bindTooltip(M.options.locale.btnMyLastKnownLocTrackOn);
} else {
container.firstChild.title = M.options.locale.btnLocTrackOff;
}
});
var observerConfig = { attributes: true, attributeFilter: ['class'] };
observer.observe(container, observerConfig);
return container;
},
stop: function () {
return this.locateControl.stop();
}
});
export var geolocationButton = function (options) {
return new GeolocationButton(options);
};