简体   繁体   English

如何在运行时在mapbox中添加带有不同图像的标记?

[英]How to add marker with different images in mapbox at runtime?

I have a problem, I want to add different images on a marker at runtime. 我有一个问题,我想在运行时在标记上添加不同的图像。

I can basically add images in style and then I have to load the map to add a marker with a different image. 我基本上可以添加风格的图像,然后我必须加载地图以添加具有不同图像的标记。

This is how I add images in mapbox right now 这就是我现在在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 should be able to show images or render it at runtime on a different marker. Mapbox应该能够在不同的标记上显示图像或在运行时呈现它。

For example, snap chat using it right now. 例如,立即使用它进行快照聊天

If you want to use the older Marker API, you can simply add markers via mapView.addMarkers() . 如果您想使用旧的Marker API,只需通过mapView.addMarkers()添加标记mapView.addMarkers() You can customize them at runtime with MarkerOptions() or MarkerViewOptions() . 您可以使用MarkerOptions()MarkerViewOptions()在运行时自定义它们。 More on markers here . 更多关于标记的信息

On the other hand you could use a SymbolLayer to provide your custom markers, allowing more customization and custom logic for styling (and performance). 另一方面,您可以使用SymbolLayer提供自定义标记,从而为样式(和性能)提供更多自定义和自定义逻辑。 I recommend reading this . 我建议读这个

A third option would be using the new Annotation Plugin, that is mostly similar to using Layers directly, but with more convenience and less need to write boilerplate code. 第三种选择是使用新的Annotation插件,这与使用Layers直接相似,但更方便,更少需要编写样板代码。 Some examples here and in the Github repo . 这里Github回购中的一些例子。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM