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<String, Source> sources = new HashMap<>(); private final HashMap<String, Layer> layers = new HashMap<>(); private final HashMap<String, Bitmap> 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<Layer> 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,进行修改 。

MapBox地图怎么去掉地名显示,这个需求我之前也没遇到过,于是今天就尝试了一番,总结一下。一. 首先尝试查找com.mapbox.mapboxsdk.maps.UiSettings源码查看后发现根本没有地图文学显示相关设置,全部都是地图的操作设置,例如旋转手势等。第一步失败!二. 分析地图是如果显示地名的。Mapbox现在都是用Layer添加覆盖物,所以判断地名也是通过L...
大约就是实现这样一个效果,图标数据为后端提供切片数据 首先我们需要了解到每个数据里有什么字段: Amap.mapbox.on("click", "livestock-layer", (e) => { console.log('66666666',e.features[0].properties) (正常直接获取map进行on即可,本代码处理可同时进行mapbox和l7) 打印里面发现存在name: 在addlayer中添加: layout: {
通过官网的介绍,天地图默认是加载矢量图的,那么当我我们默认使用影像底图的时候只有影像底图,没有地名注记,开发文档没有明确说明如何添加,经过个人理解,可以通过下面的方法添加注记。 根据地图API定义图层服务地址url // 影像底图url const imageURL = "http://t0.tianditu.gov.cn/img_w/wmts?" + "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER.
Mapbox样式文件里使用glyphs来指定使用的字体文件,不能直接使用ttf格式字体文件,需转换为符合Mapbox要求的pbf格式的文件,有两种开源工具可以实现。 一、node-fontnik build后可直接使用bin目录下的build-glyphs来生成。 二、genfontgl(依赖...
由于我的项目突然出现了白屏的问题,定位bug到设置样式的函数,一旦设置样式就会报跨域请求阻塞的问题,花了一个中午的时间给解决了,百度真坑.. 目前想要设置百度地图的样式需要作出以下调整 需要将原有的2.0版本修改为3.0版本 需要调用3.0版本设置样式的函数setMapStyleV2(),其他参数不变 需要将所有的设置函数放在样式设置位置以上,否则会报父节点找不到...
map1 = new mapboxgl.Map({ container: "map1", style: "mapbox://styles/mapbox/streets-v11", zoom: 12,