Map tiles in Osmdroid are provided by map tile providers. The default tile provider used by Osmdroid is MapTileProviderBasic. This provider extends MapTileProviderArray, which means that it is an array of a few other tile providers - when a tile is requested these tile providers are asked one by one for a tile image until one of them provides it. Take a look at the constructor of MapTileProviderBasic
:
public MapTileProviderBasic(final IRegisterReceiver pRegisterReceiver,
final INetworkAvailablityCheck aNetworkAvailablityCheck,
final ITileSource pTileSource) {
super(pTileSource, pRegisterReceiver);
final TileWriter tileWriter = new TileWriter();
final MapTileFilesystemProvider fileSystemProvider =
new MapTileFilesystemProvider(pRegisterReceiver, pTileSource);
mTileProviderList.add(fileSystemProvider);
final MapTileFileArchiveProvider archiveProvider =
new MapTileFileArchiveProvider(pRegisterReceiver, pTileSource);
mTileProviderList.add(archiveProvider);
final MapTileDownloader downloaderProvider =
new MapTileDownloader(pTileSource, tileWriter, aNetworkAvailablityCheck);
mTileProviderList.add(downloaderProvider);
}
There are three map tile providers added to the array of providers, in this order:
MapTileFilesystemProvider
- provides tiles from the file system (SD card directory)
MapTileFileArchiveProvider
- provides tiles from archive in file system
MapTileDownloader
- provides tiles by downloading them from the Internet (e.g. from OSM servers)
So the MapTileProviderBasic
looks for a given tile first in the file system, if the tile is not available then it looks for it in archive files and again if it is not available there it downloads the tile from the Internet.
Ok, this is the default mechanism. If you want to change this mechanism to look for tiles stored in a DB then you can create you own class similar to MapTileProviderBasic
. So your class could also extend MapTileProviderArray
and just use other providers in the constructor. In Osmdroid there is a class DatabaseFileArchive which could probably help you in reading tiles from the DB.
After creating your own tile provider you should use it instead of the default one. Map tile providers are attached to the MapView
. Some of the constructors of MapView
take MapTileProviderBase
as an argument - you can use one of them to attach your own provider.