我正在使用MapBox 8.4.0,我使用以下代码片段将地图加载到一个片段上,使用一个标记来固定用户的当前位置。我需要通过使用从网络URL加载的图像动态设置foregroundDrawable来自定义标记。但是foregroundDrawable只接受资源ID作为参数。
val customOptions = LocationComponentOptions.builder(context!!)
.elevation(5f)
.foregroundDrawable(R.drawable.icon_profile) // set image dynamically
.backgroundDrawable(R.drawable.icon_current_location)
.build()
val activationOptions = LocationComponentActivationOptions.builder(context!!, style)
.locationComponentOptions(customOptions)
.build()
mapboxMap.locationComponent.apply {
activateLocationComponent(activationOptions)
isLocationComponentEnabled = true
cameraMode = CameraMode.TRACKING
renderMode = RenderMode.NORMAL
}在运行时将profile icon替换为加载的图像后,它应该如下所示。
https://i.stack.imgur.com/eoXuG.jpg
我有办法做到这一点吗?
发布于 2020-01-30 22:58:11
我们可以使用foregroundName()为我们的标记设置动态图标。
mapboxMap.getStyle { loadedStyle ->
loadedStyle.addImage("marker-icon", bitmapIcon) // create a Bitmap icon; you may use Glide to load image from URL
val locationComponentOptions: LocationComponentOptions =
LocationComponentOptions.builder(context!!)
.foregroundName("marker-icon") // set icon for the marker
.build()
val activationOptions =
LocationComponentActivationOptions.builder(context!!, loadedStyle)
.locationComponentOptions(locationComponentOptions)
.build()
mapboxMap.locationComponent.apply {
activateLocationComponent(activationOptions)
...
}
}发布于 2020-02-06 08:35:42
如果您使用的是毕加索而不是Glide,https://stackoverflow.com/a/20181629/6358488将展示如何使用毕加索设置一个目标,以便从网络URL调用中获取Bitmap。
https://stackoverflow.com/questions/59828022
复制相似问题