Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable animations #334

Merged
merged 2 commits into from
Dec 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public void setAlgorithm(Algorithm<T> algorithm) {
cluster();
}

public void setAnimation(boolean animate) {
mRenderer.setAnimation(animate);
}

public ClusterRenderer<T> getRenderer() {
return mRenderer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public interface ClusterRenderer<T extends ClusterItem> {

void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItemInfoWindowClickListener<T> listener);

/**
* Called to set animation on or off
*/
void setAnimation(boolean animate);

/**
* Called when the view is added.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen
private final IconGenerator mIconGenerator;
private final ClusterManager<T> mClusterManager;
private final float mDensity;
private boolean mAnimate;

private static final int[] BUCKETS = {10, 20, 50, 100, 200, 500, 1000};
private ShapeDrawable mColoredCircleBackground;
Expand Down Expand Up @@ -129,6 +130,7 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen

public DefaultClusterRenderer(Context context, GoogleMap map, ClusterManager<T> clusterManager) {
mMap = map;
mAnimate = true;
mDensity = context.getResources().getDisplayMetrics().density;
mIconGenerator = new IconGenerator(context);
mIconGenerator.setContentView(makeSquareTextView(context));
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
Expand Down