Android Tutorial MOBAC supports MapsForge for offline tiles

The latest alpha version of MOBAC supports rendering tiles from a local MapsForge database.

http://mobac.sourceforge.net/forum/viewtopic.php?f=1&t=526

This allows MOBAC to render bitmap tiles on-the-fly using Mapsforge vector data files. Those vector data files can be downloaded pre-generated for a large number of regions world-wide. Alternatively you can convert OpenStreetMap data to mapsforge format on your own.
The map rendering of the vector data can be configured using xml base render themes.

What does this mean?
  • If you use offline map tiles in your application you might have noticed that many tileservers are now blocking bulk download requests.
    For example, Mapnik no longer allows you to use MOBAC to download their tiles for use offline.
  • You'll also know that many tileservers are incredible slow and may throttle download requests to ensure that bulk downloaders do not overload the tileserver making it impossible for 'normal' requests to be served.
  • MOBAC only enables you to bulk download tiles from tileservers up to zoom level 16.
    The tileserver may support zoom levels up to 18 but MOBAC is hardcoded to only enable zoom levels up to 16.
    This is again an attempt to prevent you from overloading the tileserver.
  • When you download tiles from a tileserver your tiles are styled by the tileserver.
    You have no control over the rendering style of the tiles.
    Different tileservers offer differently styled tiles but you have no control over the styles.

MOBAC's support for MapsForge means you can forget about all of these limits and restrictions.

You will need:
  • The latest version 2.0 alpha MOBAC:
    http://sourceforge.net/projects/mobac/files/Alpha and experimental/
    MOBAC requires Java 7 to be installed, i'm using Java 8 and it works fine for me.
  • A MapsForge database. Download a database that covers the region that you want to create tiles for:
    http://download.mapsforge.org/
  • To define a new MOBAC Map Source that references your MapsForge database.
    An example is given:
    B4X:
    <?xml version="1.0" encoding="UTF-8"?>
    <mapsforge>
       <!-- name of the map - as shown in map source list -->
       <name>Custom Mapsforge</name>
       
       <!-- optional -->
       <minZoom>0</minZoom>
       
       <!-- optional -->
       <maxZoom>20</maxZoom>
          
       <!-- absolute or relative file name -->
       <mapFile>mapsforge-test.map</mapFile>
       
       <!-- optional default OSMARENDERER Theme -->
       <!-- <xmlRenderTheme>mytheme.xml</xmlRenderTheme> -->
       
       <transparent>false</transparent>
       
       <!-- text size scale factor -->
       <textScale>1.0</textScale>
       
    </mapsforge>
    Just modify the mapFile path to point to your MapsForge database.
    Save this as an XML file in your MOBAC/mapsources directory, the XML filename is not important.

Now start MOBAC and look in the (upper left) list of available Map Sources.
You should see your new 'Custom Mapsforge' Map Source.
Pan the map so that it shows an area covered by your MapsForge database and you'll see MOBAC is rendering and displaying tiles from your MapsForge database.

You can now create an offline tile archive using your new MapsForge Map Source.
Quick and simple with no limits and restrictions.

Now if you want MOBAC to render your tiles with a different style you can create a new custom 'Render Theme'.
Have a look here:
https://github.com/mapsforge/mapsforge/blob/master/docs/Rendertheme.md.

The current default MapsForge Render Theme can be found here:
https://github.com/mapsforge/mapsforge/tree/master/mapsforge-map/src/main/resources/osmarender
osmarender.xml defines exactly how your tiles are styled.

Creating a custom Render Theme can be as simple as changing the color of a feature such as a footpath.

Or you could spend time creating an entirely new Render Theme.

You can download the default MapsForge Render Theme and use it as a base for a new Render Theme.

Once you've created a new Render Theme you need to modify your MapsForge Map Source XML file, uncomment the 'xmlRenderTheme' element and set the path to your new Render Theme.
Restart MOBAC and you should now see your tiles are rendered using your new style.

MapsForge still has ongoing issues with tiles that contain both land and sea - the sea sometimes fails to render as blue.
A solution can be found here:
https://github.com/mapsforge/mapsforge-mapcreator
The MapCreator can be used to convert Open Street Map data into a MapsForge database using a technique which ensures that tiles that contain both land and sea are correctly rendered.

