Here i'm releasing a library that enables you to add offline mapping to a GoogleMap.
MapsForgeTileProvider enables you to render a MapsForge map database file on a GoogleMap.
A MapsForge map database consists of (binary) vector map data and the MapsForgeTileProvider renders map tiles on the fly on the android device from the vector data in the database.
Instead of many MBs or GBs of pre-rendered image file map tiles to enable offline mapping, a map database enables you to provide offline mapping in a relatively compact format.
As an example i have a map database that contains data for Great Britain, this map database is 306MBs in size.
The MapsForgeTileProvider can render map tiles for Great Britain at zoom levels 0 to 21 from this database.
Covering a similar area using image files as tiles for zoom level 0 to
16 would require over 4.4
million individual image tiles.
The FAT32 file system used on most device's external memory uses a cluster size of at least 4KB, a single file stored on a FAT32 file system will always use at least 4KBs.
4.4 million multiplied by at least 4KBs is a lot of memory space!
MapsForgeTileProvider isn't perfect though...
- It's a single threaded library that will not make use of multi-core CPUs.
- The larger your map database, the slower tile rendering will be.
This is more noticeable when zoomed out to low zoom levels.
- The MapsForge library which i have created the MapsForgeTileProvider from has had a bug when rendering tiles which contain both land and sea for a long while.
A few attempts have been made to fix the bug but it remains unfixed.
If a tile contains both land and sea then the sea area will be rendered as white.
UPDATE: Read this post for a possible solution.
- If your map database is derived from Open Street Map data you may find it contains erroneous data.
This is a problem with the Open Street Map project itself and it's contributors, not a MapsForge problem.
- GoogleMaps allows variable zoom levels - you can for example pinch zoom to zoom level 6.45.
The built in GoogleMaps MapTypes all look good at non-integer zoom levels.
But the MapsForgeTileProvider is based on code that renders tiles for integer zoom levels only.
If you pinch zoom the map to a non-integer zoom level then often you'll see visual artifacts (pixelation) where GoogleMaps has upscaled a MapsForgeTileProvider tile.
More info on the original android MapsForge project can be found here:
http://code.google.com/p/mapsforge/.
MapsForgeTileProvider
Version: 1.0
- MapDatabase
Methods:
- CloseFile
Closes the map file and destroys all internal caches.
- HasOpenFile As Boolean
Returns True if a map file is currently opened, False otherwise.
- IsInitialized As Boolean
Properties:
- MapFileInfo As MapFileInfo [read only]
- MapFileInfo
Methods:Properties:
- Comment As String [read only]
Get the comment field of the map database.
The comment field can be set when the map database is created.
It may not have been set, in which case this method will return an empty String "".
- CreatedBy As String [read only]
Get the created by field of the map database.
The created by field can be set when the map database is created.
It may not have been set, in which case this method will return an empty String "".
- FileSize As Long [read only]
Get the size of the map database, measured in bytes.
- FileVersion As Int [read only]
Get the file version of the map database.
- LanguagePreference As String [read only]
Get the preferred language for names as defined in ISO 3166-1.
The preferred language for names can be set when the map database is created.
It may not have been set, in which case this method will return an empty String "".
- LatLngBounds As LatLngBounds [read only]
Get the area covered by the map database file as a LatLngBounds object.
- MapDate As Long [read only]
Get the date of the map database in milliseconds since January 1, 1970.
- PoiTags() As Tag [read only]
Get the POI Tags from the map database.
- StartLatLng As LatLngWrapper [read only]
Get the map database start position.
The start position can be set when the map database is created.
It may not have been set, in which case this method will return a LatLng that is NOT initialized.
- StartZoomLevel As Int [read only]
Get the map start zoom level
The start zoom can be set when the map database is created.
It may not have been set, in which case this method will return a value of -1.
- WayTags() As Tag [read only]
Get the way Tags from the map database.
- MapsForgeTileProvider
Methods:
- GetMapsForgeTileProviderOptions As MapsForgeTileProviderOptions
Gets the MapsForgeTileProviderOptions that will be used when the MapsForgeTileProvider Initialize method is called.
- Initialize
Initialize the MapsForgeTileProvider.
You must have set any MapsForgeTileProviderOptions required options before calling Initialize.
- IsInitialized As Boolean
- SetNoTileTile (NoTileTile As Tile)
Sets a Tile to be used when there is no tile available from the MapsForge map database.
Pass Null to restore the default 'no tile' tile.
- SetTextScale (TextScale As Float)
Sets the text scale.
Default value is 1.
Properties:
- MapDatabase As MapDatabase [read only]
- MapsForgeTileProviderOptions
Fields:
- BITMAP_CONFIG_ARGB_8888 As Config
Each pixel is stored on 4 bytes.
Each channel (RGB and alpha for translucency) is stored with 8 bits of precision.
- BITMAP_CONFIG_RGB_565 As Config
Each pixel is stored on 2 bytes and only the RGB channels are encoded.
Methods:
- SetBitmapConfig (BitmapConfig As Config) As MapsForgeTileProviderOptions
Optionally set the Bitmap.Config for the rendered tiles.
Default value is BITMAP_CONFIG_RGB_565.
- SetDebugSettings (DrawTileCoordinates As Boolean, DrawTileFrames As Boolean, HighlightWaterTiles As Boolean) As MapsForgeTileProviderOptions
Optionally set the DebugSettings.
Default values are:
DrawTileCoordinates - False.
DrawTileFrames - False.
HighlightWaterTiles - False.
- SetMapDatabaseFile (Dir As String, FileName As String) As MapsForgeTileProviderOptions
Set the path to the MapsForge map database file.
- SetNoTileTile (NoTileTile As Tile) As MapsForgeTileProviderOptions
Optionally set the Tile to be used when there is no tile available from the MapsForge map database.
- SetRenderTheme (InputStream1 As InputStream) As MapsForgeTileProviderOptions
Optionally set a custom RenderTheme to be used to render tiles.
Default value is Null which means that the built in default RenderTheme will be used.
- SetTextScale (TextScale As Float) As MapsForgeTileProviderOptions
Optionally set the text scale.
Default value is 1.
- Tag
Methods:
- Equals (Tag1 As Tag) As Boolean
- IsInitialized As Boolean
Properties:
- Key As String [read only]
- Value As String [read only]
In order to use MapsForgeTileProvider you will need the latest version of GoogleMapsExtras.
I've not added MapsForgeTileProvider to GoogleMapsExtras.
MapsForgeTileProvider contains a folder of various images used in the rendering process and, if included in GoogleMapsExtras, these images would be included in your project whether you used MapsForgeTileProvider or not. We're talking about less than 100KBs here, not a lot but there's no point bloating a project with unused assets.
So this is MapsForgeTileProvider 1.0, and it is attached to the first post in this thread.
An example project can be found here:
http://www.b4x.com/android/forum/threads/google-maps-android-v2-tutorial.24415/page-13#post-199802.
Martin.