Skip to content

Odd cluster behavior during clustering #1316

@danijel-vrecic

Description

@danijel-vrecic

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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage meI really want to be triaged.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions