I trying to implement OSM using osmdroid, so far i am able to do everything correctly. But i would like to know how i can set two tile sources on top of each other.
Below is how i am trying to implement:
map = (MapView) findViewById(R.id.map);
map.getTileProvider().getTileCache().getProtectedTileComputers().clear();
map.getTileProvider().getTileCache().setAutoEnsureCapacity(false);
map.setTileSource(TileSourceFactory.MAPNIK);
map.setTileSource(new OnlineTileSourceBase("USGS Topo", 0, 18, 256, ".png?apikey=123",
new String[] { "https://api.xyz.com/maps/satellite/zxy/2020-04-21T16:10:00Z/" }) {
@Override
public String getTileURLString(long pMapTileIndex) {
return getBaseUrl()
+ MapTileIndex.getZoom(pMapTileIndex)
+ "/" + MapTileIndex.getY(pMapTileIndex)
+ "/" + MapTileIndex.getX(pMapTileIndex)
+ mImageFilenameEnding;
}
});
map.setVerticalMapRepetitionEnabled(false);
So far i am getting below output but there is no mapnik source under the satellite tile source.
but i need the output to look like this
How do i achieve this?
As mentioned in the wiki docs on osmdroid's GitHub page , you can use more than one tile source at a time.
You can only set one setTileSource
, so for your code to work you need to set the map as the tile source and add the weather tile layer as an overlay over it.
map = (MapView) findViewById(R.id.map);
map.getTileProvider().getTileCache().getProtectedTileComputers().clear();
map.getTileProvider().getTileCache().setAutoEnsureCapacity(false);
map.setTileSource(TileSourceFactory.MAPNIK);
MapTileProviderBasic provider = new MapTileProviderBasic(MainActivity.this, new OnlineTileSourceBase("USGS Topo", 0, 18, 256, "png?apikey=123", new String[0]) {
@Override
public String getTileURLString(MapTile aTile) {
// BoundingBox bbox = tile2boundingBox(aTile.getX(), aTile.getY(), aTile.getZoomLevel());
// String baseUrl ="https://api.xyz.com/maps/satellite/zxy/2020-04-21T16:10:00Z/?dpi=96&transparent=true&format=png24&bbox="+bbox.west+","+bbox.south+","+bbox.east+","+bbox.north+"&size=256,256&f=image";
return "https://api.xyz.com/maps/satellite/zxy/2020-04-21T16:10:00Z/" + aTile.getZoomLevel() + "/" + aTile.getY() + "/" + aTile.getX();
// return baseUrl;
}
});
TilesOverlay layer = new TilesOverlay(provider, MainActivity.this);
layer.setLoadingBackgroundColor(Color.TRANSPARENT);
layer.setLoadingLineColor(Color.TRANSPARENT);
map.getOverlays().add(layer);
map.setVerticalMapRepetitionEnabled(false);
If you are using osmndroid-wms then too you can use a map layer and an overlay layer on it by changing the following line
MapTileProviderBasic provider = new MapTileProviderBasic(MainActivity.this, mWMSTileSource)
over here mWMSTileSource
will be the response you get from WMSTileSource.createFrom(WMSEndpoint endpoint, WMSLayer layer)
after you have made a call to the WMS server as mentioned in the wiki .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.