首页 > 解决方案 > Android 上的 Mapbox 无法添加源异常

问题描述

当我尝试将源添加到 Android 上的 Mapbox 地图时出现异常,即使我之前删除了每个同名的源。

我试图删除源然后层或层然后源并且没有任何效果。

    if (map != null){
        String layerName = floor.getLayerName();

        map.removeLayer(layerName);
        //Remove source and layer if already selected
        map.removeSource(SOURCE); //SOURCE IS A CONST
        map.clear();

        String url = GEOSERVER_URL_NAME;
        RasterSource resource = new RasterSource(SOURCE,new TileSet("tileset",url+layerName));
        map.addSource(resource);
        RasterLayer webMapLayer = new RasterLayer(layerName,SOURCE);
        map.addLayerBelow(webMapLayer, "com.mapbox.annotations.points");
        poisViewModel.refreshPoisByName(building.getId(), floor.getId(), "");
    }

我正进入(状态:

com.mapbox.mapboxsdk.style.sources.CannotAddSourceException:源 floor_map_source 已存在。floor_map_source 是 SOURCE 的值。

标签: androidmapbox-android

解决方案


我发现了问题,实际上,我使用的 layerName 是不同的,并且阻止了源删除。在设置新图层之前,我必须添加旧图层的名称并将其删除。


推荐阅读