[Pkg-javascript-commits] [leaflet] 32/301: Invalidate _initialCenter along with size (fixes #1919)

Jonas Smedegaard js at moszumanska.debian.org
Mon Jan 27 22:22:39 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 a0c6363bb6f0bffe443ffbe8bd4c24da22e2fba4
Author: John Firebaugh <john.firebaugh at gmail.com>
Date:   Mon Aug 5 13:58:54 2013 -0700

    Invalidate _initialCenter along with size (fixes #1919)
---
 spec/suites/map/MapSpec.js | 15 ++++++++++++++-
 src/map/Map.js             |  3 ++-
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js
index 1c90699..11e0561 100644
--- a/spec/suites/map/MapSpec.js
+++ b/spec/suites/map/MapSpec.js
@@ -72,11 +72,24 @@ describe("Map", function () {
 	});
 
 	describe('#getCenter', function () {
-		it ('throws if not set before', function () {
+		it('throws if not set before', function () {
 			expect(function () {
 				map.getCenter();
 			}).to.throwError();
 		});
+
+		it('returns a precise center when zoomed in after being set (#426)', function () {
+			var center = L.latLng(10, 10);
+			map.setView(center, 1);
+			map.setZoom(19);
+			expect(map.getCenter()).to.eql(center);
+		});
+
+		it('returns correct center after invalidateSize (#1919)', function () {
+			map.setView(L.latLng(10, 10), 1);
+			map.invalidateSize();
+			expect(map.getCenter()).not.to.eql(L.latLng(10, 10));
+		});
 	});
 
 	describe("#whenReady", function () {
diff --git a/src/map/Map.js b/src/map/Map.js
index 62f16ef..80757be 100644
--- a/src/map/Map.js
+++ b/src/map/Map.js
@@ -253,6 +253,7 @@ L.Map = L.Class.extend({
 
 		var oldSize = this.getSize();
 		this._sizeChanged = true;
+		this._initialCenter = null;
 
 		if (this.options.maxBounds) {
 			this.setMaxBounds(this.options.maxBounds);
@@ -326,7 +327,7 @@ L.Map = L.Class.extend({
 	getCenter: function () { // (Boolean) -> LatLng
 		this._checkIfLoaded();
 
-		if (!this._moved()) {
+		if (this._initialCenter && !this._moved()) {
 			return this._initialCenter;
 		}
 		return this.layerPointToLatLng(this._getCenterLayerPoint());

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