首页 > 解决方案 > 在 google map api 上更改 Android Cluster 的吸引力

问题描述

我们可以改变一个集群的吸引力,从而吸引更多的标记吗?

我的代码:(我在地图片段中使用的一个简单的类扩展)

class MyClusterManagerRenderer(
   context : Context,
   map : GoogleMap,
   mClusterManager: ClusterManager<ClusterItem>
) : DefaultClusterRenderer<ClusterItem>(context, map, mClusterManager) {

   private val mContext = context

   override fun onBeforeClusterItemRendered(item: ClusterItem?, markerOptions: MarkerOptions?) {
      super.onBeforeClusterItemRendered(item, markerOptions)

      val iconFactory = IconGenerator(mContext)
      iconFactory.setColor(ContextCompat.getColor(mContext, R.color.color))
      iconFactory.setTextAppearance(R.style.googleMarkerText)

      markerOptions
         ?.icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(item!!.title)))
         ?.anchor(iconFactory.anchorU, iconFactory.anchorV)
   }

   override fun getColor(clusterSize: Int): Int { return ContextCompat.getColor(mContext, R.color.color) }

   override fun getMinClusterSize(): Int { return 3 }
}

标签: androidkotlin

解决方案


推荐阅读