diff --git a/spec/suites/layer/TileLayerSpec.js b/spec/suites/layer/TileLayerSpec.js index 8d575e1d..64a979c1 100644 --- a/spec/suites/layer/TileLayerSpec.js +++ b/spec/suites/layer/TileLayerSpec.js @@ -13,10 +13,11 @@ describe('TileLayer', function () { minZoom = 5; map.setView([0, 0], 1); - L.tileLayer(tileUrl, { - maxZoom: maxZoom, - minZoom: minZoom - }).addTo(map); + L.tileLayer(tileUrl, { + maxZoom: maxZoom, + minZoom: minZoom + }).addTo(map); + expect(map.getMaxZoom()).to.be(maxZoom); expect(map.getMinZoom()).to.be(minZoom); }); diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 061c85cf..762594e1 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -122,12 +122,15 @@ describe("Map", function () { describe("#getMinZoom and #getMaxZoom", function () { it("minZoom and maxZoom options overrides any minZoom and maxZoom set on layers", function () { - var c = document.createElement('div'), - map = L.map(c, { minZoom: 5, maxZoom: 10 }); - L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map); - L.tileLayer("{z}{x}{y}", { minZoom:5, maxZoom: 15 }).addTo(map); - expect(map.getMinZoom()).to.be(5); - expect(map.getMaxZoom()).to.be(10); + + var map = L.map(document.createElement('div'), {minZoom: 2, maxZoom: 20}); + + L.tileLayer("{z}{x}{y}", {minZoom: 4, maxZoom: 10}).addTo(map); + L.tileLayer("{z}{x}{y}", {minZoom: 6, maxZoom: 17}).addTo(map); + L.tileLayer("{z}{x}{y}", {minZoom: 0, maxZoom: 22}).addTo(map); + + expect(map.getMinZoom()).to.be(2); + expect(map.getMaxZoom()).to.be(20); }); }); diff --git a/src/map/Map.js b/src/map/Map.js index e760c38a..0df345c5 100644 --- a/src/map/Map.js +++ b/src/map/Map.js @@ -345,18 +345,15 @@ L.Map = L.Class.extend({ }, getMinZoom: function () { - var z1 = this.options.minZoom || 0, - z2 = this._layersMinZoom || 0, - z3 = this._boundsMinZoom || 0; - - return Math.max(z1, z2, z3); + var z1 = this._layersMinZoom === undefined ? -Infinity : this._layersMinZoom, + z2 = this._boundsMinZoom === undefined ? -Infinity : this._boundsMinZoom; + return this.options.minZoom === undefined ? Math.max(z1, z2) : this.options.minZoom; }, getMaxZoom: function () { - var z1 = this.options.maxZoom === undefined ? Infinity : this.options.maxZoom, - z2 = this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom; - - return Math.min(z1, z2); + return this.options.maxZoom === undefined ? + (this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) : + this.options.maxZoom; }, getBoundsZoom: function (bounds, inside, padding) { // (LatLngBounds[, Boolean, Point]) -> Number