Anton A.
Anton A.

Reputation: 1748

Android Google Map Cluster icon ignores custom icon

Android Google Map Cluster icon ignores custom icon on zoom out. Any suggestion how to fix it?

override fun onBeforeClusterRendered(cluster: Cluster<T>, markerOptions: MarkerOptions) {
    mClusterIconGenerator.setBackground(context?.let { ContextCompat.getDrawable(it, R.drawable.map_cluster_item) })
    mClusterIconGenerator.setTextAppearance(R.style.WhiteTextAppearance)
    val icon = mClusterIconGenerator.makeIcon(cluster.size.toString())
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}

enter image description here enter image description here

Upvotes: 3

Views: 397

Answers (1)

Anton A.
Anton A.

Reputation: 1748

Fixed with override of getDescriptorForCluster

private val mClusterIconGenerator = IconGenerator(context).apply {
    setBackground(context?.let { ContextCompat.getDrawable(it, R.drawable.map_cluster_item) })
    setTextAppearance(R.style.WhiteTextAppearance)
}
override fun onBeforeClusterRendered(cluster: Cluster<T>, markerOptions: MarkerOptions) {
    val icon = mClusterIconGenerator.makeIcon(cluster.size.toString())
    markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
}
override fun getDescriptorForCluster(cluster: Cluster<T>): BitmapDescriptor {
    val icon = mClusterIconGenerator.makeIcon(cluster.size.toString())
    return BitmapDescriptorFactory.fromBitmap(icon)
}

Upvotes: 7

Related Questions