[Pkg-javascript-commits] [leaflet-markercluster] 112/128: Another test and fix for #753

Jonas Smedegaard dr at jones.dk
Sun Apr 16 06:26:09 UTC 2017


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

js pushed a commit to branch master
in repository leaflet-markercluster.

commit c82f342520a9ec514a1b5945a54b34389b63acc7
Author: danzel <dave at smartrak.co.nz>
Date:   Thu Feb 2 09:22:29 2017 +1300

    Another test and fix for #753
---
 spec/suites/markerMoveSupportSpec.js | 22 ++++++++++++++++++++++
 src/MarkerClusterGroup.js            | 11 ++++++++---
 2 files changed, 30 insertions(+), 3 deletions(-)

diff --git a/spec/suites/markerMoveSupportSpec.js b/spec/suites/markerMoveSupportSpec.js
index 9497f98..867e794 100644
--- a/spec/suites/markerMoveSupportSpec.js
+++ b/spec/suites/markerMoveSupportSpec.js
@@ -78,6 +78,28 @@ describe('moving markers', function () {
 		expect(group.getLayers().length).to.be(1);
 	});
 
+	it('moves multiple markers that were moved while off the map', function () {
+
+		group = new L.MarkerClusterGroup();
+		map.addLayer(group);
+
+		var markers = [];
+		for (var i = 0; i < 10; i++) {
+			var marker = new L.Marker([10, 10]);
+			group.addLayer(marker);
+			markers.push(marker);
+		}
+
+		map.removeLayer(group);
+		for (var i = 0; i < 10; i++) {
+			var marker = markers[i];
+			marker.setLatLng([1.5, 1.5]);
+		}
+		map.addLayer(group);
+
+		expect(group.getLayers().length).to.be(10);
+	});
+
 
 	/////////////////////////////
 	// CLEAN UP CODE
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 3046fa4..19049ec 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -571,7 +571,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 	//Overrides FeatureGroup.onAdd
 	onAdd: function (map) {
 		this._map = map;
-		var i, l, layer, latlngbk;
+		var i, l, layer;
 
 		if (!isFinite(this._map.getMaxZoom())) {
 			throw "Map has no maxZoom specified";
@@ -586,12 +586,17 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 		this._maxLat = map.options.crs.projection.MAX_LATITUDE;
 
+		//Restore all the positions as they are in the MCG before removing them
 		for (i = 0, l = this._needsRemoving.length; i < l; i++) {
 			layer = this._needsRemoving[i];
-			latlngbk = layer.layer._latlng;
+			layer.newlatlng = layer.layer._latlng;
 			layer.layer._latlng = layer.latlng;
+		}
+		//Remove them, then restore their new positions
+		for (i = 0, l = this._needsRemoving.length; i < l; i++) {
+			layer = this._needsRemoving[i];
 			this._removeLayer(layer.layer, true);
-			layer.layer._latlng = latlngbk;
+			layer.layer._latlng = layer.newlatlng;
 		}
 		this._needsRemoving = [];
 

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



More information about the Pkg-javascript-commits mailing list