如何通过mapbox api以编程方式创建新的mapbox样式?

马特·斯平克斯

我正在尝试通过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选择样式模板

我从“基本”模板开始,然后继续在编辑器中添加我的自定义图层之一: 在mapbox Studio编辑器中添加我的自定义图层

实际上,这就是我试图通过mapbox api以编程方式实现的目标。但是,我被困在2点上,这是我的问题:

  1. “创建样式”的api端点没有“模板”的选项。相反,它允许“源”和“层”。“基本”模板如何与源和图层相关联?换句话说,为了实现“基本模板”的结果,需要以编程方式添加哪些源和层?
  2. How do I add my custom layer to this "create style" request? I see that 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?

Rafael Almeida

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"
    }
  }
]

您将需要在sourcesource-layer字段中引用自定义上传的图层,因此您可能还应该查看Sources对象文档假设您的自定义图层是矢量图层,则可能会mapbox://<Tileset ID>在Layer对象中对其进行引用

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

mapbox gl-js:如何从 mapbox studio 获取点/多边形的样式并以编程方式定位?

来自分类Dev

如何通过网络表单使mapbox地图转到特定方向?

来自分类Dev

如何创建新的客户端证书/令牌,以编程方式访问GKE上托管的Kubernetes API?

来自分类Dev

MapBox Android如何隐藏Mapbox标签

来自分类Dev

MapBox Android如何隐藏Mapbox标签

来自分类Dev

如何从Mapbox获取CSS

来自分类Dev

如何在 mapbox-gl-draw 中以编程方式链接绘图点

来自分类Dev

如何检查我是否正在以编程方式创建新实例?

来自分类Dev

如何使用样式化组件添加样式以动态级别以编程方式创建标题?

来自分类Dev

通过API在Google上以编程方式创建会话操作

来自分类Dev

mapbox gl geojson样式

来自分类Dev

如何以编程方式创建API管理服务?

来自分类Dev

如何更改URL titleLayer mapbox

来自分类Dev

如何更改URL titleLayer mapbox

来自分类Dev

Mapbox Geolocation,如何载入地图?

来自分类Dev

使用mapbox js,如何更改地图样式?

来自分类Dev

如何设置单个Mapbox矢量图块的样式?

来自分类Dev

如何以编程方式创建/初始化具有自定义样式的Button?

来自分类Dev

如何通过文本查找以编程方式创建的按钮?

来自分类Dev

如何通过php以编程方式为wordpress创建作者?

来自分类Dev

在Ember中,如何以编程方式通过名称创建组件

来自分类Dev

如何以编程方式更改TabPageIndicator样式

来自分类Dev

如何从PNG中创建SDF-Icon(在Mapbox中使用)?

来自分类Dev

通过 ScalaTest 以编程方式添加新测试

来自分类Dev

以编程方式利用通过CloudFormation创建的资源

来自分类Dev

如何解决来自Mapbox的Surface API中的CORS问题?

来自分类Dev

mapbox API:如何为“ get”表达式设置后备?

来自分类Dev

Mapbox GL和公共样式

来自分类Dev

像FourSquare这样的Mapbox样式

Related 相关文章

  1. 1

    mapbox gl-js:如何从 mapbox studio 获取点/多边形的样式并以编程方式定位?

  2. 2

    如何通过网络表单使mapbox地图转到特定方向?

  3. 3

    如何创建新的客户端证书/令牌,以编程方式访问GKE上托管的Kubernetes API?

  4. 4

    MapBox Android如何隐藏Mapbox标签

  5. 5

    MapBox Android如何隐藏Mapbox标签

  6. 6

    如何从Mapbox获取CSS

  7. 7

    如何在 mapbox-gl-draw 中以编程方式链接绘图点

  8. 8

    如何检查我是否正在以编程方式创建新实例?

  9. 9

    如何使用样式化组件添加样式以动态级别以编程方式创建标题?

  10. 10

    通过API在Google上以编程方式创建会话操作

  11. 11

    mapbox gl geojson样式

  12. 12

    如何以编程方式创建API管理服务?

  13. 13

    如何更改URL titleLayer mapbox

  14. 14

    如何更改URL titleLayer mapbox

  15. 15

    Mapbox Geolocation,如何载入地图?

  16. 16

    使用mapbox js,如何更改地图样式?

  17. 17

    如何设置单个Mapbox矢量图块的样式?

  18. 18

    如何以编程方式创建/初始化具有自定义样式的Button?

  19. 19

    如何通过文本查找以编程方式创建的按钮?

  20. 20

    如何通过php以编程方式为wordpress创建作者?

  21. 21

    在Ember中,如何以编程方式通过名称创建组件

  22. 22

    如何以编程方式更改TabPageIndicator样式

  23. 23

    如何从PNG中创建SDF-Icon(在Mapbox中使用)?

  24. 24

    通过 ScalaTest 以编程方式添加新测试

  25. 25

    以编程方式利用通过CloudFormation创建的资源

  26. 26

    如何解决来自Mapbox的Surface API中的CORS问题?

  27. 27

    mapbox API:如何为“ get”表达式设置后备?

  28. 28

    Mapbox GL和公共样式

  29. 29

    像FourSquare这样的Mapbox样式

热门标签

归档