allow setZoom before setView, make setView zoom optional, close #2056, close #1449

This commit is contained in:
Vladimir Agafonkin 2013-09-30 15:00:46 +03:00
parent 68bc39a1a8
commit 2250cee6ec
3 changed files with 12 additions and 1 deletions

View File

@ -121,6 +121,12 @@ describe("Map", function () {
expect(map.getZoom()).to.be(13);
expect(map.getCenter().distanceTo([51.505, -0.09])).to.be.lessThan(5);
});
it("can be passed without a zoom specified", function () {
map.setZoom(13);
expect(map.setView([51.605, -0.11])).to.be(map);
expect(map.getZoom()).to.be(13);
expect(map.getCenter().distanceTo([51.605, -0.11])).to.be.lessThan(5);
});
});
describe("#getBounds", function () {

View File

@ -56,11 +56,16 @@ L.Map = L.Class.extend({
// replaced by animation-powered implementation in Map.PanAnimation.js
setView: function (center, zoom) {
zoom = zoom === undefined ? this.getZoom() : zoom;
this._resetView(L.latLng(center), this._limitZoom(zoom));
return this;
},
setZoom: function (zoom, options) {
if (!this._loaded) {
this._zoom = this._limitZoom(zoom);
return this;
}
return this.setView(this.getCenter(), zoom, {zoom: options});
},

View File

@ -6,7 +6,7 @@ L.Map.include({
setView: function (center, zoom, options) {
zoom = this._limitZoom(zoom);
zoom = zoom === undefined ? this._zoom : this._limitZoom(zoom);
center = L.latLng(center);
options = options || {};