Clone the LatLng rather than taking a reference so we don't break it when we edit it.

This commit is contained in:
danzel
2012-08-10 16:05:49 +12:00
parent 7b568d10e6
commit aed2816986
+2 -2
View File
@@ -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;