[Pkg-javascript-commits] [leaflet-markercluster] 72/479: get moveEnd working again!
Jonas Smedegaard
dr at jones.dk
Thu Oct 16 16:00:11 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 c2609c7dfb1769e9025e5b7eda20449f695ffccb
Author: danzel <danzel at localhost.geek.nz>
Date: Fri Jul 20 17:17:31 2012 +1200
get moveEnd working again!
---
src/MarkerCluster.js | 18 ++++++++++++------
src/MarkerClusterGroup.js | 47 +++++++++++++----------------------------------
2 files changed, 25 insertions(+), 40 deletions(-)
diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index 5875314..64a4873 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -242,6 +242,7 @@ L.MarkerCluster = L.Marker.extend({
} else {
c.setOpacity(0);
}
+
c._addToMap();
}
);
@@ -313,24 +314,29 @@ L.MarkerCluster = L.Marker.extend({
delete this._backupLatlng;
}
},
-
- _recursivelyRemoveChildrenFromMap: function (previousBounds, depth) {
+
+ //exceptBounds: If set, don't remove any markers/clusters in it
+ _recursivelyRemoveChildrenFromMap: function (previousBounds, depth, exceptBounds) {
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);
+ if (!exceptBounds || !exceptBounds.contains(m._latlng)) {
+ 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 (!exceptBounds || !exceptBounds.contains(m._latlng)) {
+ L.FeatureGroup.prototype.removeLayer.call(c._group, m);
+ m.setOpacity(1);
+ }
}
}
);
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index 2c4e893..20f048a 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -53,41 +53,15 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
if (this._inZoomAnimation > 0) {
return;
}
- return; //TODO FIXME OBV
- var l, i,
- layers = this._layers,
- bounds = this._getExpandedVisibleBounds(),
- highestLevel = this._markersAndClustersAtZoom[this._highestZoom],
- depth = this._zoom - this._highestZoom,
- highestLevelClusters = highestLevel.clusters,
- highestLevelUnclustered = highestLevel.unclustered;
-
- //Remove visible layers that are no longer visible
- for (i in layers) {
- l = layers[i];
- if (!bounds.contains(l.getLatLng())) {
- L.FeatureGroup.prototype.removeLayer.call(this, l);
- }
- }
- //Re-Check everyone for being in the viewport
- //Do the clusters (and their child unclustered ones) recursively for performance
- for (i = 0; i < highestLevelClusters.length; i++) {
- l = highestLevelClusters[i];
- if (bounds.intersects(l._bounds)) {
- l._recursivelyAddChildrenToMap(null, depth, bounds);
- }
- }
+ var newBounds = this._getExpandedVisibleBounds(),
+ depth = this._zoom - this._topClusterLevel._zoom;
- //Do the markers at this level too
- for (i = 0; i < highestLevelUnclustered.length; i++) {
- l = highestLevelUnclustered[i];
- if (bounds.contains(l.getLatLng())) {
- L.FeatureGroup.prototype.addLayer.call(this, l);
- }
- }
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, depth, newBounds);
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, depth + 1, newBounds);
- this._currentShownBounds = bounds;
+ this._currentShownBounds = newBounds;
+ return;
},
_generateInitialClusters: function () {
@@ -106,8 +80,10 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
_mergeSplitClusters: function () {
if (this._zoom < this._map._zoom) { //Zoom in, split
+ //Note: Clusters generate new children as needed on a zoom in
- //Clusters generate new children as needed on a zoom in
+ //Remove clusters now off screen
+ this._topClusterLevel._recursivelyRemoveChildrenFromMap(this._currentShownBounds, this._zoom - this._topClusterLevel._zoom, this._getExpandedVisibleBounds());
this._animationZoomIn(this._zoom, this._map._zoom);
@@ -267,7 +243,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
_getExpandedVisibleBounds: function () {
var map = this._map,
bounds = map.getPixelBounds(),
- width = Math.abs(bounds.max.x - bounds.min.x),
+ width = Math.abs(bounds.max.x - bounds.min.x),
height = Math.abs(bounds.max.y - bounds.min.y),
sw = map.unproject(new L.Point(bounds.min.x - width, bounds.min.y - height)),
ne = map.unproject(new L.Point(bounds.max.x + width, bounds.max.y + height));
@@ -376,6 +352,9 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
depthToAnimateIn = previousZoomLevel - newZoomLevel;
this._animationZoomOutSingle(this._topClusterLevel, depthToStartAt, depthToAnimateIn);
+
+ //Need to add markers for those that weren't on the map before but are now
+ this._topClusterLevel._recursivelyAddChildrenToMap(null, depthToStartAt, this._getExpandedVisibleBounds());
},
_animationZoomOutSingle: function (marker, depthToStartAt, depthToAnimateIn) {
var bounds = this._getExpandedVisibleBounds();
--
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