gpt4 book ai didi

api - 使用 Mapbox 静态 api 绘制多边形

转载 作者:行者123 更新时间:2023-12-05 09:21:05 26 4
gpt4 key购买 nike

在 mapbox api 上尝试将多边形添加到静态 map 时,我不断收到 消息:“无效的 GeoJSON” 错误。

在下面的 map 上:

https://api.mapbox.com/v4/mapbox.streets/geojson(%7B%22type%22%3A%22Feature%22%2C%22properties%22%3A%7B%7D%2C%22geometry%22%3A%7B%22type%22%3A%22LineString%22%2C%22coordinates%22%3A%5B%5B-120.8492%2C39.4916%5D%2C%5B-120.8474%2C39.4896%5D%2C%5B-120.8510%2C39.4864%5D%2C%5B-120.8492%2C39.4916%5D%5D%7D%7D),pin-s-1+f44(-120.849200,39.491600,13),pin-s-2+f44(-120.847400,39.489600,13),pin-s-3+f44(-120.851000,39.486400,13),geojson(%7B%22type%22%3A%22Feature%22%2C%22properties%22%3A%7B%22stroke-width%22%3A4%2C%22stroke%22%3A%22%23ff4444%22%2C%22stroke-opacity%22%3A0.5%7D%2C%22geometry%22%3A%7B%22type%22%3A%22LineString%22%2C%22coordinates%22%3A%5B%5B39.4916%2C%20-120.8492%5D%2C%5B39.4896%2C%20-120.8474%5D%2C%5B39.4864%2C%20-120.8510%5D%2C%5B39.4888%2C%20-120.8496%5D%5D%7D%7D)/-120.849600,39.488800,15/800x400.png?access_token=token

我的 LineString 示例用于勾勒出我希望绘制的多边形的边界:

geojson({"type":"Feature","properties":{},"geometry":{"type":"LineString","coordinates":[[-120.8492,39.4916],[-120.8474,39.4896],[-120.8510,39.4864],[-120.8492,39.4916]]}})

如果尝试使用以下 geojson 对象将其变成多边形:

geojson({"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[-120.8492,39.4916],[-120.8474,39.4896],[-120.8510,39.4864],[-120.8492,39.4916]]}})

爆炸了:

https://api.mapbox.com/v4/mapbox.streets/geojson(%7B%22type%22%3A%22Feature%22%2C%22properties%22%3A%7B%7D%2C%22geometry%22%3A%7B%22type%22%3A%22Polygon%22%2C%22coordinates%22%3A%5B%5B-120.8492%2C39.4916%5D%2C%5B-120.8474%2C39.4896%5D%2C%5B-120.8510%2C39.4864%5D%2C%5B-120.8492%2C39.4916%5D%5D%7D%7D),pin-s-1+f44(-120.849200,39.491600,13),pin-s-2+f44(-120.847400,39.489600,13),pin-s-3+f44(-120.851000,39.486400,13),geojson(%7B%22type%22%3A%22Feature%22%2C%22properties%22%3A%7B%22stroke-width%22%3A4%2C%22stroke%22%3A%22%23ff4444%22%2C%22stroke-opacity%22%3A0.5%7D%2C%22geometry%22%3A%7B%22type%22%3A%22LineString%22%2C%22coordinates%22%3A%5B%5B39.4916%2C%20-120.8492%5D%2C%5B39.4896%2C%20-120.8474%5D%2C%5B39.4864%2C%20-120.8510%5D%2C%5B39.4888%2C%20-120.8496%5D%5D%7D%7D)/-120.849600,39.488800,15/800x400.png?access_token=token

有人能看出我做错了什么吗?我在查找使用静态 api 绘制多边形的任何示例时遇到问题,但 static api doc说这是可能的。

谢谢。

最佳答案

您的 geojson 字符串无效。您错过了坐标周围的两个方括号。这是一个有效的公式。

geojson({
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [[[-120.8492, 39.4916], [-120.8474, 39.4896], [-120.8510, 39.4864], [-120.8492, 39.4916]]]
}
})

如果你想用你的多边形生成静态 map ,相应的 API 调用类似于

https://api.mapbox.com/v4/mapbox.satellite/geojson(%7B%0A%20%20%20%20%22type%22%3A%20%22Feature%22%2C%0A%20%20%20%20%22properties%22%3A%20%7B%7D%2C%0A%20%20%20%20%22geometry%22%3A%20%7B%0A%20%20%20%20%20%20%20%20%22type%22%3A%20%22Polygon%22%2C%0A%20%20%20%20%20%20%20%20%22coordinates%22%3A%20%5B%5B%5B-120.8492%2C%2039.4916%5D%2C%20%5B-120.8474%2C%2039.4896%5D%2C%20%5B-120.8510%2C%2039.4864%5D%2C%20%5B-120.8492%2C%2039.4916%5D%5D%5D%0A%20%20%20%20%7D%0A%7D)/-120.8492,39.4890,15/600x300@2x.png?access_token={{your_access_token}}

可以在这个网站上试一下http://staticmapmaker.com/mapbox/

关于api - 使用 Mapbox 静态 api 绘制多边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34700418/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com