移动地图时自定义集群图标更改

问题描述

我以这种方式更改了认集群图标

    internal class MarkerClusterRenderer(private val context: Context?,map: GoogleMap?,clusterManager: ClusterManager<PointOfInterest>?) :
        DefaultClusterRenderer<PointOfInterest>(context,map,clusterManager) {

        private val mClusterIconGenerator = IconGenerator(context)

        override fun onBeforeClusterItemRendered(item: PointOfInterest,markerOptions: MarkerOptions) {
            markerOptions.icon(BitmapDescriptorFactory.fromresource(getMarkerResource(item)))
        }
        override fun onBeforeClusterRendered(cluster: Cluster<PointOfInterest>,markerOptions: MarkerOptions) {
            markerOptions.icon(BitmapDescriptorFactory.fromresource(R.drawable.ic_cluster))

        }

但是当我移动地图时,我设置的图标会更改为认图标。

我该如何解决

更新

我通过覆盖一个方法设法解决了这个问题。这是最后一堂课

 internal class MarkerClusterRenderer(private val context: Context?,clusterManager) {

        private val mClusterIconGenerator = IconGenerator(context)
        val clusterIcon = ResourcesCompat.getDrawable(context!!.resources,R.drawable.ic_cluster,null)!!

        override fun onBeforeClusterItemRendered(item: PointOfInterest,markerOptions: MarkerOptions) {
            markerOptions.icon(BitmapDescriptorFactory.fromresource(getMarkerResource(item)))
        }
        
        override fun onBeforeClusterRendered(cluster: Cluster<PointOfInterest>,markerOptions: MarkerOptions) {
            mClusterIconGenerator.setBackground(clusterIcon)

            if (cluster.size < 10) {
                mClusterIconGenerator.setContentPadding(40,20,0)
            } else {
                mClusterIconGenerator.setContentPadding(30,0)
            }

            val icon: Bitmap = mClusterIconGenerator.makeIcon(cluster.size.toString())
            markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon))
        }

        override fun getDescriptorForCluster(cluster: Cluster<PointOfInterest>): BitmapDescriptor {
            mClusterIconGenerator.setBackground(clusterIcon)

            if (cluster.size < 10) {
                mClusterIconGenerator.setContentPadding(40,0)
            }

            val icon: Bitmap = mClusterIconGenerator.makeIcon(cluster.size.toString())
            return BitmapDescriptorFactory.fromBitmap(icon)
        }

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)