From d032b53fea74b3a6fe1514cbd7ba4f6637225eb6 Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 21 Jun 2013 16:55:38 +1200 Subject: [PATCH] Fix places we were looping over this._layers to use this._featureGroup.eachLayer instead. Fixes child markers not being added to the map. --- src/MarkerClusterGroup.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 1f820a10f..58c51b950 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -166,12 +166,11 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ } //Update the icons of all those visible clusters that were affected - for (i in this._layers) { - m = this._layers[i]; - if (m instanceof L.MarkerCluster && m._iconNeedsUpdate) { - m._updateIcon(); + fg.eachLayer(function (c) { + if (c instanceof L.MarkerCluster && c._iconNeedsUpdate) { + c._updateIcon(); } - } + }); this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds); @@ -180,7 +179,8 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //Takes an array of markers and removes them in bulk removeLayers: function (layersArray) { - var i, l, m; + var i, l, m, + fg = this._featureGroup; if (!this._map) { for (i = 0, l = layersArray.length; i < l; i++) { @@ -198,8 +198,8 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ this._removeLayer(m, true, true); - if (this._featureGroup.hasLayer(m)) { - this._featureGroup.removeLayer(m); + if (fg.hasLayer(m)) { + fg.removeLayer(m); if (m.setOpacity) { m.setOpacity(1); } @@ -209,12 +209,11 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ //Fix up the clusters and markers on the map this._topClusterLevel._recursivelyAddChildrenToMap(null, this._zoom, this._currentShownBounds); - for (i in this._layers) { - m = this._layers[i]; - if (m instanceof L.MarkerCluster) { - m._updateIcon(); + fg.eachLayer(function (c) { + if (c instanceof L.MarkerCluster) { + c._updateIcon(); } - } + }); return this; }, @@ -824,18 +823,15 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? { }); this._forceLayout(); - var j, n; //Update opacities me._topClusterLevel._recursivelyBecomeVisible(bounds, newZoomLevel); //TODO Maybe? Update markers in _recursivelyBecomeVisible - for (j in me._layers) { - n = me._layers[j]; - + fg.eachLayer(function (n) { if (!(n instanceof L.MarkerCluster) && n._icon) { n.setOpacity(1); } - } + }); //update the positions of the just added clusters/markers me._topClusterLevel._recursively(bounds, previousZoomLevel, newZoomLevel, function (c) {