Mapbox使用矢量源添加图层

时间:2018-04-10 13:51:37

标签: mapbox mapbox-gl-js

我在mapbox工作室上传了一个矢量源(tileset)。我正在添加这个tileset的源代码,如:

map.addSource("abc", {
            type: "vector",
            url: "mapbox://RELEVANT_MAP_ID"
        });

然后我试图添加一个像:

的图层
map.addLayer({
    "id": "layer_id",
    "type": "line",
    "source": "abc",
    "source-layer": "source_layer_id",
    "layout": {
        "line-join": "round",
        "line-cap": "round"
    },
    "paint": {
        "line-color": "#ff69b4",
        "line-width": 4
    }
});

执行此代码时出现错误:

Error: Source layer "source_layer_id" does not exist on source "abc" as specified by style layer "terrain-data"

source_layer到底是为了什么?在矢量切片的情况下,如何在源上提及源图层?有没有办法在创建图块集时提及源图层?

1 个答案:

答案 0 :(得分:1)

如果您在Mapbox Studio中打开了tileset(由RELEVANT_MAP_ID引用的那个),您将会看到类似这样的内容

enter image description here

source-layer是您要为其创建样式图层的Tileset源中的哪个图层,因此从屏幕截图中可以是adminaerowayairport_label,等