Skip to content

Commit 75c1330

Browse files
committed
fix Map min/maxZoom not overriding TileLayer-derived min/max, close Leaflet#1848
1 parent a4c6c03 commit 75c1330

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
lines changed

spec/suites/layer/TileLayerSpec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@ describe('TileLayer', function () {
1313
minZoom = 5;
1414
map.setView([0, 0], 1);
1515

16-
L.tileLayer(tileUrl, {
17-
maxZoom: maxZoom,
18-
minZoom: minZoom
19-
}).addTo(map);
16+
L.tileLayer(tileUrl, {
17+
maxZoom: maxZoom,
18+
minZoom: minZoom
19+
}).addTo(map);
20+
2021
expect(map.getMaxZoom()).to.be(maxZoom);
2122
expect(map.getMinZoom()).to.be(minZoom);
2223
});

spec/suites/map/MapSpec.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,15 @@ describe("Map", function () {
122122

123123
describe("#getMinZoom and #getMaxZoom", function () {
124124
it("minZoom and maxZoom options overrides any minZoom and maxZoom set on layers", function () {
125-
var c = document.createElement('div'),
126-
map = L.map(c, { minZoom: 5, maxZoom: 10 });
127-
L.tileLayer("{z}{x}{y}", { minZoom:0, maxZoom: 10 }).addTo(map);
128-
L.tileLayer("{z}{x}{y}", { minZoom:5, maxZoom: 15 }).addTo(map);
129-
expect(map.getMinZoom()).to.be(5);
130-
expect(map.getMaxZoom()).to.be(10);
125+
126+
var map = L.map(document.createElement('div'), {minZoom: 2, maxZoom: 20});
127+
128+
L.tileLayer("{z}{x}{y}", {minZoom: 4, maxZoom: 10}).addTo(map);
129+
L.tileLayer("{z}{x}{y}", {minZoom: 6, maxZoom: 17}).addTo(map);
130+
L.tileLayer("{z}{x}{y}", {minZoom: 0, maxZoom: 22}).addTo(map);
131+
132+
expect(map.getMinZoom()).to.be(2);
133+
expect(map.getMaxZoom()).to.be(20);
131134
});
132135
});
133136

src/map/Map.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -345,18 +345,15 @@ L.Map = L.Class.extend({
345345
},
346346

347347
getMinZoom: function () {
348-
var z1 = this.options.minZoom || 0,
349-
z2 = this._layersMinZoom || 0,
350-
z3 = this._boundsMinZoom || 0;
351-
352-
return Math.max(z1, z2, z3);
348+
var z1 = this._layersMinZoom === undefined ? -Infinity : this._layersMinZoom,
349+
z2 = this._boundsMinZoom === undefined ? -Infinity : this._boundsMinZoom;
350+
return this.options.minZoom === undefined ? Math.max(z1, z2) : this.options.minZoom;
353351
},
354352

355353
getMaxZoom: function () {
356-
var z1 = this.options.maxZoom === undefined ? Infinity : this.options.maxZoom,
357-
z2 = this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom;
358-
359-
return Math.min(z1, z2);
354+
return this.options.maxZoom === undefined ?
355+
(this._layersMaxZoom === undefined ? Infinity : this._layersMaxZoom) :
356+
this.options.maxZoom;
360357
},
361358

362359
getBoundsZoom: function (bounds, inside, padding) { // (LatLngBounds[, Boolean, Point]) -> Number

0 commit comments

Comments
 (0)