MapBox 中的 Source、Layer 和 Tileset 有什么区别?

What is the difference between Source, Layer and Tileset in MapBox?

我目前正在研究一段使用 MapBox GL JS 的代码,它有一个 addSource() 函数,看起来像这样

this.mapAdapter.map.addSource(`${this.asset.uuid}-data`, {
        type: 'geojson',
        data: this.getMapboxGeometry(),
      })

还有另一个 addLayer() 函数,看起来像这样

this.mapAdapter.map.addLayer({
        id: `${this.asset.uuid}-polygon`,
        type: 'fill',
        source: `${this.asset.uuid}-data`,
        filter: ['==', '$type', 'Polygon'],
        }

我想知道source和layer的区别。我似乎找不到合适的明确定义。

特征采集代码如下

 type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {},
      geometry: {
        type: 'Polygon',
      ...}

图层是否以某种方式与要素集合相关?

图块集是源的另一个名称还是完全不同?

源和图层在 Mapbox-GL 样式规范中定义:https://docs.mapbox.com/mapbox-gl-js/style-spec/

简而言之:源定义数据的来源,图层定义源的显示方式。

Are layers related to the feature collection in some way?

不是真的。

Are tilesets another name for sources or are they entirely different?

矢量瓦片集是一种来源。 GeoJSON 来源(就像你在这里使用的一样)是另一个。

I want to know what the difference between source and layer is. I can't seem to find a proper clear definition fo it.

当我开始学习 Mapbox 时,在尝试理解源、图层、数据集、tilesets、样式等之间的差异时,我有过非常相似的挣扎。 Mapbox 提供了多少内容以及他们拥有多少文档,这真是太棒了,但是很容易在噪音中迷失方向。

我认为 sources 是我地图的迷你数据存储,layers 是源的可视化表示。添加源会告诉 Mapbox “嘿,这是一个包含或更多图层的数据存储,可以添加到地图中”。当您向地图添加图层时,您将其指向源并告诉 Mapbox 如何在地图上表示源。

将源添加到地图后,您可以使用它创建任意数量的图层。例如,如果我添加了一个包含城市公园的来源,我可以从该单一来源创建以下三个图层。

  • 一个 fill 图层,将公园边界表示为阴影多边形
  • line 层,将边界表示为轮廓
  • 一个 symbol 图层,将公园名称显示为文本标签

我写了一个 Mapbox 和 React Deep Dives 系列,更深入地介绍了这一点。这里有一些与您的问题非常相关的帖子。