From 2a0a62f3f0b45ee33a28104ef6ca2a2511c1dd31 Mon Sep 17 00:00:00 2001 From: danzel Date: Tue, 24 Jul 2012 16:12:27 +1200 Subject: [PATCH] Cluster everything up from the bottom. Makes clustering look visually pleasing and gets rid of artifacts from old clustering. Some dead code removal from this change next... --- src/MarkerClusterGroup.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 1d2f78a8a..3c9a1ad84 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -60,23 +60,23 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ }, _generateInitialClusters: function () { - var res = this._topClusterLevel = this._clusterToMarkerCluster(this._needsClustering, this._map.getZoom()), - minZoom = this._map.getMinZoom(); + var minZoom = this._map.getMinZoom(), + maxZoom = this._map.getMaxZoom(), + currentZoom = this._map.getZoom(); - //Generate 2 levels up if we can - if (minZoom < this._topClusterLevel._zoom && this._topClusterLevel._childCount > 1) { + this._topClusterLevel = this._clusterToMarkerCluster(this._needsClustering, maxZoom); + + //Generate to the top + while (minZoom < this._topClusterLevel._zoom) { this._topClusterLevel = this._clusterToMarkerCluster(this._topClusterLevel._childClusters.concat(this._topClusterLevel._markers), this._topClusterLevel._zoom - 1); - if (minZoom < this._topClusterLevel._zoom && this._topClusterLevel._childCount > 1) { - this._topClusterLevel = this._clusterToMarkerCluster(this._topClusterLevel._childClusters.concat(this._topClusterLevel._markers), this._topClusterLevel._zoom - 1); - } } //Remember the current zoom level and bounds - this._zoom = this._map._zoom; + this._zoom = currentZoom; this._currentShownBounds = this._getExpandedVisibleBounds(); //Make things appear on the map - res._recursivelyAddChildrenToMap(null, 1, this._getExpandedVisibleBounds()); + this._topClusterLevel._recursivelyAddChildrenToMap(null, currentZoom - minZoom + 1, this._currentShownBounds); }, //Merge and split any existing clusters that are too big or small