fix Map min/maxZoom not overriding TileLayer-derived min/max, close #1848

This commit is contained in:
Vladimir Agafonkin 2013-07-12 15:05:59 +03:00
parent a4c6c03550
commit 75c133082c
3 changed files with 20 additions and 19 deletions

View File

@ -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);
});

View File

@ -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);
});
});

View File

@ -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