Mapbox-GL GEOjsonSource 与数据源

Mapbox-GL GEOjsonSource vs Datasource

被 mapbox-gl-js 上的 API 搞糊涂了。

您可以通过使用 GEOjsonsource or DataSource, what is the difference ? It seems like you can only associate a style 和数据源而不是 GeoJsonsource 添加 geojson 文件?

您问题中的两个链接 ("GEOjsonsource" and "DataSource") 都描述了同一个域对象 GeoJSONSource

first link 是 Mapbox GL 样式规范,它解释了如何在样式中声明 GeoJSON 源。样式是描述地图外观的 JSON 文件。

second link 是 Mapbox GL JS API 文档,它解释了如何在 Mapbox GL JS 中使用 GeoJSONSource class。您在样式中的声明用于创建 GeoJSONSource 的实例。您也可以直接创建 GeoJSONSource 的实例。

您可能会发现 this example 对您有所帮助。