diff --git a/src/MarkerCluster.js b/src/MarkerCluster.js index a3a7d6797..cdca102ef 100644 --- a/src/MarkerCluster.js +++ b/src/MarkerCluster.js @@ -51,7 +51,7 @@ L.MarkerCluster = L.Marker.extend({ mapZoom = map.getZoom(), i; - //calculate how fare we need to zoom down to see all of the markers + //calculate how far we need to zoom down to see all of the markers while (childClusters.length > 0 && boundsZoom > zoom) { zoom++; var newClusters = []; diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 4b77fbfcd..da151055e 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -423,16 +423,27 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ }; if (layer._icon && this._map.getBounds().contains(layer.getLatLng())) { + //Layer is visible ond on screen, immediate return callback(); } else if (layer.__parent._zoom < this._map.getZoom()) { - //Layer should be visible now but isn't on screen, just pan over to it + //Layer should be visible at this zoom level. It must not be on screen so just pan over to it this._map.on('moveend', showMarker, this); this._map.panTo(layer.getLatLng()); } else { + var moveStart = function () { + this._map.off('movestart', moveStart, this); + moveStart = null; + }; + + this._map.on('movestart', moveStart, this); this._map.on('moveend', showMarker, this); this.on('animationend', showMarker, this); - this._map.setView(layer.getLatLng(), layer.__parent._zoom + 1); layer.__parent.zoomToBounds(); + + if (moveStart) { + //Never started moving, must already be there, probably need clustering however + showMarker.call(this); + } } },