在MapBox上添加标记的最佳方法是什么?

编程入门 行业动态 更新时间:2024-10-28 16:24:56
本文介绍了在MapBox上添加标记的最佳方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

众所周知, mapbox.addMarker()已弃用!我试图找出使用符号层

As most of you know, mapbox.addMarker() is deprecated! I tried to figure the new way to add markers which are using Symbol Layer

我正在使用此代码,它正在为我工​​作!但是每次我要添加标记时,它都会重新定义地图的样式

I'm using this code, it is working for me! but it re-define the Style of the map every time I want to add a marker

下面是代码:

//Add Marker to the Map public void addMarker(@NonNull LatLng point) { Feature feature = Feature.fromGeometry(Point.fromLngLat(point.getLongitude(), point.getLatitude())); mapboxMap .setStyle(new Style.Builder() .fromUri("mapbox://styles/mapbox/cjf4m44iw0uza2spb3q0a7s41") .withImage(ICON_ID, marker) .withSource(new GeoJsonSource(SOURCE_ID, feature)) .withLayer(new SymbolLayer(LAYER_ID, SOURCE_ID) .withProperties(PropertyFactory.iconImage(ICON_ID), iconAllowOverlap(true), iconIgnorePlacement(true), iconOffset(new Float[]{0f, -9f})))); }

因此,我想知道在最新的MapBox SDK 8.5.0

谢谢!

推荐答案

mapboxMap.setStyle(Style.MAPBOX_STREETS, new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull final Style style) { AddSanciangkoStreet(style); SanciangkoStreetMarker(); } } private void AddSanciangkoStreet(@NonNull Style style) { style.addImage("sanciangko-street", BitmapUtils.getBitmapFromDrawable(getResources().getDrawable(R.drawable.floodicon))); style.addSource(new GeoJsonSource("sanciangkoFlood1-source-id")); style.addLayer(new SymbolLayer("sanciangkoFlood1-layer-id", "sanciangkoFlood1-source-id").withProperties( iconImage("sanciangko-street"), iconIgnorePlacement(true), iconAllowOverlap(true), iconSize(1f) )); } private void SanciangkoStreetMarker() { if (map.getStyle() != null) { GeoJsonSource sanciangkoFlood1 = map.getStyle().getSourceAs("sanciangkoFlood1-source-id"); if (sanciangkoFlood1 != null) { sanciangkoFlood1.setGeoJson(FeatureCollection.fromFeature( Feature.fromGeometry(Point.fromLngLat(123.895801, 10.297237)) )); } } }

更多推荐

在MapBox上添加标记的最佳方法是什么?

本文发布于:2023-11-24 09:30:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624662.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   方法   MapBox

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!