문제

In my app, I am setting (online) source of tiles based on user's choice in the preferences (there are only 2 options possible - UMP and default, i.e. OpenStreetMaps). Here is how I change source of the tiles from the default:

SharedPreferences prefs = PreferenceManager
        .getDefaultSharedPreferences(getBaseContext());
if (prefs.getString("map_source_preference", "osm") == "ump") {
    final MapTileProviderBasic tileProvider = new MapTileProviderBasic(
            getApplicationContext());
    final ITileSource tileSource = new XYTileSource("UMP Tiles", null,
            3, 14, 256, ".png", "http://tiles.ump.waw.pl/ump_tiles/");
    tileProvider.setTileSource(tileSource);
    final TilesOverlay tilesOverlay = new TilesOverlay(tileProvider,
            this.getBaseContext());
    mapView.getOverlays().add(tilesOverlay);
}

My question is: how do I set tile provider back to the OSMDroid's default? Would tileProvider.detach() work in this case?

도움이 되었습니까?

해결책

You don't want to create a new TilesOverlay when you change ITileSource. You can call

mapView.setTileSource(tileSource);

and that will apply your new tile source to the existing TilesOverlay.

If you wanted to go back to the default tile source you can call

mapView.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top