[Pkg-javascript-commits] [leaflet-markercluster] 350/479: Fix #160

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:50 UTC 2014


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

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

commit e7e1d5391f2612c8d8da92a1e310aeaac8d6e2ad
Author: danzel <danzel at localhost.geek.nz>
Date:   Fri Apr 26 09:58:40 2013 +1200

    Fix #160
    
    If we are added to the map, then removed, then a marker is removed from us. Previously that marker wouldn't be removed, now it is when we get re-added to the map.
---
 src/MarkerClusterGroup.js | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index f0fd78f..9f4ae75 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -41,6 +41,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 		this._inZoomAnimation = 0;
 		this._needsClustering = [];
+		this._needsRemoving = []; //Markers removed while we aren't on the map need to be kept track of
 		//The bounds of the currently shown area (from _getExpandedVisibleBounds) Updated on zoom/move
 		this._currentShownBounds = null;
 	},
@@ -94,7 +95,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 	removeLayer: function (layer) {
 
 		if (!this._map) {
-			this._arraySplice(this._needsClustering, layer);
+			if (!this._arraySplice(this._needsClustering, layer) && this.hasLayer(layer)) {
+				this._needsRemoving.push(layer);
+			}
 			return this;
 		}
 
@@ -262,12 +265,18 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 			return false;
 		}
 
-		if (this._needsClustering.length > 0) {
-			var anArray = this._needsClustering;
-			for (var i = anArray.length - 1; i >= 0; i--) {
-				if (anArray[i] === layer) {
-					return true;
-				}
+		var i, anArray = this._needsClustering;
+
+		for (i = anArray.length - 1; i >= 0; i--) {
+			if (anArray[i] === layer) {
+				return true;
+			}
+		}
+
+		anArray = this._needsRemoving;
+		for (i = anArray.length - 1; i >= 0; i--) {
+			if (anArray[i] === layer) {
+				return false;
 			}
 		}
 
@@ -315,13 +324,20 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 	//Overrides FeatureGroup.onAdd
 	onAdd: function (map) {
 		this._map = map;
+		var i, l, layer;
 
 		if (!this._gridClusters) {
 			this._generateInitialClusters();
 		}
 
-		for (var i = 0, l = this._needsClustering.length; i < l; i++) {
-			var layer = this._needsClustering[i];
+		for (i = 0, l = this._needsRemoving.length; i < l; i++) {
+			layer = this._needsRemoving[i];
+			this._removeLayer(layer);
+		}
+		this._needsRemoving = [];
+
+		for (i = 0, l = this._needsClustering.length; i < l; i++) {
+			layer = this._needsClustering[i];
 			if (layer.__parent) {
 				continue;
 			}
@@ -329,6 +345,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		}
 		this._needsClustering = [];
 
+
 		this._map.on('zoomend', this._zoomEnd, this);
 		this._map.on('moveend', this._moveEnd, this);
 
@@ -377,7 +394,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		for (var i = anArray.length - 1; i >= 0; i--) {
 			if (anArray[i] === obj) {
 				anArray.splice(i, 1);
-				return;
+				return true;
 			}
 		}
 	},

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