OSMdroid : How to load offline map from zip archive - MapTileFileArchiveProvider

空扰寡人 提交于 2019-12-29 06:30:08

问题


I really need some help with the OSMdroid library. It is useful to have maps stored in sdcard as zip files. Also, maps can be unzipped and the image files may be used directly for faster rendering.

I managed to load tiles from my sdcard when the tiles are unziiped, have .tile extension and are stored in the folder /sdcard/osmdroid/tiles/Mapnik/... To create my map I used the Mobile Atlas Creator and OSMAND tile storage format.

I read some tutorials on the web that claim storing zip files containing tiles are stored in /sdcard/osmdroid then the offline map will be loaded from the zip. But it does not work for me.

  1. Did anybody managed to make it work? If so how?

  2. Do I need to instantiate my own MapTileFileArchiveProvider? If so, how can I do that? Any examples?


回答1:


The files in your ZIP need to be in the form of:

Z/X/Y.png

If you rename your Y.tile files to Y.png, zip them up and put the zip file in /sdcard/osmdroid/, that should work.




回答2:


Just a correction or addition to the answer of user976933, the zip should also contain the name of the tilesource as base directory, the needed structure inside the zip is:

tilesourcename/Z/X/Y

The code loading the tiles is in BitmapTileSourceBase:

@Override
public String getTileRelativeFilenameString(final MapTile tile) {
    final StringBuilder sb = new StringBuilder();
    sb.append(pathBase());
    sb.append('/');
    sb.append(tile.getZoomLevel());
    sb.append('/');
    sb.append(tile.getX());
    sb.append('/');
    sb.append(tile.getY());
    sb.append(imageFilenameEnding());
    return sb.toString();
}

public String pathBase() {
    return mName;
}


来源:https://stackoverflow.com/questions/7634148/osmdroid-how-to-load-offline-map-from-zip-archive-maptilefilearchiveprovider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!