[Pkg-javascript-commits] [leaflet-markercluster] 152/219: Reset bounds rather than re-create
Jonas Smedegaard
dr at jones.dk
Sat May 7 09:39:29 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository leaflet-markercluster.
commit d9441c78c3a6fbf96604a8f002a989da95b3fb73
Author: ghybs <ghybs1 at gmail.com>
Date: Tue Oct 20 17:16:35 2015 +0400
Reset bounds rather than re-create
Added a new method "reset" to L.LatLngBounds to avoid having to re-create objects every time the bounds must be recomputed.
Also performed some clean-up.
---
src/MarkerCluster.js | 37 ++++++++++++++++++-------------------
src/MarkerClusterGroup.js | 10 +++-------
2 files changed, 21 insertions(+), 26 deletions(-)
diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index 90d387f..2d16ba8 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -142,13 +142,14 @@ L.MarkerCluster = L.Marker.extend({
totalCount = this._childCount,
i, child, childLatLng, childCount;
- this._bounds = new L.LatLngBounds();
-
// Case where all markers are removed from the map and we are left with just an empty _topClusterLevel.
if (totalCount === 0) {
return;
}
+ // Reset rather than creating a new object, for performance.
+ this._bounds.reset();
+
// Child markers.
for (i = 0; i < markers.length; i++) {
childLatLng = markers[i]._latlng;
@@ -378,26 +379,24 @@ L.MarkerCluster = L.Marker.extend({
}
},
- /**
- * Runs a function recursively on every child cluster, then on THIS cluster.
- * @param runAtEveryLevel function to be called on each cluster. Takes as single argument the cluster to be processed.
- * @private
- */
- _recursivelySimple: function (runAtEveryLevel) {
- var childClusters = this._childClusters,
- i = 0;
-
- for (; i < childClusters.length; i++) {
- childClusters[i]._recursivelySimple(runAtEveryLevel);
- }
-
- return runAtEveryLevel(this);
- },
-
-
//Returns true if we are the parent of only one cluster and that cluster is the same as us
_isSingleParent: function () {
//Don't need to check this._markers as the rest won't work if there are any
return this._childClusters.length > 0 && this._childClusters[0]._childCount === this._childCount;
}
});
+
+/**
+ * Assigns impossible bounding values so that the next extend entirely determines the new bounds.
+ * This method avoids having to trash the previous object and to create a new one, which is much slower for this class.
+ */
+L.LatLngBounds.prototype.reset = function () {
+ if (this._southWest) {
+ this._southWest.lat = Infinity;
+ this._southWest.lng = Infinity;
+ }
+ if (this._northEast) {
+ this._northEast.lat = -Infinity;
+ this._northEast.lng = -Infinity;
+ }
+};
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 492736e..8bf2e3c 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -105,7 +105,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
this._addLayer(layer, this._maxZoom);
- // Re-calculate bounds must be done manually now.
+ // Refresh bounds and weighted positions.
this._topClusterLevel._recalculateBounds();
//Work out what is visible
@@ -163,7 +163,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
//Remove the marker from clusters
this._removeLayer(layer, true);
- // Bounds and weighted position must be done manually now.
+ // Refresh bounds and weighted positions.
this._topClusterLevel._recalculateBounds();
if (this._featureGroup.hasLayer(layer)) {
@@ -314,7 +314,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
}
- // Re-compute bounds and weighted positions.
+ // Refresh bounds and weighted positions.
this._topClusterLevel._recalculateBounds();
//Fix up the clusters and markers on the map
@@ -526,9 +526,6 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
l = this._needsClustering;
this._needsClustering = [];
this.addLayers(l);
-
- // Re-compute bounds and weighted positions.
- this._topClusterLevel._recalculateBounds();
},
//Overrides FeatureGroup.onRemove
@@ -641,7 +638,6 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
}
} else {
- //cluster._recalculateBounds();
if (!dontUpdateMap || !cluster._icon) {
cluster._updateIcon();
}
--
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