From aed28169864424daaa6a680f0a7173811187efcd Mon Sep 17 00:00:00 2001 From: danzel Date: Fri, 10 Aug 2012 16:05:49 +1200 Subject: [PATCH] Clone the LatLng rather than taking a reference so we don't break it when we edit it. --- src/MarkerCluster.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js index cb8a033f8..eb0d05c56 100644 --- a/src/MarkerCluster.js +++ b/src/MarkerCluster.js @@ -46,6 +46,7 @@ L.MarkerCluster = L.Marker.extend({ }, _addChild: function (new1) { + this._expandBounds(new1); if (new1 instanceof L.MarkerCluster) { this._childClusters.push(new1); this._childCount += new1._childCount; @@ -58,7 +59,6 @@ L.MarkerCluster = L.Marker.extend({ this.setIcon(this._group.options.iconCreateFunction(this._childCount)); } - this._expandBounds(new1); }, _expandBounds: function (marker) { @@ -79,7 +79,7 @@ L.MarkerCluster = L.Marker.extend({ var totalCount = this._childCount + addedCount; if (!this._latlng) { - this._latlng = addedLatLng; + this._latlng = 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;