[Pkg-javascript-commits] [leaflet-markercluster] 75/479: Do backwards loops for some tiny performance win.
Jonas Smedegaard
dr at jones.dk
Thu Oct 16 16:00:12 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 6e81c385e17d05e4ede7b83fac26b03755281333
Author: danzel <danzel at localhost.geek.nz>
Date: Mon Jul 23 14:38:24 2012 +1200
Do backwards loops for some tiny performance win.
---
src/MarkerCluster.js | 17 +++++++++--------
src/MarkerClusterGroup.js | 7 +++----
2 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js
index 64a4873..3ece9f3 100644
--- a/src/MarkerCluster.js
+++ b/src/MarkerCluster.js
@@ -20,11 +20,11 @@ L.MarkerCluster = L.Marker.extend({
getAllChildMarkers: function (storageArray) {
storageArray = storageArray || [];
- for (var i = 0; i < this._childClusters.length; i++) {
+ for (var i = this._childClusters.length - 1; i >= 0; i--) {
this._childClusters[i].getAllChildMarkers(storageArray);
}
- for (var j = 0; j < this._markers.length; j++) {
+ for (var j = this._markers.length - 1; j >= 0; j--) {
storageArray.push(this._markers[j]);
}
@@ -236,7 +236,8 @@ L.MarkerCluster = L.Marker.extend({
c._recursivelyAnimateChildrenIn(bounds, c._group._map.latLngToLayerPoint(c.getLatLng()).round(), depthToAnimateIn);
//TODO: depthToAnimateIn affects _isSingleParent, if there is a multizoom we may/may not be.
- if (c._isSingleParent() && depthToAnimateIn === 1) { //TODO: If we are the same as our parent, don't do an animation, just immediately appear
+ //As a hack we only do a animation free zoom on a single level zoom, if someone does multiple levels then we always animate
+ if (c._isSingleParent() && depthToAnimateIn === 1) {
c.setOpacity(1);
c._recursivelyRemoveChildrenFromMap(bounds, depthToAnimateIn - 1); //Immediately remove our children as we are replacing them. TODO previousBounds not bounds
} else {
@@ -262,7 +263,7 @@ L.MarkerCluster = L.Marker.extend({
}
//Add our child markers at startPos (so they can be animated out)
- for (var i = 0; i < c._markers.length; i++) {
+ for (var i = c._markers.length - 1; i >= 0; i--) {
var nm = c._markers[i];
if (!bounds.contains(nm._latlng)) {
@@ -288,7 +289,7 @@ L.MarkerCluster = L.Marker.extend({
_recursivelyRestoreChildPositions: function (depth) {
//Fix positions of child markers
- for (var i = 0; i < this._markers.length; i++) {
+ for (var i = this._markers.length - 1; i >= 0; i--) {
var nm = this._markers[i];
if (nm._backupLatlng) {
nm.setLatLng(nm._backupLatlng);
@@ -298,11 +299,11 @@ L.MarkerCluster = L.Marker.extend({
if (depth === 1) {
//Reposition child clusters
- for (var j = 0; j < this._childClusters.length; j++) {
+ for (var j = this._childClusters.length - 1; j >= 0; j--) {
this._childClusters[j]._restorePosition();
}
} else {
- for (var k = 0; k < this._childClusters.length; k++) {
+ for (var k = this._childClusters.length - 1; k >= 0; k--) {
this._childClusters[k]._recursivelyRestoreChildPositions(depth - 1);
}
}
@@ -352,7 +353,7 @@ L.MarkerCluster = L.Marker.extend({
var childClusters = this._childClusters,
i, c;
- //TODO: When zooming down we need to generate new clusters for levels that don't have them yet
+ //When zooming down we need to generate new clusters for levels that don't have them yet
if (!this._haveGeneratedChildClusters && (depthToStartAt > 0 || timesToRecurse > 0)) {
this._generateChildClusters();
}
diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js
index b2a157e..3390b8d 100644
--- a/src/MarkerClusterGroup.js
+++ b/src/MarkerClusterGroup.js
@@ -170,14 +170,14 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
i, j, c;
//go through each point
- for (i = 0; i < toCluster.length; i++) {
+ for (i = toCluster.length - 1; i >= 0; i--) {
var point = toCluster[i],
used = false;
point._projCenter = this._map.project(point.getLatLng(), zoom); //Calculate pixel position
//try add it to an existing cluster
- for (j = 0; j < clusters.length; j++) {
+ for (j = clusters.length - 1; j >= 0; j--) {
c = clusters[j];
if (this._sqDist(point._projCenter, c._projCenter) <= clusterRadiusSqrd) {
c._addChild(point);
@@ -219,7 +219,7 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
}
//Remove the _projCenter temp variable from clusters
- for (i = 0; i < clusters.length; i++) {
+ for (i = clusters.length - 1; i >= 0; i--) {
delete clusters[i]._projCenter;
clusters[i]._baseInit();
}
@@ -411,7 +411,6 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
me._animationStart();
me._animationZoomOutSingle(newCluster, 0, 1);
}, 0);
- //newCluster._recursivelyAnimateChildrenInAndAddSelfToMap(newCluster._bounds, 0, 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