[Pkg-javascript-commits] [leaflet-markercluster] 161/479: use first point as centers while clustering, use weighted centers on display

Jonas Smedegaard dr at jones.dk
Thu Oct 16 16:00:25 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 f3fddb835d6d4197291501765da0f87e1a25e7dd
Author: Vladimir Agafonkin <agafonkin at gmail.com>
Date:   Fri Aug 10 14:27:32 2012 +0300

    use first point as centers while clustering, use weighted centers on display
---
 src/MarkerCluster.js | 19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index eb0d05c..23016fd 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -42,6 +42,7 @@ L.MarkerCluster = L.Marker.extend({
 	},
 
 	_baseInit: function () {
+		this._latlng = this._wLatLng;
 		L.Marker.prototype.initialize.call(this, this._latlng, { icon: this._group.options.iconCreateFunction(this._childCount) });
 	},
 
@@ -64,25 +65,29 @@ L.MarkerCluster = L.Marker.extend({
 	_expandBounds: function (marker) {
 
 		var addedCount,
-		    addedLatLng;
+		    addedLatLng = marker._latlng;
 
 		if (marker instanceof L.MarkerCluster) {
 			this._bounds.extend(marker._bounds);
 			addedCount = marker._childCount;
-			addedLatLng = marker._latlng;
 		} else {
-			addedLatLng = marker.getLatLng();
 			this._bounds.extend(addedLatLng);
 			addedCount = 1;
 		}
 
+		if (!this._latlng) {
+			// when clustering, take position of the first point as the cluster center
+			this._latlng = addedLatLng;
+		}
+
+		// when showing clusters, take weighted average of all points as cluster center
 		var totalCount = this._childCount + addedCount;
 
-		if (!this._latlng) {
-			this._latlng = new L.LatLng(addedLatLng.lat, addedLatLng.lng);
+		if (!this._wLatLng) {
+			this._wLatLng = new L.LatLng(addedLatLng.lat, addedLatLng.lng);
 		} else {
-			this._latlng.lat = (addedLatLng.lat * addedCount + this._latlng.lat * this._childCount) / totalCount;
-			this._latlng.lng = (addedLatLng.lng * addedCount + this._latlng.lng * this._childCount) / totalCount;
+			this._wLatLng.lat = (addedLatLng.lat * addedCount + this._wLatLng.lat * this._childCount) / totalCount;
+			this._wLatLng.lng = (addedLatLng.lng * addedCount + this._wLatLng.lng * this._childCount) / totalCount;
 		}
 	},
 

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