Replace setTimeout(..., 0) calls with explicit forceLayout calls, tidier code.

This commit is contained in:
danzel
2012-07-25 14:03:23 +12:00
parent fbd46fd2b8
commit 7537fb0986
2 changed files with 105 additions and 102 deletions
+3 -5
View File
@@ -143,7 +143,7 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? {
L.FeatureGroup.prototype.addLayer.call(group, m);
}
setTimeout(function () {
this._group._forceLayout();
group._animationStart();
var initialLegOpacity = L.Browser.svg ? 0 : 0.3,
@@ -198,23 +198,21 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? {
//Set the opacity of the spiderLegs back to their correct value
// The animations above override this until they complete.
// Doing this at 250ms causes some minor flickering on FF, so just do it immediately
// If the initial opacity of the spiderlegs isn't 0 then they appear before the animation starts.
if (L.Browser.svg) {
setTimeout(function () {
this._group._forceLayout();
for (i = childMarkers.length - 1; i >= 0; i--) {
m = childMarkers[i]._spiderLeg;
m.options.opacity = 0.5;
m._path.setAttribute('stroke-opacity', 0.5);
}
}, 0);
}
setTimeout(function () {
group._animationEnd();
}, 250);
}, 0);
},
_animationUnspiderfy: function () {
+16 -11
View File
@@ -305,8 +305,7 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
});
//Immediately fire an event to update the opacity and locations (If we immediately set it they won't animate)
setTimeout(function () {
this._forceLayout();
var j, n;
//Update opacities
@@ -326,7 +325,6 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
me._topClusterLevel._recursively(bounds, depthToStartAt, 0, function (c) {
c._recursivelyRestoreChildPositions(depthToDescend);
});
}, 0);
this._inZoomAnimation++;
@@ -361,10 +359,9 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
var me = this;
//Immediately fire an event to update the opacity (If we immediately set it they won't animate)
setTimeout(function () {
//Update the opacity (If we immediately set it they won't animate)
this._forceLayout();
marker._recursivelyBecomeVisible(bounds, depthToStartAt);
}, 0);
//TODO: Maybe use the transition timing stuff to make this more reliable
//When the animations are done, tidy up
@@ -383,9 +380,8 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
if (newCluster !== layer) {
if (newCluster._childCount > 2) { //Was already a cluster
this._forceLayout();
this._animationStart();
setTimeout(function () {
var backupLatlng = layer.getLatLng();
layer.setLatLng(newCluster._latlng);
@@ -397,14 +393,23 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
me._animationEnd();
}, 250);
}, 0);
} else { //Just became a cluster
setTimeout(function () {
this._forceLayout();
me._animationStart();
me._animationZoomOutSingle(newCluster, 0, 1);
}, 0);
}
}
},
//Force a browser layout of stuff in the map
// Should apply the current opacity and location to all elements so we can update them again for an animation
_forceLayout: function () {
//In my testing this works, infact offsetWidth of any element seems to work.
//Could loop all this._layers and do this for each _icon if it stops working
L.Util.falseFn(document.body.offsetWidth);
}
});