How to add own tile in Mapbox 4.1

2019-07-03 05:06发布

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条回答
We Are One
2楼-- · 2019-07-03 05:41

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"
    }
  ]
}
查看更多
登录 后发表回答