当前位置: 代码迷 >> 综合 >> MapBox-Android的layer重置位置问题
  详细解决方案

MapBox-Android的layer重置位置问题

热度:80   发布时间:2024-02-11 08:43:06.0

加载图标layer官方文档有介绍:

public void onMapReady(@NonNull final MapboxMap mapboxMap) {List<Feature> symbolLayerIconFeatureList = new ArrayList<>();symbolLayerIconFeatureList.add(Feature.fromGeometry(Point.fromLngLat(-57.225365, -33.213144)));symbolLayerIconFeatureList.add(Feature.fromGeometry(Point.fromLngLat(-54.14164, -33.981818)));symbolLayerIconFeatureList.add(Feature.fromGeometry(Point.fromLngLat(-56.990533, -30.583266)));mapboxMap.setStyle(new Style.Builder().fromUri("mapbox://styles/mapbox/cjf4m44iw0uza2spb3q0a7s41")// Add the SymbolLayer icon image to the map style.withImage(ICON_ID, BitmapFactory.decodeResource(BasicSymbolLayerActivity.this.getResources(), R.drawable.mapbox_marker_icon_default))// Adding a GeoJson source for the SymbolLayer icons..withSource(new GeoJsonSource(SOURCE_ID,FeatureCollection.fromFeatures(symbolLayerIconFeatureList)))// Adding the actual SymbolLayer to the map style. An offset is added that the bottom of the red
// marker icon gets fixed to the coordinate, rather than the middle of the icon being fixed to
// the coordinate point. This is offset is not always needed and is dependent on the image
// that you use for the SymbolLayer icon..withLayer(new SymbolLayer(LAYER_ID, SOURCE_ID).withProperties(iconImage(ICON_ID),iconAllowOverlap(true),iconIgnorePlacement(true))), new Style.OnStyleLoaded() {@Overridepublic void onStyleLoaded(@NonNull Style style) {// Map is set up and the style has loaded. Now you can add additional data or make other map adjustments.}});}

效果如下:

但是如果想要让这个layer动起来,比如实现跟踪位置的效果怎么办呢?比如在做一个室内定位的效果:

                                                   

 

主要分三步:

  1. 准备数据
  2. 移除资源(图片和layer)
  3. 获取style实例,添加新的显示坐标

代码如下:

 

 

 

 

 
  相关解决方案