[Pkg-javascript-commits] [leaflet-markercluster] 157/219: Replaced bounds reset method extension by cluster private method

Jonas Smedegaard dr at jones.dk
Sat May 7 09:39:30 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 1c4a5f62ce717c5cc73a0e6effe96e8e727df7dc
Author: ghybs <ghybs1 at gmail.com>
Date:   Thu Oct 22 10:08:46 2015 +0400

    Replaced bounds reset method extension by cluster private method
    
    Following danzel's comment https://github.com/Leaflet/Leaflet.markercluster/pull/584#issuecomment-149748066, replaced the L.LatLngBounds class extension (method reset) by a private method _resetBounds within L.MarkerCluster.
---
 src/MarkerCluster.js | 21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index 2d16ba8..90bd998 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -134,6 +134,25 @@ L.MarkerCluster = L.Marker.extend({
 		}
 	},
 
+	/**
+	 * Assigns impossible bounding values so that the next extend entirely determines the new bounds.
+	 * This method avoids having to trash the previous L.LatLngBounds object and to create a new one, which is much slower for this class.
+	 * As long as the bounds are not extended, most other methods would probably fail, as they would with bounds initialized but not extended.
+	 * @private
+	 */
+	_resetBounds: function () {
+		var bounds = this._bounds;
+
+		if (bounds._southWest) {
+			bounds._southWest.lat = Infinity;
+			bounds._southWest.lng = Infinity;
+		}
+		if (bounds._northEast) {
+			bounds._northEast.lat = -Infinity;
+			bounds._northEast.lng = -Infinity;
+		}
+	},
+
 	_recalculateBounds: function () {
 		var markers = this._markers,
 		    childClusters = this._childClusters,
@@ -148,7 +167,7 @@ L.MarkerCluster = L.Marker.extend({
 		}
 
 		// Reset rather than creating a new object, for performance.
-		this._bounds.reset();
+		this._resetBounds();
 
 		// Child markers.
 		for (i = 0; i < markers.length; i++) {

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