Aliaaa
Aliaaa

Reputation: 1668

osmdroid how to use multiple tile provider?

I want to use both online and offline map tile provider in osmdroid. So I created a class MyTileProvider that extends MapTileProviderArray; then I add both of my offline and online providers to the provider list. Theatrically based on documents it should look on first provider and if it not provides the tile and returned null then going to another provider to look up the tile.
But the online provider does not works on places that offline returns null. Here is my code:

class MyTileProvider extends MapTileProviderArray
{
private static ITileSource tileSource;

protected MyTileProvider(Context context)
{
    super(tileSource = TileSourceFactory.MAPNIK, new SimpleRegisterReceiver(context));
    // offline tile providing:
    mTileProviderList.add(new OfflineMapTileProvider(context, tileSource));
    // online tile providing:
    mTileProviderList.add(new MapTileDownloader(TileSourceFactory.MAPNIK));

    setTileSource(tileSource);
}
}

Any suggestions will be appreciated. Thanks.

Upvotes: 0

Views: 1559

Answers (1)

koponk
koponk

Reputation: 472

try this :

//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);

Upvotes: 3

Related Questions