Search code examples
androidsqliteosmdroid

OsmDroid load multiple offline map


I have different .sqlite map files and I would like to load on MapView. I'm able to load only one sqlite file. Is it possible to load multiple Offline maps ? In my case different sqlite files.


Solution

  • In short the answer is yes. Ironically, I did this myself just a few days ago.

    If you're using the same tile source, such as "Mapnik", spanned across multiple tile archives, then you shouldn't have to do anything. Just use the default tile provider, set setUseDataConnection(false), set your tile source to match the source of what's in your archives and you're off to the races. Since 5.0, you can also use the OfflineTileProvider and explicitly specify which tile archives to load.

    If you're using mixed tiles sources and want to create a composite (e.g. ignore all tile source names and just display the first tile available), then this is also possible with some trickery.

    1. First, override DatabaseFileArchive and remove the check for the tile source name
    2. Override other Archive classes as needed to remove the check for the tile source name.
    3. If you're using v5 or newer, you can then register your custom DatabaseFileArchive implementation using ArchiveFileFactory.registerArchiveFileProvider Older than v5? Use a custom tile provider
      1. Use any tile source you want at this point, since it's ignored at the file archive loader.

    With the second approach, you may run into some performance issues with a lot of tile archives, so just an FYI.

    Edit: There is another way to do this, using multiple TileOverlays. For everything other than the base layer, set the loading lines and background to transparent.