Search code examples
dictionaryosmdroid

Osmdroid. How to use two online tile source base the same time in mapview


Sorry for my bad English. I have question. Is it possible to use two or more online source base the same time in the mapview? For example, i have two online source base, one of this map tiles, and the other one displays traffic jam in the roads. Both tiles are 256x256 px jpg format. I want to display traffic jam tiles above map tiles. is it possible?


Solution

  • Yes, it is possible. Create a new TilesOverlay for your traffic jam tiles and add it to the list of overlays of your map.

    Take a look at SampleWithTilesOverlayAndCustomTileSource.java in the OpenStreetMapViewer samples:

    final MapView osmv = new MapView(this, 256);
    
    // …
    
    // Add tiles layer with custom tile source
    final MapTileProviderBasic tileProvider = 
            new MapTileProviderBasic(getApplicationContext());
    final ITileSource tileSource =
            new XYTileSource("FietsRegionaal", null, 3, 18, 256, ".png",
            new String [] {"http://overlay.openstreetmap.nl/openfietskaart-rcn/"});
    tileProvider.setTileSource(tileSource);
    final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider,
            this.getBaseContext());
    tilesOverlay.setLoadingBackgroundColor(Color.TRANSPARENT);
    
    osmv.getOverlays().add(tilesOverlay);