[Pkg-javascript-commits] [leaflet-markercluster] 28/128: Don't return markers that need to be removed in eachLayer/getLayers.

Jonas Smedegaard dr at jones.dk
Sun Apr 16 06:26:00 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 57cf04cdccd79d9f990a5dfd6ddb89289abb38b8
Author: danzel <danzel at localhost.geek.nz>
Date:   Tue Dec 22 11:25:15 2015 +1300

    Don't return markers that need to be removed in eachLayer/getLayers.
    
    Fixes #613
---
 spec/suites/getLayersSpec.js | 17 +++++++++++++++++
 src/MarkerClusterGroup.js    |  5 ++++-
 2 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/spec/suites/getLayersSpec.js b/spec/suites/getLayersSpec.js
index 1c45096..410d550 100644
--- a/spec/suites/getLayersSpec.js
+++ b/spec/suites/getLayersSpec.js
@@ -45,4 +45,21 @@
 		expect(layers).to.contain(marker);
 		expect(layers).to.contain(polygon);
 	});
+
+	it('skips markers and polygons removed while not on the map', function () {
+		var group = new L.MarkerClusterGroup();
+		var polygon = new L.Polygon([[1.5, 1.5], [2.0, 1.5], [2.0, 2.0], [1.5, 2.0]]);
+		var marker = new L.Marker([1.5, 1.5]);
+
+		group.addLayers([polygon, marker]);
+
+		map.addLayer(group);
+		map.removeLayer(group);
+
+		group.removeLayers([polygon, marker]);
+
+		var layers = group.getLayers();
+
+		expect(layers.length).to.be(0);
+	});
 });
\ No newline at end of file
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 714e3cd..852194c 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -383,6 +383,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 	//Overrides LayerGroup.eachLayer
 	eachLayer: function (method, context) {
 		var markers = this._needsClustering.slice(),
+			needsRemoving = this._needsRemoving,
 			i;
 
 		if (this._topClusterLevel) {
@@ -390,7 +391,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		}
 
 		for (i = markers.length - 1; i >= 0; i--) {
-			method.call(context, markers[i]);
+			if (needsRemoving.indexOf(markers[i]) === -1) {
+				method.call(context, markers[i]);
+			}
 		}
 
 		this._nonPointGroup.eachLayer(method, context);

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