diff --git a/library/src/com/google/maps/android/clustering/ClusterManager.java b/library/src/com/google/maps/android/clustering/ClusterManager.java index b4faa597c..68e11e079 100644 --- a/library/src/com/google/maps/android/clustering/ClusterManager.java +++ b/library/src/com/google/maps/android/clustering/ClusterManager.java @@ -46,7 +46,8 @@ public class ClusterManager implements GoogleMap.OnCameraIdleListener, GoogleMap.OnMarkerClickListener, - GoogleMap.OnInfoWindowClickListener { + GoogleMap.OnInfoWindowClickListener, + GoogleMap.OnInfoWindowCloseListener { private final MarkerManager mMarkerManager; private final MarkerManager.Collection mMarkers; @@ -218,14 +219,23 @@ public void onCameraIdle() { // Don't re-compute clusters if the map has just been panned/tilted/rotated. } else if (mPreviousCameraPosition == null || mPreviousCameraPosition.zoom != mMap.getCameraPosition().zoom) { - mPreviousCameraPosition = mMap.getCameraPosition(); cluster(); } + mPreviousCameraPosition = mMap.getCameraPosition(); } @Override public boolean onMarkerClick(Marker marker) { - return getMarkerManager().onMarkerClick(marker); + final boolean markerClick = getMarkerManager().onMarkerClick(marker); + if (!markerClick) { + mAlgorithm.setShouldReclusterOnMapMovement(false); + } + return markerClick; + } + + @Override + public void onInfoWindowClose(final Marker marker) { + mAlgorithm.setShouldReclusterOnMapMovement(true); } @Override diff --git a/library/src/com/google/maps/android/clustering/algo/NonHierarchicalViewBasedAlgorithm.java b/library/src/com/google/maps/android/clustering/algo/NonHierarchicalViewBasedAlgorithm.java index ecacf1df2..383c543b9 100644 --- a/library/src/com/google/maps/android/clustering/algo/NonHierarchicalViewBasedAlgorithm.java +++ b/library/src/com/google/maps/android/clustering/algo/NonHierarchicalViewBasedAlgorithm.java @@ -41,6 +41,8 @@ public class NonHierarchicalViewBasedAlgorithm private LatLng mMapCenter; + private boolean shouldReclusterOnMapMovement = true; + public NonHierarchicalViewBasedAlgorithm(int screenWidth, int screenHeight) { mViewWidth = screenWidth; mViewHeight = screenHeight; @@ -58,7 +60,7 @@ protected Collection> getClusteringItems(PointQuadTree> @Override public boolean shouldReclusterOnMapMovement() { - return true; + return shouldReclusterOnMapMovement; } /** @@ -72,6 +74,10 @@ public void updateViewSize(int width, int height) { mViewHeight = height; } + public void setShouldReclusterOnMapMovement(final boolean shouldReclusterOnMapMovement) { + this.shouldReclusterOnMapMovement = shouldReclusterOnMapMovement; + } + private Bounds getVisibleBounds(int zoom) { if (mMapCenter == null) { return new Bounds(0, 0, 0, 0); diff --git a/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithm.java b/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithm.java index c08028509..dd960c285 100644 --- a/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithm.java +++ b/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithm.java @@ -28,4 +28,6 @@ public interface ScreenBasedAlgorithm extends Algorithm, GoogleMap.OnCameraChangeListener { boolean shouldReclusterOnMapMovement(); + + void setShouldReclusterOnMapMovement(boolean shouldReclusterOnMapMovement); } diff --git a/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithmAdapter.java b/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithmAdapter.java index 49e97cc27..73616922a 100644 --- a/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithmAdapter.java +++ b/library/src/com/google/maps/android/clustering/algo/ScreenBasedAlgorithmAdapter.java @@ -36,6 +36,10 @@ public boolean shouldReclusterOnMapMovement() { return false; } + public void setShouldReclusterOnMapMovement(final boolean shouldReclusterOnMapMovement) { + // always do not recluster + } + @Override public void addItem(T item) { mAlgorithm.addItem(item);