I've been using Mapbox's Android SDK for a prototype and was wondering if anyone knows how to use a vector tile map that is not from Mapbox's servers. For example, I want to load Mapzen or even OpenMapTiles vector tile maps using Mapbox's Android SDK without much difference versus loading Mapbox's default map styles.
You could do this using MapView#setStyleUrl
.
First create mapzen.json
in your assets/
directory with this simple style (be sure to replace YOUR_MAPZEN_API_KEY
with your real key) https://mapzen.com/developers/sign_up
{
"version": 8,
"sources": {
"osm": {
"type": "vector",
"tiles": ["https://vector.mapzen.com/osm/all/{z}/{x}/{y}.mvt?api_key=[YOUR_MAPZEN_API_KEY]"]
}
},
"layers": [{
"id": "background",
"type": "background",
"paint": {
"background-color": "#41afa5"
}
}, {
"id": "water",
"type": "fill",
"source": "osm",
"source-layer": "water",
"filter": ["==", "$type", "Polygon"],
"paint": {
"fill-color": "#3887be"
}
}]
}
Then set the custom style on your MapView
:
mapView.setStyleUrl("asset://mapzen.json");
And finally, load the map:
mapView.getMapAsync(new OnMapReadyCallback() {
@Override
public void onMapReady(MapboxMap mapboxMap) {
//customize map
}
});