Multiple tile layers on osmdroid
Asked Answered
B

1

6

Currently I am loading one tile data-layer over an OSMdroid basemap with

final MapTileProviderBasic tileProvider = 
    new MapTileProviderBasic(getApplicationContext());
final ITileSource tileSource = 
    new XYTileSource("MyCustomTiles", null, 1, 16, 256, ".png",
            "http://a.url.to/custom-tiles/");
tileProvider.setTileSource(tileSource);
final TilesOverlay tilesOverlay = 
    new TilesOverlay(tileProvider, this.getBaseContext());
tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
osmv.getOverlays().add(tilesOverlay);

Is it possible to render multiple data layers on top of each other over the BaseMap or can I only display one data layer at a time? I found this example for GoogleMaps, but haven't found some example OSMdroid code dealing with multipe tileSources at a time.

Brahms answered 13/11, 2012 at 23:27 Comment(0)
R
7

Yes, of course you can. You just have to add another TilesOverlay to the map. The overlays(also tilesOverlays) get drawn consecutively, starting at the list's lowest index(=0). Here's an example:

//create the first tilesOverlay
final MapTileProviderBasic tileProvider = new MapTileProviderBasic(getApplicationContext());
final ITileSource tileSource = new XYTileSource("MyCustomTiles", null, 1, 16, 256, ".png",
        "http://a.url.to/custom-tiles/");
tileProvider.setTileSource(tileSource);
final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider, this.getBaseContext());
tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);

//create the second one
final MapTileProviderBasic anotherTileProvider = new MapTileProviderBasic(getApplicationContext());
final ITileSource anotherTileSource = new XYTileSource("MyCustomTiles", null, 1, 16, 256, ".png",
        "http://a.secondurl.to/custom-tiles/");
anotherTileProvider.setTileSource(anotherTileSource);
final TilesOverlay secondTilesOverlay = new TilesOverlay(anotherTileProvider, this.getBaseContext());
secondTilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);

// add the first tilesOverlay to the list
osmv.getOverlays().add(tilesOverlay);

// add the second tilesOverlay to the list
osmv.getOverlays().add(secondTilesOverlay);
Reprobative answered 10/12, 2012 at 10:35 Comment(2)
In my experiences, layers in the osmdroid library are a bit memory consuming, which means if you add more than 2 or 3 layers you will quickly run into some trouble(OutOfMemory Exception).Reprobative
how to change BaseLayer?Zina

© 2022 - 2024 — McMap. All rights reserved.