[Pkg-javascript-commits] [leaflet] 05/40: fire viewreset before onAdd, fix #2510

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:33:06 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 0e558adcea3f47460b89c85eab48827035b1e300
Author: Vladimir Agafonkin <agafonkin at gmail.com>
Date:   Wed Mar 5 23:08:28 2014 +0200

    fire viewreset before onAdd, fix #2510
---
 spec/suites/layer/TileLayerSpec.js | 24 +++++++++++++++++++-----
 src/map/Map.js                     |  4 ++--
 2 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/spec/suites/layer/TileLayerSpec.js b/spec/suites/layer/TileLayerSpec.js
index ab00e92..d4949f9 100644
--- a/spec/suites/layer/TileLayerSpec.js
+++ b/spec/suites/layer/TileLayerSpec.js
@@ -1,12 +1,26 @@
 
 describe('TileLayer', function () {
-	var tileUrl = '';
+	var tileUrl = '',
+		map;
 
-	describe("#getMaxZoom, #getMinZoom", function () {
-		var map;
-		beforeEach(function () {
-			map = L.map(document.createElement('div'));
+	beforeEach(function () {
+		map = L.map(document.createElement('div'));
+	});
+
+	describe("#onAdd", function () {
+		it('is called after viewreset on first map load', function () {
+			var layer = L.tileLayer(tileUrl).addTo(map);
+			layer.onAdd = sinon.spy();
+
+			var onReset = sinon.spy();
+			map.on('viewreset', onReset);
+			map.setView([0, 0], 0);
+
+			expect(onReset.calledBefore(layer.onAdd)).to.be.ok();
 		});
+	});
+
+	describe("#getMaxZoom, #getMinZoom", function () {
 		describe("when a tilelayer is added to a map with no other layers", function () {
 			it("has the same zoomlevels as the tilelayer", function () {
 				var maxZoom = 10,
diff --git a/src/map/Map.js b/src/map/Map.js
index b207019..059a928 100644
--- a/src/map/Map.js
+++ b/src/map/Map.js
@@ -568,13 +568,13 @@ L.Map = L.Class.extend({
 		var loading = !this._loaded;
 		this._loaded = true;
 
+		this.fire('viewreset', {hard: !preserveMapOffset});
+
 		if (loading) {
 			this.fire('load');
 			this.eachLayer(this._layerAdd, this);
 		}
 
-		this.fire('viewreset', {hard: !preserveMapOffset});
-
 		this.fire('move');
 
 		if (zoomChanged || afterZoomAnim) {

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