Fire 'zoomlevelschange' when calling setMinZoom & setMaxZoom. (#5230)

* Fire 'zoomlevelschange' when calling setMinZoom & setMaxZoom.

* rename variables

* make sure 'zoomlevelschange' won't be fired unnecessarily

* fix enabling zoom control after changing zoom levels

* always fire `zoomlevelschange` if minZoom/maxZoom changed

* remove trailing spaces
This commit is contained in:
mynameisstephen 2017-10-04 13:02:45 +01:00 committed by Per Liedman
parent 000f457fcb
commit d2f6a6cdcd

View File

@ -463,11 +463,16 @@ export var Map = Evented.extend({
// @method setMinZoom(zoom: Number): this // @method setMinZoom(zoom: Number): this
// Sets the lower limit for the available zoom levels (see the [minZoom](#map-minzoom) option). // Sets the lower limit for the available zoom levels (see the [minZoom](#map-minzoom) option).
setMinZoom: function (zoom) { setMinZoom: function (zoom) {
var oldZoom = this.options.minZoom;
this.options.minZoom = zoom; this.options.minZoom = zoom;
if (this._loaded && this.getZoom() < this.options.minZoom) { if (this._loaded && oldZoom !== zoom) {
this.fire('zoomlevelschange');
if (this.getZoom() < this.options.minZoom) {
return this.setZoom(zoom); return this.setZoom(zoom);
} }
}
return this; return this;
}, },
@ -475,11 +480,16 @@ export var Map = Evented.extend({
// @method setMaxZoom(zoom: Number): this // @method setMaxZoom(zoom: Number): this
// Sets the upper limit for the available zoom levels (see the [maxZoom](#map-maxzoom) option). // Sets the upper limit for the available zoom levels (see the [maxZoom](#map-maxzoom) option).
setMaxZoom: function (zoom) { setMaxZoom: function (zoom) {
var oldZoom = this.options.maxZoom;
this.options.maxZoom = zoom; this.options.maxZoom = zoom;
if (this._loaded && (this.getZoom() > this.options.maxZoom)) { if (this._loaded && oldZoom !== zoom) {
this.fire('zoomlevelschange');
if (this.getZoom() > this.options.maxZoom) {
return this.setZoom(zoom); return this.setZoom(zoom);
} }
}
return this; return this;
}, },