diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js index 4ae9969d..9cfd925f 100644 --- a/spec/suites/map/MapSpec.js +++ b/spec/suites/map/MapSpec.js @@ -281,6 +281,34 @@ describe("Map", function () { expect(map.getMinZoom()).to.be(2); expect(map.getMaxZoom()).to.be(20); }); + + it("layer minZoom overrides map zoom if map has no minZoom set and layer minZoom is bigger than map zoom", function () { + var map = L.map(document.createElement("div"), {zoom: 10}); + L.tileLayer("{z}{x}{y}", {minZoom: 15}).addTo(map); + + expect(map.getMinZoom()).to.be(15); + }); + + it("layer maxZoom overrides map zoom if map has no maxZoom set and layer maxZoom is smaller than map zoom", function () { + var map = L.map(document.createElement("div"), {zoom: 20}); + L.tileLayer("{z}{x}{y}", {maxZoom: 15}).addTo(map); + + expect(map.getMaxZoom()).to.be(15); + }); + + it("map's zoom is adjusted to layer's minZoom even if initialized with smaller value", function () { + var map = L.map(document.createElement("div"), {zoom: 10}); + L.tileLayer("{z}{x}{y}", {minZoom: 15}).addTo(map); + + expect(map.getZoom()).to.be(15); + }); + + it("map's zoom is adjusted to layer's maxZoom even if initialized with larger value", function () { + var map = L.map(document.createElement("div"), {zoom: 20}); + L.tileLayer("{z}{x}{y}", {maxZoom: 15}).addTo(map); + + expect(map.getZoom()).to.be(15); + }); }); describe("#hasLayer", function () { diff --git a/src/layer/Layer.js b/src/layer/Layer.js index f1c6428a..7ae66036 100644 --- a/src/layer/Layer.js +++ b/src/layer/Layer.js @@ -260,5 +260,12 @@ L.Map.include({ if (oldZoomSpan !== this._getZoomSpan()) { this.fire('zoomlevelschange'); } + + if (this.options.maxZoom === undefined && this._layersMaxZoom && this.getZoom() > this._layersMaxZoom) { + this.setZoom(this._layersMaxZoom); + } + if (this.options.minZoom === undefined && this._layersMinZoom && this.getZoom() < this._layersMinZoom) { + this.setZoom(this._layersMinZoom); + } } });