add Control.Zoom disable/enable methods, close #3172

This commit is contained in:
Vladimir Agafonkin 2015-01-27 19:09:49 +02:00
parent 06d354e9cd
commit aace5b278e

View File

@ -31,12 +31,28 @@ L.Control.Zoom = L.Control.extend({
map.off('zoomend zoomlevelschange', this._updateDisabled, this);
},
disable: function () {
this._enabled = false;
this._updateDisabled();
return this;
},
enable: function () {
this._enabled = true;
this._updateDisabled();
return this;
},
_zoomIn: function (e) {
this._map.zoomIn(e.shiftKey ? 3 : 1);
if (this._enabled) {
this._map.zoomIn(e.shiftKey ? 3 : 1);
}
},
_zoomOut: function (e) {
this._map.zoomOut(e.shiftKey ? 3 : 1);
if (this._enabled) {
this._map.zoomOut(e.shiftKey ? 3 : 1);
}
},
_createButton: function (html, title, className, container, fn) {
@ -61,10 +77,10 @@ L.Control.Zoom = L.Control.extend({
L.DomUtil.removeClass(this._zoomInButton, className);
L.DomUtil.removeClass(this._zoomOutButton, className);
if (map._zoom === map.getMinZoom()) {
if (!this._enabled || map._zoom === map.getMinZoom()) {
L.DomUtil.addClass(this._zoomOutButton, className);
}
if (map._zoom === map.getMaxZoom()) {
if (!this._enabled || map._zoom === map.getMaxZoom()) {
L.DomUtil.addClass(this._zoomInButton, className);
}
}