将地图盒中的图块集添加到我的地图中

Fab*_*ala 5 html web-applications mapbox mapbox-gl mapbox-gl-js

我是 Mapbox 的新手,最近我想创建一个网络地图。我将一个形状上传到 mapbox tilseset cloud 中,但是当我尝试将其添加到地图中时,它不显示。这是我正在使用的代码函数:

        map.on('load', function() {
        map.addLayer({
            'id' : 'Resguardos',
            'type' : 'fill',
            "source" : {
                'type' : 'vector',
                'url' : 'mapbox://fabiofz1990.9lhgml6c',
            },
            'layout' : {},
            'paint' : {
                'fill-color' : '#0044b2',
                'fill-opacity' : 1
            }
        });

    });
Run Code Online (Sandbox Code Playgroud)

谢谢

Muh*_*que 7

您可以直接从 Mapbox studio 添加图块集。

  1. 复制图块集 URL。项目清单
  2. 像这样添加网址。url: "mapbox://+tilesetid"
map.addSource('tileset_data', {
    "url": "mapbox://abcqqq123.cklxcyxew1b9421lpb8shxf4x-2ikvs",
    "type": "vector"
});
Run Code Online (Sandbox Code Playgroud)
  1. 在图层中添加上面源名称“tileset_data”中的源名称,并从上面的图片中获取源图层。
       map.addLayer({
           'id': 'circles',
           'type': 'circle',
           'source': 'tileset_data',
           'source-layer': 'children_obesity',
           'paint': {
               'circle-color': '#7F3121',
               'circle-opacity': 0.75,
               'circle-radius': 5
           }
       });
Run Code Online (Sandbox Code Playgroud)

那么你就可以出发了。


And*_*-lo 2

我认为要显示它,您需要将图块集数据添加到您正在使用的样式中。

您的 Mapbox 帐户中有一个选项:https ://www.mapbox.com/studio/tilesets/

在此输入图像描述