[Pkg-javascript-commits] [leaflet-markercluster] 37/479: Working towards fixing adding/removing. Think I'm going to have to bite the bullet and tree this up harder.
Jonas Smedegaard
dr at jones.dk
Thu Oct 16 16:00:06 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 0a29135aec1a8e279675313dd0813415283f5715
Author: danzel <danzel at localhost.geek.nz>
Date: Wed Jul 18 14:09:15 2012 +1200
Working towards fixing adding/removing. Think I'm going to have to bite the bullet and tree this up harder.
---
src/MarkerCluster.js | 32 +++++++++++++++++++++++++++++---
src/MarkerClusterGroup.js | 2 +-
2 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index a477496..bb6386d 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -85,7 +85,7 @@ L.MarkerCluster = L.Marker.extend({
for (i = markers.length - 1; i >= 0; i--) {
if (markers[i] == layer) {
markers.splice(i, 1);
- //TODO? Recalculate bounds
+ this._recalculateBounds();
this._childCount--;
if (this._icon) {
@@ -97,9 +97,17 @@ L.MarkerCluster = L.Marker.extend({
//Otherwise check our childClusters
for (i = childClusters.length - 1; i >= 0; i--) {
- if (childClusters[i]._recursivelyRemoveChildMarker(layer)) {
+ var child = childClusters[i];
+ if (child._recursivelyRemoveChildMarker(layer)) {
this._childCount--;
- //TODO? Recalculate bounds
+
+ //if our child cluster is no longer a cluster, remove it and replace with just the marker
+ if (child._childCount === 1) {
+ markers.push(child._markers[0]);
+ childClusters.splice(i, 1);
+ }
+
+ this._recalculateBounds();
if (this._icon) {
this.setIcon(this._group.options.iconCreateFunction(this._childCount));
@@ -231,6 +239,24 @@ L.MarkerCluster = L.Marker.extend({
}
},
+ _recalculateBounds: function () {
+ var markers = this._markers,
+ childClusters = this._childClusters,
+ i;
+
+ this._bounds = new L.LatLngBounds();
+
+ for (i = markers.length - 1; i >= 0; i--) {
+ this._bounds.extend(markers[i].getLatLng());
+ }
+ for (i = childClusters.length - 1; i >= 0; i--) {
+ this._bounds.extend(childClusters[i]._bounds);
+ }
+
+ this.setLatLng(this._bounds.getCenter());
+ },
+
+
//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
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 3cef276..5ca6120 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -235,7 +235,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
if (c._childCount == 1) {
//Remove cluster and add individual marker
L.FeatureGroup.prototype.removeLayer.call(this, c);
- var marker = c.getAllChildMarkers()[0];
+ var marker = c._markers[0];
L.FeatureGroup.prototype.addLayer.call(this, marker);
current.unclustered.push(marker);
current.clusters.splice(i, 1);
--
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