[Pkg-javascript-commits] [leaflet] 30/301: Fix rounding issues in Map::invalidateSize

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 f568768142dc2f0e9e4357c17f8df767f066fa03
Author: Russell Davis <russell.davis at gmail.com>
Date:   Thu Aug 1 23:09:49 2013 -0700

    Fix rounding issues in Map::invalidateSize
---
 spec/suites/map/MapSpec.js | 55 ++++++++++++++++++++++++++++++++++++++++++++++
 src/map/Map.js             |  4 +++-
 2 files changed, 58 insertions(+), 1 deletion(-)

diff --git a/spec/suites/map/MapSpec.js b/spec/suites/map/MapSpec.js
index 1c90699..d56624c 100644
--- a/spec/suites/map/MapSpec.js
+++ b/spec/suites/map/MapSpec.js
@@ -374,4 +374,59 @@ describe("Map", function () {
 			expect(spy.thisValues[0]).to.eql(map);
 		});
 	});
+
+	describe("#invalidateSize", function () {
+		var container,
+		    orig_width = 100;
+
+		beforeEach(function () {
+			container = map.getContainer();
+			container.style.width = orig_width + "px";
+			document.body.appendChild(container);
+			map.setView([0, 0], 0);
+			map.invalidateSize({pan: false});
+		});
+
+		afterEach(function () {
+			document.body.removeChild(container);
+		});
+
+		it("pans by the right amount when growing in 1px increments", function () {
+			container.style.width = (orig_width + 1) + "px";
+			map.invalidateSize();
+			expect(map._getMapPanePos().x).to.be(1);
+
+			container.style.width = (orig_width + 2) + "px";
+			map.invalidateSize();
+			expect(map._getMapPanePos().x).to.be(1);
+
+			container.style.width = (orig_width + 3) + "px";
+			map.invalidateSize();
+			expect(map._getMapPanePos().x).to.be(2);
+		});
+
+		it("pans by the right amount when shrinking in 1px increments", function () {
+			container.style.width = (orig_width - 1) + "px";
+			map.invalidateSize();
+			expect(map._getMapPanePos().x).to.be(0);
+
+			container.style.width = (orig_width - 2) + "px";
+			map.invalidateSize();
+			expect(map._getMapPanePos().x).to.be(-1);
+
+			container.style.width = (orig_width - 3) + "px";
+			map.invalidateSize();
+			expect(map._getMapPanePos().x).to.be(-1);
+		});
+
+		it("pans back to the original position after growing by an odd size then returning to the original size", function () {
+			container.style.width = (orig_width + 5) + "px";
+			map.invalidateSize();
+
+			container.style.width = orig_width + "px";
+			map.invalidateSize();
+
+			expect(map._getMapPanePos().x).to.be(0);
+		});
+	});
 });
diff --git a/src/map/Map.js b/src/map/Map.js
index 62f16ef..7ccc163 100644
--- a/src/map/Map.js
+++ b/src/map/Map.js
@@ -261,7 +261,9 @@ L.Map = L.Class.extend({
 		if (!this._loaded) { return this; }
 
 		var newSize = this.getSize(),
-		    offset = oldSize.subtract(newSize).divideBy(2).round();
+		    oldCenter = oldSize.divideBy(2).round(),
+		    newCenter = newSize.divideBy(2).round(),
+		    offset = oldCenter.subtract(newCenter);
 
 		if (!offset.x && !offset.y) { return this; }
 

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