React Mapbox GL - 如何使用 Layer 和 Feature 而不是 Markers 在地图上绘制图像

React Mapbox GL - How to draw images on the map using Layer and Feature instead of Markers

我在我的项目中使用 React Mapbox GL,因为我使用 Marker 处理大约 10000 个数据点,性能不是很好。我已阅读文档,上面写着

Note: When rendering many objects, avoid using Markers as it will negatively affect performance. Use Layers and Features instead.

如何使用图层和要素显示标记?

要渲染具有图层和特征的内容,请放置一个或多个 Feature components inside of a Layer component。您可以使用 coordinates 属性给每个特征一个位置。

现在,剩下的就是设置这些功能的样式了。如何执行此操作取决于您之前包含的标记,但是例如,如果您想为每个位置绘制圆圈,您可以将图层的 type 设置为 circle 并在 paint 属性,为 circle-colorcircle-radius 提供值(这些在 mapbox-gl API docs.

中有描述

为每个坐标绘制图片,可以使用icon-image layout property on the Layer (you would have to either use a preexisting icon or upload one to Mapbox Studio).

您可以在演示中看到一些示例代码,例如 all-shapes demo 带圆圈的样式数据。