add map.setMinZoom() and map.setMaxZoom() closes #3380
This commit is contained in:
parent
b719f931ff
commit
794e64df41
@ -206,6 +206,27 @@ describe("Map", function () {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#getMinZoom and #getMaxZoom", function () {
|
||||
describe('#getMinZoom', function () {
|
||||
it('returns 0 if not set by Map options or TileLayer options', function () {
|
||||
var map = L.map(document.createElement('div'));
|
||||
expect(map.getMinZoom()).to.be(0);
|
||||
});
|
||||
});
|
||||
|
||||
it("minZoom and maxZoom options overrides any minZoom and maxZoom set on layers", function () {
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe("#hasLayer", function () {
|
||||
it("returns false when passed undefined, null, or false", function () {
|
||||
var map = L.map(document.createElement('div'));
|
||||
|
@ -143,6 +143,22 @@ L.Map = L.Evented.extend({
|
||||
return this.on('moveend', this._panInsideMaxBounds);
|
||||
},
|
||||
|
||||
setMinZoom: function (zoom) {
|
||||
this.options.minZoom = zoom;
|
||||
|
||||
if (this._loaded && this.getZoom() < this.options.minZoom) {
|
||||
this.setZoom(zoom);
|
||||
}
|
||||
},
|
||||
|
||||
setMaxZoom: function (zoom) {
|
||||
this.options.maxZoom = zoom;
|
||||
|
||||
if (this._loaded && (this.getZoom() > this.options.maxZoom)) {
|
||||
this.setZoom(zoom);
|
||||
}
|
||||
},
|
||||
|
||||
panInsideBounds: function (bounds, options) {
|
||||
var center = this.getCenter(),
|
||||
newCenter = this._limitCenter(center, this._zoom, bounds);
|
||||
|
Loading…
Reference in New Issue
Block a user