-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet.home.js
71 lines (56 loc) · 1.74 KB
/
leaflet.home.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
L.Map.mergeOptions({
home: false
});
L.Control.Home = L.Control.extend({
options: {
home: {
title: 'Home',
initialZoom: 0,
initialCenter: []
}
},
handlers: {},
initialize: function (options) {
L.Util.extend(this.options, options);
this.map = {};
},
onAdd: function (map) {
var className = 'leaflet-control-home';
var container = map.zoomControl._container;
this.map = map;
this.options.home.initialZoom = map.options.zoom;
this.options.home.initialCenter = map.options.center;
if (this.options.home) {
this._createButton(
this.options.home.title,
className,
container,
this.goHome,
this
);
}
return container;
},
_createButton: function (title, className, container, fn, context) {
var link = L.DomUtil.create('a', className, container);
link.href = '#';
link.title = title;
L.DomEvent
.on(link, 'click', L.DomEvent.stopPropagation)
.on(link, 'mousedown', L.DomEvent.stopPropagation)
.on(link, 'dblclick', L.DomEvent.stopPropagation)
.on(link, 'click', L.DomEvent.preventDefault)
.on(link, 'click', fn, context);
return link;
},
goHome: function () {
this._exitFired = false;
this.map.setView(this.options.home.initialCenter, this.options.home.initialZoom);
}
});
L.Map.addInitHook(function () {
if (this.options.home) {
this.homeControl = new L.Control.Home();
this.addControl(this.homeControl);
}
});