【问题标题】:Adding a Tileset from mapbox into my map将 mapbox 中的 Tileset 添加到我的地图中
【发布时间】:2017-06-28 14:55:33
【问题描述】:

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

        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
            }
        });

    });

谢谢

【问题讨论】:

  • 你有没有给这个加过api键

标签: html web-applications mapbox mapbox-gl-js mapbox-gl


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    您可以直接从 Mapbox 工作室添加图块集。

    1. 复制tileset URL。
    2. 像这样添加 URL。网址:“mapbox://+tilesetid”
    map.addSource('tileset_data', {
        "url": "mapbox://abcqqq123.cklxcyxew1b9421lpb8shxf4x-2ikvs",
        "type": "vector"
    });
    
    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
               }
           });
    

    那你可以走了。

    【讨论】:

      【解决方案3】:

      您不能直接将 mapbox TileSet 添加到浏览器客户端中。

      您必须创建一个使用您的 tileSet 的新地图框样式。

      这是工作示例

      https://transparentgov.net/cleargov1/766/new-2019-world-press-freedom-ranking-map-180-countries

      https://transparentgov.net/json2tree/datahub.io/international/press-freedom-2019-mapbox-style.html

      【讨论】:

      • 有没有办法以编程方式做到这一点?如果您有数百个图块并希望您的应用根据用户输入选择要显示的图块怎么办?
      猜你喜欢
      • 2023-02-14
      • 2022-12-04
      • 1970-01-01
      • 2019-03-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      相关资源
      最近更新 更多