diff --git a/src/MarkerCluster.Spiderfier.js b/src/MarkerCluster.Spiderfier.js
index c814bcefa6..be6f6af9cc 100644
--- a/src/MarkerCluster.Spiderfier.js
+++ b/src/MarkerCluster.Spiderfier.js
@@ -40,11 +40,12 @@ L.MarkerCluster.include({
this._animationSpiderfy(childMarkers, positions);
},
- unspiderfy: function () {
+ unspiderfy: function (zoomDetails) {
+ /// Argument from zoomanim if being called in a zoom animation or null otherwise
if (this._group._inZoomAnimation) {
return;
}
- this._animationUnspiderfy();
+ this._animationUnspiderfy(zoomDetails);
this._group._spiderfied = null;
},
@@ -225,10 +226,10 @@ L.MarkerCluster.include(!L.DomUtil.TRANSITION ? {
}, 250);
},
- _animationUnspiderfy: function () {
+ _animationUnspiderfy: function (zoomDetails) {
var group = this._group,
map = group._map,
- thisLayerPos = map.latLngToLayerPoint(this._latlng),
+ thisLayerPos = zoomDetails ? map._latLngToNewLayerPoint(this._latlng, zoomDetails.zoom, zoomDetails.center) : map.latLngToLayerPoint(this._latlng),
childMarkers = this.getAllChildMarkers(),
svg = L.Browser.svg,
m, i, a;
@@ -305,7 +306,8 @@ L.MarkerClusterGroup.include({
_spiderfied: null,
_spiderfierOnAdd: function () {
- this._map.on('click zoomstart', this._unspiderfy, this);
+ this._map.on('click', this._unspiderfyWrapper, this);
+ this._map.on('zoomstart', this._unspiderfyZoomStart, this);
if (L.Browser.svg) {
this._map._initPathRoot(); //Needs to happen in the pageload, not after, or animations don't work in chrome
@@ -315,12 +317,30 @@ L.MarkerClusterGroup.include({
},
_spiderfierOnRemove: function () {
- this._map.off('click zoomstart', this._unspiderfy, this);
+ this._map.off('click', this._unspiderfyWrapper, this);
+ this._map.off('zoomstart', this._unspiderfyZoomStart, this);
},
- _unspiderfy: function () {
+
+ //On zoom start we add a zoomanim handler so that we are guaranteed to be last (after markers are animated)
+ //This means we can define the animation they do rather than Markers doing an animation to their actual location
+ _unspiderfyZoomStart: function () {
+ this._map.on('zoomanim', this._unspiderfyZoomAnim, this);
+ },
+ _unspiderfyZoomAnim: function (zoomDetails) {
+ this._map.off('zoomanim', this._unspiderfyZoomAnim, this);
+ this._unspiderfy(zoomDetails);
+ },
+
+
+ _unspiderfyWrapper: function () {
+ /// _unspiderfy but passes no arguments
+ this._unspiderfy();
+ },
+
+ _unspiderfy: function (zoomDetails) {
if (this._spiderfied) {
- this._spiderfied.unspiderfy();
+ this._spiderfied.unspiderfy(zoomDetails);
}
},