How to add own tile in Mapbox 4.1

孤街浪徒 提交于 2019-12-12 15:20:05

问题


I have a source for tiles as an url and want to add these to my map. I am able to do this with Google Map and OSMDroid, but I do not know how to figure it out using Mapbox.

My url has the format "http...mysource..x=..y=..z=.."

I have seen a solution for web, but I do not find such an approach for mobile.


回答1:


I assume you have a URL for a tile server such as http://server/tiles/{z}/{x}/{y}.png If so, please update your question.

Please see this Mapbox example, https://www.mapbox.com/android-sdk/examples/custom-raster/ to add in a custom Mapbox Style. Note the parameter for setStyleUrl. Open up that json file and inspect it.

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

You will then need to create two JSON files. See this project (which is for iOS, but the JSON files are identical for Android, Web, and iOS.).


tile.json sample

{
    "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, put this in the parameter for 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"
    }
  ]
}


来源:https://stackoverflow.com/questions/40411025/how-to-add-own-tile-in-mapbox-4-1

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!