[Pkg-javascript-commits] [leaflet-markercluster] 45/479: Add _recursively and refactor _recursivelyRemoveChildrenFromMap to use it
Jonas Smedegaard
dr at jones.dk
Thu Oct 16 16:00:07 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 de35c09a016b9528a4d6040666870b022f535c76
Author: danzel <danzel at localhost.geek.nz>
Date: Thu Jul 19 11:43:02 2012 +1200
Add _recursively and refactor _recursivelyRemoveChildrenFromMap to use it
---
src/MarkerCluster.js | 69 +++++++++++++++++++++++++++++++++++++---------------
1 file changed, 50 insertions(+), 19 deletions(-)
diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index b760110..f3d7085 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -286,28 +286,59 @@ L.MarkerCluster = L.Marker.extend({
//depth 1 means I remove my immediate children from the map
_recursivelyRemoveChildrenFromMap: function (previousBounds, depth) {
- //TODO: Use previousBounds so we only bother looking at ones that weren't on screen
- var m;
- //markers
- for (var i = 0; i < this._markers.length; i++) {
- m = this._markers[i];
- L.FeatureGroup.prototype.removeLayer.call(this._group, m);
- m.setOpacity(1);
- }
+ var m, i;
+ this._recursively(previousBounds, 0, depth,
+ function (c) {
+ //Remove markers at every level
+ for (i = c._markers.length - 1; i >= 0; i--) {
+ m = c._markers[i];
+ L.FeatureGroup.prototype.removeLayer.call(c._group, m);
+ m.setOpacity(1);
+ }
+ },
+ function (c) {
+ //Remove child clusters at just the bottom level
+ for (i = c._childClusters.length - 1; i >= 0; i--) {
+ m = c._childClusters[i];
+ L.FeatureGroup.prototype.removeLayer.call(c._group, m);
+ m.setOpacity(1);
+ }
+ }
+ );
+ },
- if (depth === 1) {
- //child clusters
- for (var j = 0; j < this._childClusters.length; j++) {
- m = this._childClusters[j];
- L.FeatureGroup.prototype.removeLayer.call(this._group, m);
- m.setOpacity(1);
+ //Run the given functions recursively to this and child clusters
+ // boundsToApplyTo: a L.LatLngBounds representing the bounds of what clusters to recurse in to
+ // depthToStartAt: the depth to start calling the given functions
+ // depthToRunFor: how many layers deep to recurse in to, bottom level: depthToRunFor == 0
+ // runAtEveryLevel: function that takes an L.MarkerCluster as an argument that should be applied on every level
+ // runAtBottomLevel: function that takes an L.MarkerCluster as an argument that should be applied at only the bottom level
+ _recursively: function (boundsToApplyTo, depthToStartAt, depthToRunFor, runAtEveryLevel, runAtBottomLevel) {
+ var childClusters = this._childClusters,
+ i, c;
+
+ if (depthToStartAt > 0) { //Still going down to required depth, just recurse to child clusters
+ for (i = childClusters.length - 1; i >= 0; i--) {
+ c = childClusters[i];
+ if (boundsToApplyTo.intersects(c._bounds)) {
+ c._recursively(boundsToApplyTo, depthToStartAt - 1, depthToRunFor, runAtEveryLevel, runAtBottomLevel);
+ }
}
- } else {
- var childClusters = this._childClusters,
- childClustersLength = childClusters.length;
+ } else { //In required depth
- for (var k = 0; k < childClustersLength; k++) {
- childClusters[k]._recursivelyRemoveChildrenFromMap(previousBounds, depth - 1);
+ runAtEveryLevel(this);
+ if (depthToRunFor == 0 && runAtBottomLevel) {
+ runAtBottomLevel(this);
+ }
+
+ //TODO: This loop is almost the same as above
+ if (depthToRunFor > 0) {
+ for (i = childClusters.length - 1; i >= 0; i--) {
+ c = childClusters[i];
+ if (boundsToApplyTo.intersects(c._bounds)) {
+ c._recursively(boundsToApplyTo, depthToStartAt, depthToRunFor - 1, runAtEveryLevel, runAtBottomLevel);
+ }
+ }
}
}
},
--
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