首页 > 解决方案 > Mapbox Static API - 如何在 GeoJSON 叠加层中使用自定义标记?

问题描述

文档说这是可能的,所以我显然遗漏了一些东西。到目前为止,我已经在 Mapbox操场上使用单点和特征集合(如示例中所示)测试了 marker-url 和 url- 的不同变体,但我得到的只是通用标记。

有什么指导可以为我指明正确的方向吗?

https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/geojson({"type":"FeatureCollection","features":[{"type":"Feature","properties":{"url-":"http%253A%252F%252Fwebsite.com%252Ffiles%252Fmarkers%252Fgreenpin.png"},"geometry":{"type":"Point","coordinates":[-122.2599,37.8098]}},{"type":"Feature","properties":{"url-":"http%253A%252F%252Fwebsite.com%252Ffiles%252Fmarkers%252Fgreenpin.png"},"geometry":{"type":"Point","coordinates":[-122.2591,37.8062]}},{"type":"Feature","properties":{"url-":"http%253A%252F%252Fwebsite.com%252Ffiles%252Fmarkers%252Fgreenpin.png"},"geometry":{"type":"Point","coordinates":[-122.2565,37.8063]}}]})/-122.2647,37.8006,12,0/1080x1080@2x?access_token={token}

标签: mapbox

解决方案


这没有反映在官方文档中,但是为了使用带有 geojson 覆盖的自定义标记,您可以依赖该marker-url属性来实现您的功能。

如果您将对 API 的请求更新为以下内容,您应该会获得所需的结果:

https://api.mapbox.com/styles/v1/mapbox/streets-v11/static/geojson({"type":"FeatureCollection","features":[{"type":"Feature","properties":{"marker-url":"http%253A%252F%252Fwebsite.com%252Ffiles%252Fmarkers%252Fgreenpin.png"},"geometry":{"type":"Point","coordinates":[-122.2599,37.8098]}},{"type":"Feature","properties":{"marker-url":"http%253A%252F%252Fwebsite.com%252Ffiles%252Fmarkers%252Fgreenpin.png"},"geometry":{"type":"Point","coordinates":[-122.2591,37.8062]}},{"type":"Feature","properties":{"marker-url":"http%253A%252F%252Fwebsite.com%252Ffiles%252Fmarkers%252Fgreenpin.png"},"geometry":{"type":"Point","coordinates":[-122.2565,37.8063]}}]})/-122.2647,37.8006,12,0/1080x1080@2x?access_token={token}

免责声明:我目前在 Mapbox 工作


推荐阅读