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..5e3e1b25f 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 { @@ -434,7 +436,7 @@ public void run() { 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 +482,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); }