0

Mapbox JS 在这里有一个广泛的示例库,但缺少的是有关如何从 Mapbox Studio 加载矢量切片的文档。

在升级后的 Mapbox GL JS 中,这在文档中有明确的解释。

map.addLayer({
    "id": "terrain-data",
    "type": "line",
    "source": {
        type: 'vector',
        url: 'mapbox://mapbox.mapbox-terrain-v2'
    },
    "source-layer": "contour",
    "layout": {
        "line-join": "round",
        "line-cap": "round"
    },
    "paint": {
        "line-color": "#ff69b4",
        "line-width": 1
    }
});

其中 url 包含mapidsource-layer是图层的名称。所以如果mapid= abcd1234,我的用户名是testUser,我的矢量图层名称是testLayer我会写:

"source": {
    type: 'vector',
    url: 'mapbox://testUser.abcd1234'
},
"source-layer": "testLayer",

这在 Mapbox GL JS 中完美运行,但是在 Mapbox JS 中从 Mapbox Studio 加载 mapbox 矢量切片的等效示例是什么?

4

1 回答 1

1

假设 Mapbox JS 基于 Leaflet 1+,那么您可以使用http://leaflet.github.io/Leaflet.VectorGrid/vectorgrid-api-docs.html。其实我发现这个插件 + Leaflet/Mapbox JS 比 gl js 有一定的优势。

于 2017-06-02T03:58:26.410 回答