MapBox地图怎么去掉地名显示

您所在的位置:网站首页 百度地图怎么去掉地名路名标志 MapBox地图怎么去掉地名显示

MapBox地图怎么去掉地名显示

2024-06-14 18:35| 来源: 网络整理| 查看: 265

 MapBox地图怎么去掉地名显示,这个需求我之前也没遇到过,于是今天就尝试了一番,总结一下。

一.  首先尝试查找com.mapbox.mapboxsdk.maps.UiSettings源码

查看后发现根本没有地图文字显示相关设置,全部都是地图的操作设置,例如旋转手势等。

第一步失败!

二. 分析地图是如果显示地名的。

Mapbox现在都是用Layer添加覆盖物,所以判断地名也是通过Layer添加上去的,而添加Layer必然要用到Style。Style中通过

HashMap保存 许许多多的Layer。

1. com.mapbox.mapboxsdk.maps.Style源码 /** * The proxy object for current map style. *

* To create new instances of this object, create a new instance using a {@link Builder} and load the style with * MapboxMap. This object is returned from {@link MapboxMap#getStyle()} once the style * has been loaded by underlying map. *

*/ @SuppressWarnings("unchecked") public class Style { private final NativeMap nativeMap; private final HashMap sources = new HashMap(); private final HashMap layers = new HashMap(); private final HashMap images = new HashMap(); private final Builder builder; private boolean fullyLoaded; } 2.获取Style mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { mapboxMap.setStyle(Style.SATELLITE_STREETS, new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull Style style) { //这里就是我们需要的style } }); } }); 3.获取style包含所有Layers mapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(@NonNull MapboxMap mapboxMap) { mapboxMap.setStyle(Style.SATELLITE_STREETS, new Style.OnStyleLoaded() { @Override public void onStyleLoaded(@NonNull Style style) { //这里就是我们需要的style List layers = style.getLayers(); for (Layer lay:layers) { //设置Layer文字颜色透明 lay.setProperties( PropertyFactory.textColor(Color.TRANSPARENT) ); lay.setProperties( PropertyFactory.textHaloColor(Color.TRANSPARENT) ); //打印所有LayerId Log.d("Style==>" , "LayerId: " + lay.getId()); } } }); } });

通过上面代码就可以隐藏地图上的文字,顺便打印所有Layer的Id

Style==>LayerId: background Style==>LayerId: satellite Style==>LayerId: tunnel-primary-secondary-tertiary-case Style==>LayerId: tunnel-major-link-case Style==>LayerId: tunnel-motorway-trunk-case Style==>LayerId: tunnel-path Style==>LayerId: tunnel-steps Style==>LayerId: tunnel-major-link Style==>LayerId: tunnel-pedestrian Style==>LayerId: tunnel-primary-secondary-tertiary Style==>LayerId: tunnel-oneway-arrow-blue Style==>LayerId: tunnel-motorway-trunk Style==>LayerId: tunnel-oneway-arrow-white Style==>LayerId: ferry Style==>LayerId: ferry-auto Style==>LayerId: road-pedestrian-case Style==>LayerId: road-street-low Style==>LayerId: road-street-case Style==>LayerId: road-secondary-tertiary-case Style==>LayerId: road-primary-case Style==>LayerId: road-major-link-case Style==>LayerId: road-motorway-trunk-case Style==>LayerId: road-path Style==>LayerId: road-steps Style==>LayerId: road-major-link Style==>LayerId: road-pedestrian Style==>LayerId: road-street Style==>LayerId: road-secondary-tertiary Style==>LayerId: road-primary Style==>LayerId: road-oneway-arrow-blue Style==>LayerId: road-motorway-trunk Style==>LayerId: road-oneway-arrow-white Style==>LayerId: bridge-pedestrian-case Style==>LayerId: bridge-primary-secondary-tertiary-case Style==>LayerId: bridge-major-link-case Style==>LayerId: bridge-motorway-trunk-case Style==>LayerId: bridge-path Style==>LayerId: bridge-steps Style==>LayerId: bridge-major-link Style==>LayerId: bridge-pedestrian Style==>LayerId: bridge-primary-secondary-tertiary Style==>LayerId: bridge-oneway-arrow-blue Style==>LayerId: bridge-motorway-trunk Style==>LayerId: bridge-major-link-2-case Style==>LayerId: bridge-motorway-trunk-2-case Style==>LayerId: bridge-major-link-2 Style==>LayerId: bridge-motorway-trunk-2 Style==>LayerId: bridge-oneway-arrow-white Style==>LayerId: aerialway Style==>LayerId: admin-1-boundary-bg Style==>LayerId: admin-0-boundary-bg Style==>LayerId: admin-1-boundary Style==>LayerId: admin-0-boundary Style==>LayerId: admin-0-boundary-disputed Style==>LayerId: road-label Style==>LayerId: road-number-shield Style==>LayerId: road-exit-shield Style==>LayerId: waterway-label Style==>LayerId: natural-line-label Style==>LayerId: natural-point-label Style==>LayerId: water-line-label Style==>LayerId: water-point-label Style==>LayerId: poi-label Style==>LayerId: transit-label Style==>LayerId: airport-label Style==>LayerId: settlement-subdivision-label Style==>LayerId: settlement-label Style==>LayerId: state-label Style==>LayerId: country-label

透过名字就可以看出每个Id对应在地图上的显示,例如road开头就是道路相关的。

第二步成功!

最后可以自己通过id获取对应的Layer,进行修改 。


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3