From 592658ddf6114753e4773e78986778f327711c21 Mon Sep 17 00:00:00 2001 From: Elizabeth Stevenson Date: Tue, 6 Dec 2016 10:34:59 +1100 Subject: [PATCH 1/2] Added function setAnimation in ClusterRenderer and ClusterManager so animation can be turned on/off. --- .../maps/android/clustering/ClusterManager.java | 4 ++++ .../android/clustering/view/ClusterRenderer.java | 5 +++++ .../clustering/view/DefaultClusterRenderer.java | 14 ++++++++++++-- 3 files changed, 21 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 f1eb25eec..83b5d25f1 100644 --- a/library/src/com/google/maps/android/clustering/ClusterManager.java +++ b/library/src/com/google/maps/android/clustering/ClusterManager.java @@ -119,6 +119,10 @@ public void setAlgorithm(Algorithm algorithm) { cluster(); } + public void setAnimation(boolean animate) { + mRenderer.setAnimation(animate); + } + public ClusterRenderer getRenderer() { return mRenderer; } diff --git a/library/src/com/google/maps/android/clustering/view/ClusterRenderer.java b/library/src/com/google/maps/android/clustering/view/ClusterRenderer.java index 91c25f702..5c01acae9 100644 --- a/library/src/com/google/maps/android/clustering/view/ClusterRenderer.java +++ b/library/src/com/google/maps/android/clustering/view/ClusterRenderer.java @@ -41,6 +41,11 @@ public interface ClusterRenderer { void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItemInfoWindowClickListener listener); + /** + * Called to set animation on or off + */ + void setAnimation(boolean animate); + /** * Called when the view is added. */ diff --git a/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java b/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java index 9dc9197ef..ff6b35cfb 100644 --- a/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java +++ b/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java @@ -79,6 +79,7 @@ public class DefaultClusterRenderer implements ClusterRen private final IconGenerator mIconGenerator; private final ClusterManager mClusterManager; private final float mDensity; + private boolean mAnimate; private static final int[] BUCKETS = {10, 20, 50, 100, 200, 500, 1000}; private ShapeDrawable mColoredCircleBackground; @@ -129,6 +130,7 @@ public class DefaultClusterRenderer implements ClusterRen public DefaultClusterRenderer(Context context, GoogleMap map, ClusterManager clusterManager) { mMap = map; + mAnimate = true; mDensity = context.getResources().getDisplayMetrics().density; mIconGenerator = new IconGenerator(context); mIconGenerator.setContentView(makeSquareTextView(context)); @@ -395,7 +397,7 @@ public void run() { if (zoomingIn && onScreen && SHOULD_ANIMATE) { Point point = mSphericalMercatorProjection.toPoint(c.getPosition()); Point closest = findClosestCluster(existingClustersOnScreen, point); - if (closest != null) { + if (closest != null && mAnimate) { LatLng animateTo = mSphericalMercatorProjection.toLatLng(closest); markerModifier.add(true, new CreateMarkerTask(c, newMarkers, animateTo)); } else { @@ -431,10 +433,13 @@ public void run() { boolean onScreen = visibleBounds.contains(marker.position); // Don't animate when zooming out more than 3 zoom levels. // TODO: drop animation based on speed of device & number of markers to animate. + // TODO + // TODO + // TODO if (!zoomingIn && zoomDelta > -3 && onScreen && SHOULD_ANIMATE) { final Point point = mSphericalMercatorProjection.toPoint(marker.position); final Point closest = findClosestCluster(newClustersOnScreen, point); - if (closest != null) { + if (closest != null && mAnimate) { LatLng animateTo = mSphericalMercatorProjection.toLatLng(closest); markerModifier.animateThenRemove(marker, marker.position, animateTo); } else { @@ -480,6 +485,11 @@ public void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItem mItemInfoWindowClickListener = listener; } + @Override + public void setAnimation(boolean animate) { + mAnimate = animate; + } + private static double distanceSquared(Point a, Point b) { return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y); } From 023e23f92bf08d10432426db00631803017ed28d Mon Sep 17 00:00:00 2001 From: Elizabeth Stevenson Date: Tue, 6 Dec 2016 11:05:08 +1100 Subject: [PATCH 2/2] Removed unnecessary comments. --- .../maps/android/clustering/view/DefaultClusterRenderer.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java b/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java index ff6b35cfb..5e3e1b25f 100644 --- a/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java +++ b/library/src/com/google/maps/android/clustering/view/DefaultClusterRenderer.java @@ -433,9 +433,6 @@ public void run() { boolean onScreen = visibleBounds.contains(marker.position); // Don't animate when zooming out more than 3 zoom levels. // TODO: drop animation based on speed of device & number of markers to animate. - // TODO - // TODO - // TODO if (!zoomingIn && zoomDelta > -3 && onScreen && SHOULD_ANIMATE) { final Point point = mSphericalMercatorProjection.toPoint(marker.position); final Point closest = findClosestCluster(newClustersOnScreen, point);