Use events rather than hacky setTimeouts to make zoomToShowLayer more reliable

This commit is contained in:
danzel
2012-09-12 11:13:02 +12:00
parent 122571d50c
commit 07a11582d3
2 changed files with 29 additions and 9 deletions
+2
View File
@@ -107,6 +107,7 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? {
m._spiderLeg = leg;
}
this.setOpacity(0.3);
group.fire('spiderfied');
},
_animationUnspiderfy: function () {
@@ -223,6 +224,7 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? {
setTimeout(function () {
group._animationEnd();
group.fire('spiderfied');
}, 250);
},
+27 -9
View File
@@ -149,17 +149,34 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({
},
zoomToShowLayer: function (layer, callback) {
layer.__parent.zoomToBounds();
setTimeout(function () {
if (layer._icon) {
callback();
} else {
layer.__parent.spiderfy();
setTimeout(function () {
var showMarker = function () {
if ((layer._icon || layer.__parent._icon) && !this._inZoomAnimation) {
this._map.off('moveend', showMarker, this);
this.off('animationend', showMarker, this);
if (layer._icon) {
callback();
}, L.DomUtil.TRANSITION ? 250 : 0); //TODO: This is hardcoded based on the time to spiderfy
} else if (layer.__parent._icon) {
var afterSpiderfy = function () {
this.off('spiderfied', afterSpiderfy, this);
callback();
};
this.on('spiderfied', afterSpiderfy, this);
layer.__parent.spiderfy();
}
}
}, L.DomUtil.TRANSITION ? 600 : 0); //TODO: This is hardcoded based on the leaflet time to zoom
};
if ((layer._icon || layer.__parent._icon) && this._map.getBounds().contains(layer.__parent._latlng)) {
//Layer or cluster is already visible
showMarker.call(this);
} else {
this._map.on('moveend', showMarker, this);
this.on('animationend', showMarker, this);
layer.__parent.zoomToBounds();
}
},
//Overrides FeatureGroup.onAdd
@@ -533,6 +550,7 @@ L.MarkerClusterGroup.include(!L.DomUtil.TRANSITION ? {
this._map._mapPane.className = this._map._mapPane.className.replace(' leaflet-cluster-anim', '');
}
this._inZoomAnimation--;
this.fire('animationend');
},
_animationZoomIn: function (previousZoomLevel, newZoomLevel) {
var me = this,