-
Notifications
You must be signed in to change notification settings - Fork 75
Combined tile sources
If you add several map layers, so their zoom range (defined with minZoom and maxZoom parameters) do not overlap, then you have different map sources for different zooms as one seamless base map. In the following example you have bundled map data (in apk package) in first 4 zooms, and online tile source map afterwards.
- Map tiles are in /res/raw folder, with t_ZOOM_X_Y.png pattern
- Code to activate layers:
// set basemap with zoom range 5 to 18
TMSMapLayer mapLayer = new TMSMapLayer(new EPSG3857(), 5, 18, 0,
"http://otile1.mqcdn.com/tiles/1.0.0/osm/", "/", ".png");
mapView.getLayers().setBaseLayer(mapLayer);
// set overlay with zoom range 0 to 4
PackagedMapLayer packagedMapLayer = new PackagedMapLayer(mapLayer.getProjection(), 0, 4, 13, "t", this);
mapView.getLayers().addLayer(packagedMapLayer);
Here packagedMapLayer could be baseLayer and TMSMapLayer overlay, it would not make difference.
Another case could be that you want to use offline map tile (e.g. bundled map tile) and if this is not found, then use online tile. For this AdvancedLayers has FallbackRasterDataSource. Usage:
// Only if tile is not found from packaged datasource, then do online request.
// 1. define individual data sources
RasterDataSource offlineDataSource = new PackagedRasterDataSource(new EPSG3857(), 0, 5, "t{zoom}_{x}_{y}", getApplicationContext());
RasterDataSource onlineDataSource = new HTTPRasterDataSource(new EPSG3857(), 6, 20, "http://otile1.mqcdn.com/tiles/1.0.0/osm/{zoom}/{x}/{y}.png");
// 2. define combined data source
RasterDataSource dataSource = new FallbackRasterDataSource(offlineDataSource, onlineDataSource);
// 3. create layer, add to map
mapView.getLayers().addLayer(new RasterLayer(dataSource, id));
If you have full data coverage for some (e.g. lower) zooms in PackagedDataSource, then the previous approach - separating layers by zoom levels would be a bit faster. But for some other cases fallback is good strategy.