[英]Is DefaultClusterRenderer in android-maps-utils broken in v1.2.1?
當試圖覆蓋 DefaultClusterRenderer 中的任何函數時,它不會在 v1.2.1 中編譯。 v1.1.0 中一切正常
在這里,我想將 colors 設置為 clustericons,並覆蓋DefaultClusterRenderer
onBeforeClusterItemRendered
以根據值設置 colors。
以下代碼在 v1.2.1 中失敗,在 v1.1.0 中完全沒問題
package no.rogo.emptyfuel.utilities.cluster
import android.content.Context
import android.graphics.Color
import android.util.Log
import com.bumptech.glide.load.resource.bitmap.BitmapDrawableEncoder
import com.google.android.gms.maps.GoogleMap
import com.google.android.gms.maps.model.BitmapDescriptorFactory
import com.google.android.gms.maps.model.Marker
import com.google.android.gms.maps.model.MarkerOptions
import com.google.maps.android.clustering.Cluster
import com.google.maps.android.clustering.ClusterManager
import com.google.maps.android.clustering.view.DefaultClusterRenderer
import com.google.maps.android.ui.IconGenerator
import no.rogo.emptyfuel.R
import no.rogo.emptyfuel.utilities.StatusLevel
/**
* Created by Roar on 05.04.2020.
* Copyright RoGo Software / Gronmo IT
*/
class CustomClusterRenderer(
context: Context,
map: GoogleMap,
clusterManager: ClusterManager<ClusterStation?>?
) : DefaultClusterRenderer<ClusterStation?>(context,map,clusterManager)
{
private val TAG by lazy { this::class.java.simpleName }
private val clusterIconGenerator = IconGenerator(context.applicationContext)
override fun onBeforeClusterItemRendered(
item: ClusterStation?,
markerOptions: MarkerOptions?
) {
var markerHue = when(item?.statusLevel)
{
StatusLevel.SINCE_NEW -> BitmapDescriptorFactory.HUE_GREEN
StatusLevel.SINCE_FAIR -> BitmapDescriptorFactory.HUE_YELLOW
StatusLevel.SINCE_OLD -> BitmapDescriptorFactory.HUE_RED
StatusLevel.SINCE_OLDER -> BitmapDescriptorFactory.HUE_BLUE
StatusLevel.NOT_SET -> BitmapDescriptorFactory.HUE_CYAN
StatusLevel.NOT_AVAILABLE -> BitmapDescriptorFactory.HUE_AZURE
StatusLevel.HIDDEN -> BitmapDescriptorFactory.HUE_ROSE
StatusLevel.UNCERTAIN -> BitmapDescriptorFactory.HUE_ORANGE
StatusLevel.UNKNOWN -> BitmapDescriptorFactory.HUE_MAGENTA
else -> BitmapDescriptorFactory.HUE_VIOLET
}
//Color.colorToHSV(markerColor,markerHue)
//Log.i(TAG,"map3: markerHue = ${markerHue[0]}")
val markerDescriptor = BitmapDescriptorFactory.defaultMarker(markerHue)
markerOptions?.icon(markerDescriptor)
super.onBeforeClusterItemRendered(item, markerOptions)
}
override fun onClusterItemRendered(clusterItem: ClusterStation?, marker: Marker?) {
super.onClusterItemRendered(clusterItem, marker)
}
override fun onBeforeClusterRendered(
cluster: Cluster<ClusterStation?>?,
markerOptions: MarkerOptions?
) {
super.onBeforeClusterRendered(cluster, markerOptions)
}
}
有誰知道發生了什么變化,以及如何解決?
RG
我找到了問題的解決方案,在這個拉( https://github.com/googlemaps/android-maps-utils/pull/687 )中,他們將參數更改為 nullsafe,所以在更改時:
override fun onBeforeClusterItemRendered(
item: ClusterStation?,
markerOptions: MarkerOptions?
)
至
override fun onBeforeClusterItemRendered(
item: ClusterStation,
markerOptions: MarkerOptions
)
解決它。 它實際上是一個 kotlin 問題......
RG
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.