googlemaps / android-maps-utils

Maps SDK for Android Utility Library
https://developers.google.com/maps/documentation/android-sdk/utility
Apache License 2.0
3.55k stars 1.53k forks source link

Odd cluster behavior during clustering #1316

Open danijel-vrecic opened 7 months ago

danijel-vrecic commented 7 months ago

Summary

Weird cluster behaviour when clusters change with an animation on zooming. The cluster icon refreshes, resulting in a flickering shadow, even though the cluster position has not changed. The shadow flicker is caused by a new cluster appearing on top of the existing one during the animation.

Expected behavior

I would expect the cluster to not animate if there is no position change. This would prevent a shadow flickering.

Observed behavior

When clusters are (re-)clustered, this also affects a cluster that has remained in the same position, causing the shadow to blink.

Screen_recording_20240312_133131ss.webm

Environment details

kotlin = "1.9.0" mapUtils = "5.0.0" playServicesMaps = "18.2.0"

Code example

Custom renderer with no additional modifications.

class CustomClusterRenderer(
    private val context: Context,
    map: GoogleMap,
    clusterManager: ClusterManager<MyItem>
) : DefaultClusterRenderer<MyItem>(context, map, clusterManager) {

    private val markerSize = context.resources.getDimensionPixelSize(R.dimen.marker_size)

    override fun onBeforeClusterItemRendered(item: MyItem, markerOptions: MarkerOptions) {
        markerOptions
            .icon(getIcon())
    }

    override fun onClusterItemRendered(clusterItem: MyItem, marker: Marker) {
        marker.run {
            setIcon(getIcon())
        }
    }

    override fun onBeforeClusterRendered(cluster: Cluster<MyItem>, markerOptions: MarkerOptions) {
        markerOptions.icon(getIcon())
    }

    override fun onClusterUpdated(cluster: Cluster<MyItem>, marker: Marker) {
        marker.setIcon(getIcon())
    }

    override fun shouldRenderAsCluster(cluster: Cluster<MyItem?>): Boolean {
        return cluster.size > 1
    }

    private fun getIcon(): BitmapDescriptor {
        val bitmap = BitmapFactory.decodeResource(context.resources, R.drawable.marker1)
            .scale(markerSize, markerSize, false)
        return BitmapDescriptorFactory.fromBitmap(bitmap);
    }
}
wangela commented 7 months ago

If you would like to upvote the priority of this issue, please comment below or react on the original post above with :+1: so we can see what is popular when we triage.

@danijel-vrecic Thank you for opening this issue. 🙏 Please check out these other resources that might help you get to a resolution in the meantime:

This is an automated message, feel free to ignore.