* Ensure zoom is within span when adding a layer with min/maxzoom, fixes #4915. * Add tests written by @theashyster * Add tests to verify map's zoom is actually adjusted to layer's min/max
This commit is contained in:
parent
d5c499b732
commit
8c22c4e385
@ -281,6 +281,34 @@ describe("Map", function () {
|
|||||||
expect(map.getMinZoom()).to.be(2);
|
expect(map.getMinZoom()).to.be(2);
|
||||||
expect(map.getMaxZoom()).to.be(20);
|
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 () {
|
describe("#hasLayer", function () {
|
||||||
|
@ -260,5 +260,12 @@ L.Map.include({
|
|||||||
if (oldZoomSpan !== this._getZoomSpan()) {
|
if (oldZoomSpan !== this._getZoomSpan()) {
|
||||||
this.fire('zoomlevelschange');
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user