如何在运行时在 mapbox 中添加具有不同图像的标记?
How to add marker with different images in mapbox at runtime?
我有问题,我想在运行时在标记上添加不同的图像。
我基本上可以按样式添加图像,然后我必须加载地图以添加具有不同图像的标记。
这就是我现在在 mapbox 中添加图像的方式
mapView.getMapAsync {
it.setStyle(Style.Builder().fromUrl("mapbox://styles/{user}/{mapid}")) { style ->
// Add the marker image to map
ContextCompat.getDrawable(this, R.drawable.ic_user_one_round)?.let { img ->
style.addImageAsync("key", img)
}
}
Mapbox 应该能够在运行时在不同的标记上显示或渲染图像。
例如,即时聊天正在使用它。
如果您想使用旧标记 API,您只需通过 mapView.addMarkers()
添加标记即可。您可以在运行时使用 MarkerOptions()
或 MarkerViewOptions()
自定义它们。更多关于标记 here.
另一方面,您可以使用 SymbolLayer 来提供您的自定义标记,允许更多自定义和样式(和性能)的自定义逻辑。我推荐阅读 this。
第三种选择是使用新的 Annotation Plugin,这与直接使用 Layers 非常相似,但更方便并且不需要编写样板代码。一些示例 here and in the Github repo.
我有问题,我想在运行时在标记上添加不同的图像。
我基本上可以按样式添加图像,然后我必须加载地图以添加具有不同图像的标记。
这就是我现在在 mapbox 中添加图像的方式
mapView.getMapAsync {
it.setStyle(Style.Builder().fromUrl("mapbox://styles/{user}/{mapid}")) { style ->
// Add the marker image to map
ContextCompat.getDrawable(this, R.drawable.ic_user_one_round)?.let { img ->
style.addImageAsync("key", img)
}
}
Mapbox 应该能够在运行时在不同的标记上显示或渲染图像。
例如,即时聊天正在使用它。
如果您想使用旧标记 API,您只需通过 mapView.addMarkers()
添加标记即可。您可以在运行时使用 MarkerOptions()
或 MarkerViewOptions()
自定义它们。更多关于标记 here.
另一方面,您可以使用 SymbolLayer 来提供您的自定义标记,允许更多自定义和样式(和性能)的自定义逻辑。我推荐阅读 this。
第三种选择是使用新的 Annotation Plugin,这与直接使用 Layers 非常相似,但更方便并且不需要编写样板代码。一些示例 here and in the Github repo.