-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet.zoomhome.js
94 lines (81 loc) · 3.13 KB
/
leaflet.zoomhome.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
/*
* Leaflet zoom control with a home button for resetting the view.
*
* Distributed under the CC-BY-SA-3.0 license. See the file "LICENSE"
* for details.
*
* Based on code by toms (https://gis.stackexchange.com/a/127383/48264).
*/
(function () {
"use strict";
L.Control.ZoomHome = L.Control.Zoom.extend({
options: {
position: 'topleft',
zoomInText: '+',
zoomInTitle: 'Zoom in',
zoomOutText: '-',
zoomOutTitle: 'Zoom out',
zoomHomeIcon: 'home',
zoomHomeTitle: 'Home',
homeCoordinates: null,
homeZoom: null
},
onAdd: function (map) {
var controlName = 'leaflet-control-zoomhome',
container = L.DomUtil.create('div', controlName + ' leaflet-bar'),
options = this.options;
if (options.homeCoordinates === null) {
options.homeCoordinates = map.getCenter();
}
if (options.homeZoom === null) {
options.homeZoom = map.getZoom();
}
this._zoomInButton = this._createButton(options.zoomInText, options.zoomInTitle,
controlName + '-in', container, this._zoomIn.bind(this));
var zoomHomeText = '<i class="fa fa-' + options.zoomHomeIcon + '" style="line-height:1.65;"></i>';
this._zoomHomeButton = this._createButton(zoomHomeText, options.zoomHomeTitle,
controlName + '-home', container, this._zoomHome.bind(this));
this._zoomOutButton = this._createButton(options.zoomOutText, options.zoomOutTitle,
controlName + '-out', container, this._zoomOut.bind(this));
this._updateDisabled();
map.on('zoomend zoomlevelschange', this._updateDisabled, this);
return container;
},
setHomeBounds: function (bounds) {
if (bounds === undefined) {
bounds = this._map.getBounds();
} else {
if (typeof bounds.getCenter !== 'function') {
bounds = L.latLngBounds(bounds);
}
}
this.options.homeZoom = this._map.getBoundsZoom(bounds);
this.options.homeCoordinates = bounds.getCenter();
},
setHomeCoordinates: function (coordinates) {
if (coordinates === undefined) {
coordinates = this._map.getCenter();
}
this.options.homeCoordinates = coordinates;
},
setHomeZoom: function (zoom) {
if (zoom === undefined) {
zoom = this._map.getZoom();
}
this.options.homeZoom = zoom;
},
getHomeZoom: function () {
return this.options.homeZoom;
},
getHomeCoordinates: function () {
return this.options.homeCoordinates;
},
_zoomHome: function (e) {
//jshint unused:false
this._map.setView(this.options.homeCoordinates, this.options.homeZoom);
}
});
L.Control.zoomHome = function (options) {
return new L.Control.ZoomHome(options);
};
}());