How To Create Osmdroid Xytilesource For Offline Tiles In Version 4.1?
I have offline osmdroid maps working using version 4.0. Upgrading to 4.1, they no longer work. I have narrowed the problem down to the XYTileSource, in which aBaseUrl changed from
Solution 1:
I tried to provide a full answer here: Download maps for osmdroid
If you have an "old" tiles.zip, open it, and check:
- the root directory name => put it as the "aName" of XYTileSource constructor (is it really "tiles"?)
- the tiles images extension => put it as the aImageFileNameEnding (is it really ".png"?)
The aResourceId and aBaseUrl params are not used for zip files.
Solution 2:
I see that you are using XYTileSource
, which by default extends OnlineTileSourceBase
.
I have found a workaround for the Url
issue, by creating a CustomTileSource
class. Something like below:
publicclassCustomTileSourceextendsOnlineTileSourceBase{
publicstaticString[] TILE_URL = {"my_url"};
//constructor is default - I changed nothing herepublic CustomTileSource (String aName, string aResourceId, int aZoomMinLevel, int aZoomMaxLevel,
int aTileSizePixels, String aImageFilenameEnding, String[] url) {
super(
aName,
aResourceId,
aZoomMinLevel,
aZoomMaxLevel,
aTileSizePixels,
aImageFilenameEnding,
url);
// TODO Auto-generated constructor stub
}
/**
* returns the url for each tile, depending on zoom level
*///this is where I changed the return statement to take the first url from the string array of urls
@Override
publicString getTileURLString(MapTile aTile) {
return TILE_URL[0] + aTile.getX() + "+" + aTile.getY() + "+" + aTile.getZoomLevel();
}
}
In my code, where I need to instantiate the tilesource, I use:
CustomTileSource tileSource = new CustomTileSource ("Default", ResourceProxy.string.offline_mode, MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT, CustomTileSource.TILE_URL);
//MIN_ZOOM_LVL, MAX_ZOOM_LVL, DEFAULT_TILE_SIZE, TILE_FORMAT are constants that I defined elsewhere
Hope it helps.
Post a Comment for "How To Create Osmdroid Xytilesource For Offline Tiles In Version 4.1?"