我正在尝试通过api以编程方式在我的mapbox帐户中创建新的mapbox样式。但是,我发现缺少相关文档。用于通过api创建样式的mapbox文档在此处:
https://docs.mapbox.com/api/maps/#create-a-style
从技术角度看,这似乎很简单。但是,我发现实际的实现更加复杂。他们给出的示例(我正在以此为起点)使用以下结构:
{
"version": 8,
"name": "My Awesome Style",
"metadata": { },
"sources": {
"myvectorsource": {
"url": "mapbox://{tileset_id}",
"type": "vector"
},
"myrastersource": {
"url": "mapbox://{tileset_id}",
"type": "raster"
}
},
"glyphs": "mapbox://fonts/{username}/{fontstack}/{range}.pbf",
"layers": [ ]
}
很简单。但这与我在mapbox Studio编辑器中创建样式所做的工作没有很好的关联。在mapbox studio中,我从这样的模板开始:
我从“基本”模板开始,然后继续在编辑器中添加我的自定义图层之一:
实际上,这就是我试图通过mapbox api以编程方式实现的目标。但是,我被困在2点上,这是我的问题:
layers
is an array. But an array of what? Urls? Ids? Something else? For reference, I desire to attach the following custom layer to my new style: Essentially, I would like to know what my payload needs to look like in order to create a new style using the basic template and one additional custom layer. So far I have tried this:
{
"version": 8,
"name": "test style via api",
"metadata": null,
"sources": {
"myrastersource": {
"url": "mapbox://styles/mapbox/streets-v11",
"type": "raster"
}
},
"glyphs": null,
"layers": []
}
After which I receive the error "Source url must be a valid Mapbox tileset url".
And I have tried this:
{
"version": 8,
"name": "test style via api",
"metadata": null,
"sources": {
"myrastersource": {
"url": "mapbox://styles/mapbox/streets-v11",
"type": "raster"
}
},
"glyphs": null,
"layers": ["kenazthomas.c8ieto90"]
}
After which I receive the error "layers[0]: either 'type' or 'ref' is required"
What should my payload look like?
The documentation of Mapbox's Maps API (of which the endpoint you're trying to call is a part of) mentions this under the top-level Styles header:
You will need to be familiar with the Mapbox Style Specification to use the Styles API. The Mapbox Style Specification defines the structure of map styles and is the open standard that helps Studio communicate with APIs and produce maps that are compatible with Mapbox libraries.
The relevant section of the Style object documentation is the Layers page, which contains details on the object field and its details, as well as an example:
"layers": [
{
"id": "water",
"source": "mapbox-streets",
"source-layer": "water",
"type": "fill",
"paint": {
"fill-color": "#00ffff"
}
}
]
您将需要在source
和source-layer
字段中引用自定义上传的图层,因此您可能还应该查看Sources对象文档。假设您的自定义图层是矢量图层,则可能会mapbox://<Tileset ID>
在Layer对象中对其进行引用。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句