Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Downloading specific maptiles to cache in OSMDroid

I am currently working on a school project and I am trying to learn the techniques on downloading OSM map tiles into the phone's local memory/cache, so that users are able to view the maps when offline.

This is to be done by giving a specific location, and the map tiles that are within specific radius/distance from the location will be downloaded into the phone memory (when there is online connection) for offline display.

However, I am having some slight trouble in understanding OSMDroid's APIs. From my understanding, it seems that the classes involved are:

  • MapTileBase
  • MapDownloader
  • IFilesystemCache

Please do correct me if I'm mistaken.

Also, in MapTileBase (which I believe is the provider), the getMapTile returns android.graphics.drawable.Drawable.

Is this Drawable class even related to the concept of offline map display?

Hope someone can enlighten me on where exactly maps are being called to be downloaded into the phone's memory, and how we can edit the maps to display interface items such as routes, pins, etc.

like image 274
lyk Avatar asked Oct 19 '12 06:10

lyk


1 Answers

I don't have an exactly answer as you're looking for a method to cache offline outside of an area the MapView hasn't already navigated to. The built in caching support is there, but not exactly how you want to do it.

You're going to need online download capabilities if you plan to cache and not just supply your own offline map tiles. I would take a look at the MapTileDownloader and maybe try to implement your own version of it. The MapTileDownloader.TileLoader.loadTile() method takes a MapTileRequestState which I believe the MapTileProviderArray calls when a map tile is needed.

If you can replicate the existing MapTileDownloader's TileLoader functionality, you can probably inject your own relative MapTileRequestState or straight up MapTile's to the one requested. e.g. Take the TileLoader called MapTileRequestState, inspect it, figure out how to construct new MapTileRequestState/MapTile representing tiles outside the current view. It won't be easy though as you'll have to deal with the different zoom levels, and depending on the zoom level, the radius should be smaller, etc... A lower zoom level of 18 would have a larger tile radius than a higher 10.

Personally I was recently working on trying to work 100% offline so I don't have any example code to help. Good luck even though its been a couple of months.

like image 158
dubmojo Avatar answered Sep 25 '22 08:09

dubmojo