[Pkg-javascript-commits] [leaflet-markercluster] 73/479: Try keep around 2 levels on top of what we need so the tree is more efficient. Fixes #11

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:11 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 69b62e32503f504e0e2ba375d5af02428c0a247f
Author: danzel <danzel at localhost.geek.nz>
Date:   Mon Jul 23 14:10:35 2012 +1200

    Try keep around 2 levels on top of what we need so the tree is more efficient. Fixes #11
---
 src/MarkerClusterGroup.js | 20 +++++++++++++-------
 1 file changed, 13 insertions(+), 7 deletions(-)

diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 20f048a..a325903 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -6,7 +6,6 @@
 L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 	options: {
-		//distanceToCluster: 10, //Any points closer than this will probably get put in to a cluster
 		maxClusterRadius: 60, //A cluster will cover at most this many pixels from its center
 		iconCreateFunction: function (childCount) {
 			var c = ' marker-cluster-';
@@ -66,7 +65,16 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 
 	_generateInitialClusters: function () {
 		console.log('generating initial topCluster ' + this._map.getZoom());
-		var res = this._topClusterLevel = this._clusterToMarkerCluster(this._needsClustering, this._map.getZoom());
+		var res = this._topClusterLevel = this._clusterToMarkerCluster(this._needsClustering, this._map.getZoom()),
+			minZoom = this._map.getMinZoom();
+
+		//Generate 2 levels up if we can
+		if (minZoom < this._topClusterLevel._zoom && this._topClusterLevel._childCount > 1) {
+			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;
@@ -90,7 +98,8 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 		} else if (this._zoom > this._map._zoom) { //Zoom out, merge
 
 			//Ensure all of the intermediate zoom levels are generated, generating up happens outside of MarkerCluster
-			while (this._topClusterLevel._zoom > this._map._zoom) {
+			//We also try keep 2 more levels on top if we can so the tree is used more efficiently
+			while (this._topClusterLevel._zoom > Math.max(this._map.getMinZoom(), this._map._zoom - 2)) {
 				console.log('generating new topCluster for ' + (this._topClusterLevel._zoom - 1));
 				this._topClusterLevel = this._clusterToMarkerCluster(this._topClusterLevel._childClusters.concat(this._topClusterLevel._markers), this._topClusterLevel._zoom - 1);
 			}
@@ -105,12 +114,9 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
 			return this;
 		}
 
-		var me = this,
-			newCluster;
-
 		//If we have already clustered we'll need to add this one to a cluster
 
-		newCluster = this._topClusterLevel._recursivelyAddLayer(layer, this._topClusterLevel._zoom - 1);
+		var newCluster = this._topClusterLevel._recursivelyAddLayer(layer, this._topClusterLevel._zoom - 1);
 
 		this._animationAddLayer(layer, newCluster);
 

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