Skip to content
Draft
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
2 changes: 1 addition & 1 deletion demo/src/main/res/layout/multi_profile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

<ImageView
android:id="@+id/image"
android:layout_width="@dimen/custom_profile_image"
android:layout_width="150dp"
android:layout_height="@dimen/custom_profile_image"/>

<TextView
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.R;
import com.google.maps.android.RendererLogger;
import com.google.maps.android.SphericalUtil;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterItem;
import com.google.maps.android.clustering.ClusterManager;
Expand Down Expand Up @@ -107,6 +108,7 @@ public enum AnimationType {
}

public void setAnimationType(AnimationType type) {

animationInterp = switch (type) {
case LINEAR -> new LinearInterpolator();
case EASE_IN, ACCELERATE -> new AccelerateInterpolator();
Expand Down Expand Up @@ -173,7 +175,7 @@ public void setAnimationInterpolator(TimeInterpolator interpolator) {
public ClusterRendererMultipleItems(Context context, GoogleMap map, ClusterManager<T> clusterManager) {
mMap = map;
mAnimate = true;
mAnimationDurationMs = 300;
mAnimationDurationMs = 5000;
mDensity = context.getResources().getDisplayMetrics().density;
mIconGenerator = new IconGenerator(context);
mIconGenerator.setContentView(makeSquareTextView(context));
Expand Down Expand Up @@ -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<T>> clusters) {
this.clusters = clusters;
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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<T> cluster : mClusterMarkerCache.mCache.keySet()) {
for (T clusterItem : cluster.getItems()) {
Expand Down Expand Up @@ -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());
}
Expand Down