Android maps utils cluster icon color

前端 未结 6 1645
谎友^
谎友^ 2020-12-13 07:23

Is there any method to change the background color of the cluster item? (the one that displays the count of the markers, like 100+, 200+ ...). I tried to look into the sourc

6条回答
  •  无人及你
    2020-12-13 07:35

    Sadly, overriding getColor doesn't work for me. But this looks enough to change the marker color (and something else):

    class ClusterItemRenderer(
        context: Context, map: GoogleMap,
        clusterManager: ClusterManager
    ) : DefaultClusterRenderer(context, map, clusterManager) {
    
        override fun onBeforeClusterItemRendered(item: ClusterMarker, markerOptions: MarkerOptions) {
            val markerDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)
            markerOptions.icon(markerDescriptor)
        }
    }
    

    It's also possible to add updates according to the recommendations:

    If you're using custom clustering (i.e, if you're extending DefaultClusterRenderer), you must override two additional methods in v1:

    • onClusterItemUpdated() - should be the same* as your onBeforeClusterItemRendered() method
    • onClusterUpdated() - should be the same* as your onBeforeClusterRendered() method

    *Note that these methods can't be identical, as you need to use a Marker instead of MarkerOptions

    override fun onClusterItemUpdated(item: ClusterMarker, marker: Marker) {
        val markerDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_MAGENTA)
        marker.setIcon(markerDescriptor)
    }
    

提交回复
热议问题