From ef2a51235eea7b233992c45c6cf87d888ebd3993 Mon Sep 17 00:00:00 2001 From: danzel Date: Thu, 1 Nov 2012 09:45:04 +1300 Subject: [PATCH] Unset layer.__parent in removeLayers as well as removeLayer. Refs #44 --- src/MarkerClusterGroup.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 17c9e7582..850a93724 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -110,8 +110,6 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ layer.setOpacity(1); } - delete layer.__parent; - return this; }, @@ -124,6 +122,11 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ for (var i = 0, l = layersArray.length; i < l; i++) { var m = layersArray[i]; + + if (this.hasLayer(m)) { + continue; + } + this._addLayer(m, this._maxZoom); //If we just made a cluster of size 2 then we need to remove the other marker from the map (if it is) or we never will @@ -389,6 +392,8 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ cluster = cluster.__parent; } + + delete marker.__parent; }, //Overrides FeatureGroup._propagateEvent @@ -547,10 +552,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //Try find a marker close by to form a new cluster with closest = gridUnclustered[zoom].getNearObject(markerPoint); if (closest) { - if (closest.__parent) { + var parent = closest.__parent; + if (parent) { this._removeLayer(closest, false); } - var parent = closest.__parent; //Create new cluster with these 2 in it