Martin.
 

warwound

Expert
Licensed User
Longtime User
Anyone wanting to experiment with custom Render Themes can take a look here:
http://www.openandromaps.org/en/legend/elevate-mountain-hike-theme.

I've just tried the 'Elevate 2' Render Theme with MOBAC and it works well - there's actually 4 different XML theme files to choose from.

I also tried 'Elevate 3' but MOBAC failed to render anything - maybe i didn't get the path to the theme file right.
Or (more likely) MOBAC doesn't support the latest version 0.5 MapsForge Render Themes...
 

Tom1s

Member
Licensed User
Longtime User
I am trying this. I took finland.map ~250mb and zoom levels 7-18 and selected the whole land. Trying to make osmdroid(zip). After 30min 0% with intel i7. Let's see if it ever finishes or do I have something wrong.

Then I try to get this zip working with osmdroid. Can I choose multiple *.map files somehow?
 
Last edited:

Tom1s

Member
Licensed User
Longtime User
I just noticed that I will try use binary open street map data and render it in tablet
 

warwound

Expert
Licensed User
Longtime User
I am trying this. I took finland.map ~250mb and zoom levels 7-18 and selected the whole land. Trying to make osmdroid(zip). After 30min 0% with intel i7. Let's see if it ever finishes or do I have something wrong.

Look in MOBAC near the left hand panel which lists the zoom levels you've selected to render.
You should see a count of how many tiles need to be rendered - i bet there's many thousands?
30 minutes doesn't sound excessive for a large area especially as you're rendering high zoom levels.
 

warwound

Expert
Licensed User
Longtime User
I just noticed that I will try use binary open street map data and render it in tablet

Using the MapsForge tile rendering library is a more elegant solution than an archive of thousands of tiles.
It'll probably require less storage space too.

But it'll require a reasonably powerful device to smoothly render the tiles.
Whereas an offline tile archive will workmsmoothly even on devices with low to average specs.
 

PCowling

Member
Licensed User
Longtime User
Hi Warwound,

Im struggling to recreate the work that you mention in post #2. I'd like to do the same using that map to create an offline map for my app. I am however drawing a blank at the moment. What help files did you use. I have read the ones that came with Mobac to no avail. Thanks if you can help.

Phil
 

warwound

Expert
Licensed User
Longtime User
Hi Warwound,

Im struggling to recreate the work that you mention in post #2. I'd like to do the same using that map to create an offline map for my app. I am however drawing a blank at the moment. What help files did you use. I have read the ones that came with Mobac to no avail. Thanks if you can help.

Phil

Hi.

I've not used MOBAC for a while so can't recall offhand exactly what i did to gtet the custom render themes to work.
I'd guess there's a syntax error in your render theme xml file.
Can you describe what the problem is?
Does MOBAC render anything - blank tiles for example - or does it fail to render anything whatsoever?
 

PCowling

Member
Licensed User
Longtime User
I place the XML file in the folder as outlined in the user guide. When I then start MOBAC it comes up with several errors on the syntax of the XML file. When I have opened it up and had a look it has no resemblance what-so-ever to the XML layout in post one (the one in the userguide too).

I am trying to use this to generate a shaded map with contours and footpaths for use with the app I am developing using your excellent and enjoyable OSMDroid.
 

warwound

Expert
Licensed User
Longtime User
Where did you get your render theme xml from?
Did you take an existing render theme and attempt to modify it?

I'd guess the problem is the version of the render theme you're trying to use - it's probably trying to use newer render theme features and MOBAC supports only an older version of the render theme.

Have you read this page yet?
https://github.com/mapsforge/mapsforge/blob/master/docs/Rendertheme.md

It's probably a good starting point.
 

PCowling

Member
Licensed User
Longtime User
Morning

I took the render theme from the link in post #2.

Thanks for that, yes I have. I have now managed to get am XML schema that does not throw any errors, however I have not yet managed to get it to show in the top right hand side of MOBAC. Ill post it tonight when I get home.

Thank you again.
 

Laurent T

New Member
Licensed User
Longtime User
Hello,
Is it possible to change the orientation of the street names at the same time that we change the map orientation during travel? Currently, when the map rotates, the street name are upside down.
Thank you
 
Top