diff --git a/demo/src/main/res/layout/multi_profile.xml b/demo/src/main/res/layout/multi_profile.xml
index bbd407769..0cec5a36e 100644
--- a/demo/src/main/res/layout/multi_profile.xml
+++ b/demo/src/main/res/layout/multi_profile.xml
@@ -22,7 +22,7 @@
new LinearInterpolator();
case EASE_IN, ACCELERATE -> new AccelerateInterpolator();
@@ -173,7 +175,7 @@ public void setAnimationInterpolator(TimeInterpolator interpolator) {
public ClusterRendererMultipleItems(Context context, GoogleMap map, ClusterManager clusterManager) {
mMap = map;
mAnimate = true;
- mAnimationDurationMs = 300;
+ mAnimationDurationMs = 5000;
mDensity = context.getResources().getDisplayMetrics().density;
mIconGenerator = new IconGenerator(context);
mIconGenerator.setContentView(makeSquareTextView(context));
@@ -434,6 +436,8 @@ private class RenderTask implements Runnable {
private SphericalMercatorProjection mSphericalMercatorProjection;
private float mMapZoom;
+ private static final double EPSILON = 1e-9;
+
private RenderTask(Set extends Cluster> clusters) {
this.clusters = clusters;
}
@@ -451,6 +455,10 @@ public void setMapZoom(float zoom) {
this.mSphericalMercatorProjection = new SphericalMercatorProjection(256 * Math.pow(2, Math.min(zoom, mZoom)));
}
+ private boolean areClose(double a, double b) {
+ return Math.abs(a - b) < EPSILON;
+ }
+
@SuppressLint("NewApi")
@Override
public void run() {
@@ -530,9 +538,16 @@ public void run() {
final Point closest = findClosestCluster(newClustersOnScreen, point);
if (closest != null) {
LatLng animateTo = mSphericalMercatorProjection.toLatLng(closest);
- markerModifier.animateThenRemove(marker, marker.position, animateTo);
- RendererLogger.d("ClusterRenderer", "Animating then removing marker at position: " + marker.position);
- } else if (mClusterMarkerCache.mCache.keySet().iterator().hasNext() && mClusterMarkerCache.mCache.keySet().iterator().next().getItems().contains(marker.clusterItem)) {
+ if (areClose(marker.position.latitude, animateTo.latitude) && areClose(marker.position.longitude, animateTo.longitude)) {
+ // Treat them as the same, no need for animation
+ markerModifier.remove(true, marker.marker);
+ RendererLogger.d("ClusterRenderer", "Removing marker without animation (coordinates are very close)");
+ } else {
+ // If they are not close, proceed with the original logic
+ markerModifier.animateThenRemove(marker, marker.position, animateTo);
+ }
+ }
+ else if (mClusterMarkerCache.mCache.keySet().iterator().hasNext() && mClusterMarkerCache.mCache.keySet().iterator().next().getItems().contains(marker.clusterItem)) {
T foundItem = null;
for (Cluster cluster : mClusterMarkerCache.mCache.keySet()) {
for (T clusterItem : cluster.getItems()) {
@@ -1153,7 +1168,7 @@ private void perform(MarkerModifier markerModifier) {
if (animateFrom != null) {
markerModifier.animate(markerWithPosition, animateFrom, item.getPosition());
RendererLogger.d("ClusterRenderer", "Animating marker from " + animateFrom + " to " + item.getPosition());
- } else if (currentLocation != null) {
+ } else {
markerModifier.animate(markerWithPosition, currentLocation, item.getPosition());
RendererLogger.d("ClusterRenderer", "Animating marker from " + currentLocation + " to " + item.getPosition());
}