我在应用程序中集成了集群。在onBeforeClusterItemRendered方法中为单个项目添加自定义图像会导致应用程序停滞一段时间。问题仅在Android 8设备中存在。
override fun onBeforeClusterItemRendered(item: MarkerItem?, markerOptions: MarkerOptions?) {
val iconType = getMarkerIcon(item!!.mapObjectType, item!!.markerType)
setMarkerIcon(mapObjectSelection, item.mapObjectType, markerOptions, iconType, 0, false)
}
private fun setMarkerIcon(currentTableSelection: Int, mapObjectType: Int, markerOptions: MarkerOptions?, iconType: Int, markerCount: Int, isClusterIcon: Boolean) {
if (isClusterIcon) {
val icon = mMapIconGenerator.makeIcon(iconType, tempMarkerCount)
markerOptions?.icon(BitmapDescriptorFactory.fromBitmap(icon))
} else {
var bitmap = mapIcons[iconType]
if(null == bitmap){
bitmap = BitmapFactory.decodeResource(mContext.resources,iconType)
mapIcons[iconType] = bitmap
}
}
自定义图像大小非常大,这导致了集群停滞。通过缩小地图图标图像的大小来解决