【问题标题】:Mapbox - How can I add a .pbf file as a Layer in Mapbox?Mapbox - 如何在 Mapbox 中添加 .pbf 文件作为图层?
【发布时间】:2020-03-08 01:45:39
【问题描述】:

我想在 Mapbox 中的地图上添加一个切片图层。 这些图块使用 php tileserver 在本地托管。

我之前的尝试是这样的:

map.addLayer({
            'id': 'tiles',
            'type': 'fill',
            'Source': {
                'type': 'vector',
                'tiles': ['http://localhost/tileserver-php-master/{z}/{x}/{y}.pbf'],
            },
            'paint': {
                'fill-color': 'rgb(53, 175, 109)',
                'fill-outline-color': 'rgb(53, 175, 109)'
            }
        });

图块是应放置在地图上的单个多边形。 地图可见,但个别图块不可见。

不能选择像 geojson 这样的层,因为文件太大了。

【问题讨论】:

  • 你必须指定一个“源层”。
  • 如果我这样做:map.addSource('tile', { type: 'vector', tiles: ['localhost/tileserver-php-master{z}/{x}/{y}.pbf '],缓冲区:0,最大缩放:12 }); map.addLayer(…. 仍然出现错误:layers.tiles: layer "tiles" must specify a "source-layer"
  • 您必须为矢量图层指定一个“源层”。检查一下:docs.mapbox.com/mapbox-gl-js/style-spec/#layer-source-layer 通常对于 tileserver-php,图层名称与您服务的文件相同。
  • 你能发布一个完整的例子吗?

标签: mapbox tiles openmaptiles


【解决方案1】:

@Henhuy 您可以将您的磁贴托管为 .mbtiles:https://github.com/maptiler/tileserver-php。您还将在此处看到源图层的名称。

map.addLayer({
        'id': 'uniqID',
        'type': 'fill',
        'source': {
            'type': 'vector',
            'tiles': ["LINK_TO_TILESEVER.pdf"],
        },
        'source-layer': "SOURCE_LAYER_ID",
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-08-24
    • 1970-01-01
    • 2019-08-27
    • 2020-09-01
    • 1970-01-01
    • 2016-08-14
    • 2018-11-25
    相关资源
    最近更新 更多