diff --git a/src/geo/crs/CRS.Simple.js b/src/geo/crs/CRS.Simple.js index 634baa293..b3fd55ab8 100644 --- a/src/geo/crs/CRS.Simple.js +++ b/src/geo/crs/CRS.Simple.js @@ -32,5 +32,7 @@ export var Simple = Util.extend({}, CRS, { return Math.sqrt(dx * dx + dy * dy); }, - infinite: true + infinite: true, + + minZoom: -Infinity }); diff --git a/src/geo/crs/CRS.js b/src/geo/crs/CRS.js index 1c4041c14..9454f3344 100644 --- a/src/geo/crs/CRS.js +++ b/src/geo/crs/CRS.js @@ -135,5 +135,13 @@ export var CRS = { newNe = new LatLng(ne.lat - latShift, ne.lng - lngShift); return new LatLngBounds(newSw, newNe); - } + }, + + // @property minZoom: Number = -Infinity + // The minimum zoom level supported by the CRS. + minZoom: 0, + + // @property maxZoom: Number = Infinity + // The maximum zoom level supported by the CRS. + maxZoom: Infinity }; diff --git a/src/layer/Layer.js b/src/layer/Layer.js index f8284a75d..27104dbd5 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -258,8 +258,8 @@ Map.include({ maxZoom = options.maxZoom === undefined ? maxZoom : Math.max(maxZoom, options.maxZoom); } - this._layersMaxZoom = maxZoom === -Infinity ? undefined : maxZoom; - this._layersMinZoom = minZoom === Infinity ? undefined : minZoom; + this._layersMaxZoom = isFinite(maxZoom) ? maxZoom : Infinity; + this._layersMinZoom = isFinite(minZoom) ? minZoom : -Infinity; // @section Map state change events // @event zoomlevelschange: Event @@ -269,10 +269,10 @@ Map.include({ this.fire('zoomlevelschange'); } - if (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) { + if (this.getZoom() > this.getMaxZoom()) { this.setZoom(this._layersMaxZoom); } - if (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) { + if (this.getZoom() < this.getMinZoom()) { this.setZoom(this._layersMinZoom); } } diff --git a/src/map/Map.js b/src/map/Map.js index f2d9796f4..d1f514db8 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -50,13 +50,13 @@ export var Map = Evented.extend({ // Minimum zoom level of the map. // If not specified and at least one `GridLayer` or `TileLayer` is in the map, // the lowest of their `minZoom` options will be used instead. - minZoom: undefined, + minZoom: -Infinity, // @option maxZoom: Number = * // Maximum zoom level of the map. // If not specified and at least one `GridLayer` or `TileLayer` is in the map, // the highest of their `maxZoom` options will be used instead. - maxZoom: undefined, + maxZoom: Infinity, // @option layers: Layer[] = [] // Array of layers that will be added to the map initially @@ -145,6 +145,9 @@ export var Map = Evented.extend({ this.setMaxBounds(options.maxBounds); } + this._addLayers(this.options.layers); + this._updateZoomLevels(); + if (options.zoom !== undefined) { this._zoom = this._limitZoom(options.zoom); } @@ -165,8 +168,6 @@ export var Map = Evented.extend({ this._createAnimProxy(); DomEvent.on(this._proxy, DomUtil.TRANSITION_END, this._catchTransitionEnd, this); } - - this._addLayers(this.options.layers); }, @@ -854,17 +855,21 @@ export var Map = Evented.extend({ }, // @method getMinZoom(): Number - // Returns the minimum zoom level of the map (if set in the `minZoom` option of the map or of any layers), or `0` by default. + // Returns the minimum zoom level of the map (if set in the `minZoom` option of the map or of any layers), or the CRS's minimum zoom level by default. getMinZoom: function () { - return this.options.minZoom === undefined ? this._layersMinZoom || 0 : this.options.minZoom; + return Math.max( + this.options.minZoom, + this._layersMinZoom, + this.options.crs.minZoom); }, // @method getMaxZoom(): Number - // Returns the maximum zoom level of the map (if set in the `maxZoom` option of the map or of any layers). + // Returns the maximum zoom level of the map (if set in the `maxZoom` option of the map or of any layers), or the CRS's maximum zoom level by default. getMaxZoom: function () { - return this.options.maxZoom === undefined ? - (this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) : - this.options.maxZoom; + return Math.min( + this.options.maxZoom, + this._layersMaxZoom, + this.options.crs.maxZoom); }, // @method getBoundsZoom(bounds: LatLngBounds, inside?: Boolean, padding?: Point): Number