From 9f84ee47a59114207e6eee86e23b9ee3f5b8f6bc Mon Sep 17 00:00:00 2001 From: Andrey Zaytsev Date: Wed, 17 May 2017 12:50:29 +0300 Subject: [PATCH 1/2] do not recluster when showing cluster info window --- .../maps/android/clustering/ClusterManager.java | 11 +++++++++-- .../algo/NonHierarchicalViewBasedAlgorithm.java | 8 +++++++- .../android/clustering/algo/ScreenBasedAlgorithm.java | 2 ++ .../clustering/algo/ScreenBasedAlgorithmAdapter.java | 4 ++++ 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/library/src/com/google/maps/android/clustering/ClusterManager.java b/library/src/com/google/maps/android/clustering/ClusterManager.java index b4faa597c..2b6c9eced 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,16 +219,22 @@ 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) { + mAlgorithm.setShouldReclusterOnMapMovement(false); return getMarkerManager().onMarkerClick(marker); } + @Override + public void onInfoWindowClose(final Marker marker) { + mAlgorithm.setShouldReclusterOnMapMovement(true); + } + @Override public void onInfoWindowClick(Marker marker) { getMarkerManager().onInfoWindowClick(marker); 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); From 2f1006a520a6df63439a082315a225810e7efb6e Mon Sep 17 00:00:00 2001 From: Andrey Zaytsev Date: Thu, 18 May 2017 09:26:33 +0300 Subject: [PATCH 2/2] disable recluster only on default map action --- .../com/google/maps/android/clustering/ClusterManager.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/library/src/com/google/maps/android/clustering/ClusterManager.java b/library/src/com/google/maps/android/clustering/ClusterManager.java index 2b6c9eced..68e11e079 100644 --- a/library/src/com/google/maps/android/clustering/ClusterManager.java +++ b/library/src/com/google/maps/android/clustering/ClusterManager.java @@ -226,8 +226,11 @@ public void onCameraIdle() { @Override public boolean onMarkerClick(Marker marker) { - mAlgorithm.setShouldReclusterOnMapMovement(false); - return getMarkerManager().onMarkerClick(marker); + final boolean markerClick = getMarkerManager().onMarkerClick(marker); + if (!markerClick) { + mAlgorithm.setShouldReclusterOnMapMovement(false); + } + return markerClick; } @Override