如何在 Mapbox 4.1 中添加自己的图块

How to add own tile in Mapbox 4.1

我有一个 url 的图块来源,想将它们添加到我的地图中。 我可以使用 Google MapOSMDroid 来做到这一点,但我不知道如何使用 Mapbox.

我的 url 格式为 "http...mysource..x=..y=..z=.."

我看到过针对网络的解决方案,但我没有找到针对移动设备的解决方案。

我假设您有一个 URL 用于磁贴服务器,例如 http://server/tiles/{z}/{x}/{y}.png 如果是这样,请更新您的问题。

请参阅此 Mapbox 示例,https://www.mapbox.com/android-sdk/examples/custom-raster/ 添加自定义 Mapbox 样式。注意 setStyleUrl 的参数。打开那个 json 文件并检查它。

mapView.setStyleUrl("https://www.mapbox.com/android-sdk/files/mapbox-raster-v8.json");

然后您需要创建两个 JSON 文件。请参阅此 project(用于 iOS,但 JSON 文件对于 Android、Web 和 iOS 是相同的。


tile.json样本

{
    "name": "geography-class",
    "version": "1.0.0",
    "description": "",
    "type": "overlay",
    "format": "png",
    "minzoom": 0,
    "maxzoom": 8,
    "bounds": [-117.30596604, 32.78617375, -117.21820077, 32.88817706],
    "scale": "1",
    "profile": "mercator",
    "tiles": ["http://server/tiles/{z}/{x}/{y}.png"],
    "tilejson": "2.0.0",
    "scheme": "xyz"
}

Mapbox Style JSON,将其放在 setStyleUrl()

的参数中
{
  "version": 8,
  "sources": {
    "yourTileLayer": {
        "url": "http://server/tiles/tile.json",
        "type": "raster",
        "tiles": [
                  "http://server/tiles/{z}/{x}/{y}.png"
                  ],
        "tileSize": 256
    }
  },
  "layers": [
    {
      "id": "yourTileLayer",
      "type": "raster",
      "source": "yourTileLayer"
    }
  ]
}