[Pkg-javascript-commits] [leaflet] 106/301: allow setZoom before setView, make setView zoom optional, close #2056, close #1449

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:45 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository leaflet.

commit 2250cee6ecaada01e48b4e57a785226515bff303
Author: Vladimir Agafonkin <agafonkin at gmail.com>
Date:   Mon Sep 30 15:00:46 2013 +0300

    allow setZoom before setView, make setView zoom optional, close #2056, close #1449
---
 spec/suites/map/MapSpec.js       | 6 ++++++
 src/map/Map.js                   | 5 +++++
 src/map/anim/Map.PanAnimation.js | 2 +-
 3 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js
index e9e610a..00da85d 100644
--- a/spec/suites/map/MapSpec.js
+++ b/spec/suites/map/MapSpec.js
@@ -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 () {
diff --git a/src/map/Map.js b/src/map/Map.js
index 82a243b..4fd5d5f 100644
--- a/src/map/Map.js
+++ b/src/map/Map.js
@@ -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});
 	},
 
diff --git a/src/map/anim/Map.PanAnimation.js b/src/map/anim/Map.PanAnimation.js
index a76f121..59b7e45 100644
--- a/src/map/anim/Map.PanAnimation.js
+++ b/src/map/anim/Map.PanAnimation.js
@@ -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 || {};
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/leaflet.git



More information about the Pkg-javascript-commits mailing list