Informatic0re
Informatic0re

Reputation: 6350

OSMdroid change TileSource at Runtime

i working with osmdroid and i want to change the TileSource at runtime (via menu entry). For example i can change between OSM TileSource and GoogleTileSource.

Problem: Everything works fine, but when i change the TileSource while the mapview is loading a Tile in the background, it changes the TileSource but one or two tiles are from the TileSource befor. So i see a mixed MapView with OSMTiles and one or two GoogleTiles.

The tileCache is cleared everytime after changing the TileSource. But the loading tile in the background isnt in the cache at this moment, so he put this tile to the cache, after clearing it.

Any Idea to workaround this issue?? It is all based on osmdroid, i only work with setTileSource(ITileSource)

Thanks and Greetz

Upvotes: 3

Views: 4112

Answers (3)

Informatic0re
Informatic0re

Reputation: 6350

I think we all think it is a bug (or maybe it is not wanted to switch the TileSource at runtime).

I created a little Workarround. It works but it is not realy nice or recommended.

I created a new mapView and extend the osm MapView. Than create a RequestCompleteHandler, so i can see when a tile is finish loading and saved into the cache. Than i count every cached tile and only allow to switch the tileSource after 15 tiles are loaded. (at the start of the app osmdroid will load 15 tiles and only load some more after moving the map)

class RequestCompleteHandler extends SimpleInvalidationHandler{
    private LbsMapView mMapView;

    public RequestCompleteHandler(LbsMapView pView) {
        super(pView);
        mMapView = pView;
    }

    @Override
    public void dispatchMessage(Message msg) {
        super.dispatchMessage(msg);
        Log.d("DEBUG", "HANDLER HAT GERUFEN! BACKE BACKE KUCHEN!! " + tileCount);
        tileCount++;
    }

}

then override the setTileSource method:

@Override
public void setTileSource(ITileSource aTileSource) {
    if(tileCount <= 15){
        Toast.makeText(mContext, "Jetz eher nich", Toast.LENGTH_SHORT).show();
    } else {
        tileCount = 0;
        super.setTileSource(aTileSource);
    }

}

and you need to set and initialise the Handler in the constructor:

mHandler = new RequestCompleteHandler(this);
    getTileProvider().setTileRequestCompleteHandler(mHandler);

done. Now you can switch the tileSource only when it allready loads 15 tiles. A little Problem: if the source are not working and do not load any tile you are in problems :D

But important: it is not recommended, its realy ugly code

Upvotes: 0

NickT
NickT

Reputation: 23873

If you are using osmdroid3.0.6.jar (and I think you are, as I can reproduce this bug if I build with 3.0.6). I think it's another manifestation of the issue I raised osmdroid-android-3.0.6.jar, tile loading slow or fails. This bug has been accepted by the authors.

I suggest you go back to using the 3.0.5 jar. I don't get any problems with that. (I'm still puzzled as to how you get to use Google tiles with Osmdroid)

Upvotes: 1

Ifor
Ifor

Reputation: 2835

Looks like a proper bug to me. I think you should report it as such. I can not see anything like it in the issues list. It looks like the bad tile even gets into the wrong cache on the sd card which is bad as it will be there for a while.

Upvotes: 1

Related Questions