How to use MOBAC created OSMDroid SQLite tile source file offline?

余生颓废 提交于 2019-12-03 04:57:57

OK! I know what I doing wrong and I have it all working now! (I'm excited :)

Firstly, I had some trouble with writing my Raw resource map file to the application specific directory (e.g. openFileOutput()) I'm using a Galaxy Nexus which doesn't have an SD slot so I can't dump the map file to SD. Ensure the maps file you intend to use is byte compared with the original copy. Eclipse's DDMS perspective is useful to view a device's file structure.

I also switched to the OSMdroid Zip format. I then made sure the XYTileSource() name matched the directory created in the Zip file by MOBAC, plus ensure the tile size and zoom levels match.

XYTileSource TILERENDERER = new XYTileSource("OSM CloudMade 1", ResourceProxy.string.offline_mode, 16, 18, 256, ".png", "http://127.0.0.1");

MOBAC by default will create 256 pixel tiles. I created an atlas file with 16, 17, and 18 zoom levels. PNG is the default MOBAC tile image format.

Also, if your map file has any issues, ArchiveFileFactory.getArchiveFile() will catch them, even before MapTileFileArchiveProvider.

Here's my usage. Just make every effort to get your IArchive setup correctly and you should be ok:

        XYTileSource TILERENDERER = new XYTileSource("OSM CloudMade 1", ResourceProxy.string.offline_mode, 16, 18, 256, ".png", "http://127.0.0.1");
        SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this.context);
        IArchiveFile[] archives = { ArchiveFileFactory.getArchiveFile(this.getMapsSdCard()) };
        MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(
                simpleReceiver, 
                TILERENDERER, 
                archives);
        this.mapProvider = new MapTileProviderArray(TILERENDERER, null, new MapTileModuleProviderBase[] { moduleProvider });
        this.mapProvider.setUseDataConnection(false);
        this.mapView = new MapView(this, 256, this.resourceProxy, this.mapProvider);
        this.mapView.setUseDataConnection(false);

Maybe I'm the only one who had trouble with this, but osmdroid doesn't clearly document how to do this, and when I opened the issue I couldn't get them to comment on my usage. If they had said I was implementing MapTileFileArchiveProvider correctly or included a good offline mapping sample, I would have focused on everything else first.

Isidoro

If you want to use sqlite db you only have to change

ArchiveFileFactory.getArchiveFile(this.getMapsSdCard())

to

MBTilesFileArchive.getDatabaseFileArchive(f)

where f is a File that points to your sqlite database.

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