]> git.openstreetmap.org Git - rails.git/blob - app/assets/javascripts/leaflet.zoom.js
Fix erblint warnings
[rails.git] / app / assets / javascripts / leaflet.zoom.js
1 L.OSM.Zoom = L.Control.extend({
2         options: {
3                 position: "topright"
4         },
5
6         onAdd: function (map) {
7                 var zoomName = "zoom",
8                     container = L.DomUtil.create("div", zoomName);
9
10                 this._map = map;
11
12                 this._zoomInButton = this._createButton(
13                         "", I18n.t("javascripts.map.zoom.in"), zoomName + "in", container, this._zoomIn, this);
14                 this._zoomOutButton = this._createButton(
15                         "", I18n.t("javascripts.map.zoom.out"), zoomName + "out", container, this._zoomOut, this);
16
17                 map.on("zoomend zoomlevelschange", this._updateDisabled, this);
18
19                 return container;
20         },
21
22         onRemove: function (map) {
23                 map.off("zoomend zoomlevelschange", this._updateDisabled, this);
24         },
25
26         _zoomIn: function (e) {
27                 this._map.zoomIn(e.shiftKey ? 3 : 1);
28         },
29
30         _zoomOut: function (e) {
31                 this._map.zoomOut(e.shiftKey ? 3 : 1);
32         },
33
34         _createButton: function (html, title, className, container, fn, context) {
35                 var link = L.DomUtil.create("a", "control-button " + className, container);
36                 link.innerHTML = html;
37                 link.href = "#";
38                 link.title = title;
39
40                 L.DomUtil.create("span", "icon " + className, link);
41
42                 var stop = L.DomEvent.stopPropagation;
43
44                 L.DomEvent
45                     .on(link, "click", stop)
46                     .on(link, "mousedown", stop)
47                     .on(link, "dblclick", stop)
48                     .on(link, "click", L.DomEvent.preventDefault)
49                     .on(link, "click", fn, context);
50
51                 return link;
52         },
53
54         _updateDisabled: function () {
55                 var map = this._map,
56                         className = "disabled";
57
58                 L.DomUtil.removeClass(this._zoomInButton, className);
59                 L.DomUtil.removeClass(this._zoomOutButton, className);
60
61                 if (map._zoom === map.getMinZoom()) {
62                         L.DomUtil.addClass(this._zoomOutButton, className);
63                 }
64                 if (map._zoom === map.getMaxZoom()) {
65                         L.DomUtil.addClass(this._zoomInButton, className);
66                 }
67         }
68 });
69
70 L.OSM.zoom = function (options) {
71         return new L.OSM.Zoom(options);
72 };