Android Question OpenStreetMap using .PBF?

adrianstanescu85

Active Member
Licensed User
Longtime User
Hello,

I'd like to ask if there's a solution to use the maps from OpenStreetMap project using directly the .PBF files (offline) that are freely available for download.

For instance, http://download.geofabrik.de/europe.html has every country in Europe being updated daily in that vector format so using such a file would give an immense advantage over the OsmDroid tiles approach, which may be downloaded or generated but take up a huge amount of space and time.

I would also like to ask if using the alternative SHP or OSM formats is possible in a similar way, if PBF is not (which I would expect).

Any info over this please?

Thank you!
Adrian
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

warwound

Expert
Licensed User
Longtime User
Hi! Me again.

Can you please make it active again?

http://b4a.martinpearman.co.uk/osmdroid/MapsForgeTileSource.zip

Its no longer there. I pressume you already deleted it.

Thanks again.

Do you want MapsForgeTileSource for OSMDroid version 3.0.8 or the newer 4.1?

For version 3.0.8 you want to download: http://b4a.martinpearman.co.uk/osmdroid/MapsForgeTileSource 20140308.zip

And for version 4.1 download: http://b4a.martinpearman.co.uk/osmdroid/OSMDroid_4_1_MapsForgeTileSource-20140520.zip

You can browse that folder on my server to see exactly what is available: http://b4a.martinpearman.co.uk/osmdroid/
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
HI, GREETINGS, MARTIN
I CHECK YOUR MAPSFORGE EXAMPLE :
WHAT IS THE IDEA TO SavedMapStateFileName (map_state.dat)
IF NECESSARY TO 100 PERCENT, I SAY YOU BECAUSE NOT PUT THIS AND THE EXAMPLE STILL WORKS WELL

THANKS
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
HI, GREETINGS, MARTIN
I CHECK YOUR MAPSFORGE EXAMPLE :
WHAT IS THE IDEA TO SavedMapStateFileName (map_state.dat)
IF NECESSARY TO 100 PERCENT, I SAY YOU BECAUSE NOT PUT THIS AND THE EXAMPLE STILL WORKS WELL

THANKS

Hi.

It's just a way to save and restore the map state when the device orientation changes.
It's not required - it's just an optional extra.

Martin.
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
Greetings martin
i wanted to know if you could get an idea of where is this part (of white on my apk). I've reviewed several parts... where is the part of the code to change the area color white or color area white... ;)

...
the idea is display little transitions change when zooming in-out .
As i could do to see my apk zoom in-out transitions like a google maps
tks
mapa.gif
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Looks like you've already experimented with changing the map background color in the render theme xml file?
The very first line of the render theme xml looks like this:

B4X:
<rendertheme xsi:schemaLocation="http://mapsforge.org/renderTheme ../renderTheme.xsd" version="1" map-background="#f8f8f8">

Can you change that map-background value to 'sea blue'?
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
GREETINGS MARTIN
I WANTED TO KNOW
WHY THE LINES AND Markers remain static IN A PATHOVERLAY while the rest RESPONDS TO MAP ZOOM LEVEL ... THIS IS NORMAL AS OR could BE correct ... CURRENTLY I USE THE LIBRARY OSMdroid 3_0_8(VER 3.6)
ZOOM.png

THANKS
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
@PABLO2013

I'm not sure what the problem is.
Are the markers and path behaving properly but the tile data is 'drifting' - ie the tiles are not being drawn with enough accuracy.
Or is it as you think - the marker and path are not being drawn with enough accuracy so appear to drift?

Can you display the same markers and path using a different tile source and see if the problem lies with the markers and path or with the tile imagery?
 
Upvote 0

Laurent T

New Member
Licensed User
Longtime User
MapsForgeTileSource updated to version 1.10
Completely incomapatible with code written using the previous version but much more configurable:

OSMDroid_3_0_8_MapsForgeTileSource
Comment:
MapsForgeTileSource enables you to render a MapsForge map database file as a TileSource on an OSMDroid MapView.
Version: 1.10
  • MapDatabase
    Methods:
    • IsInitialized As Boolean
    Properties:
    • MapFileInfo As MapFileInfo [read only]
  • MapFileInfo
    Methods:
    • IsInitialized As Boolean
    Properties:
    • BoundingBox As BoundingBoxE6Wrapper [read only]
      Get the bounding box of the area covered by the map database file.
    • 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 "".
    • 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.
    • StartPosition As GeoPointWrapper [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 GeoPoint 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.
  • MapsForgeTileSource
    Methods:
    • GetMapsForgeTileSourceOptions As MapsForgeTileSourceOptions
      Gets the MapsForgeTileSourceOptions that will be used when the MapsForgeTileSource Initialize method is called.
    • Initialize
      Initialize the MapsForgeTileSource.
      You must have set any MapsForgeTileSourceOptions required options before calling Initialize.
    • IsInitialized As Boolean
    • SetTextScale (TextScale As Float)
      Sets the text scale.
      Default value is 1.
    Properties:
    • MapDatabase As MapDatabase [read only]
  • MapsForgeTileSourceOptions
    Methods:
    • SetDebugSettings (DrawTileCoordinates As Boolean, DrawTileFrames As Boolean, HighlightWaterTiles As Boolean) As MapsForgeTileSourceOptions
      Optionally set the DebugSettings.
      Default values are:
      DrawTileCoordinates - False.
      DrawTileFrames - False.
      HighlightWaterTiles - False.
    • SetMapDatabaseFile (Dir As String, FileName As String) As MapsForgeTileSourceOptions
      Set the path to the MapsForge map database file.
    • SetRenderTheme (InputStream1 As InputStream) As MapsForgeTileSourceOptions
      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 MapsForgeTileSourceOptions
      Optionally set the text scale.
      Default value is 1.
    • SetTileSourceName (TileSourceName As String) As MapsForgeTileSourceOptions
      Sets the name to use for this tilesource for example "England".
  • Tag
    Methods:
    • Equals (Tag1 As Tag) As Boolean
    • IsInitialized As Boolean
    Properties:
    • Key As String [read only]
    • Value As String [read only]

Library files and updated demo project available from:
http://b4a.martinpearman.co.uk/osmdroid/MapsForgeTileSource 20140308.zip

Martin.
Hi Martin,
Do you have a demonstration project with version 4.01 of OSMdroid?
Thanks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Do you have a demonstration project with version 4.01 of OSMdroid?

To be honest i'm not sure!
If you look at the directory listing here: http://b4a.martinpearman.co.uk/osmdroid/
You'll see some v4.1 examples but i'm not sure if they include a MapsForge example.
The MapsForge example in the listing is, i think, for the previous version 3.08.

If you try to get MapsForge working and have problems then start a new thread and upload your non-working code and i'll take a look.
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
cheers Martin,
wanted to know is possible at runtime choose different render files ..... i see every time zooms it make a new reading to the render file.... if i'm wrong
I do not know .. . there are new features for this library , tks

......tileRendererLayer.setXmlRenderTheme(new ExternalRenderTheme(File))
 
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
tks
i solve it , but wanted to know if this works from a button or a menu and if this library has available.


Dim InputStream1 As InputStream
InputStream1 = File.OpenInput( File.DirAssets, "osmarender.xml")
MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetRenderTheme(InputStream1)

tks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I've attached the OSMDroid MapsForge library for OSMDroid version 4.1.

Your code should work regardless of how it is called.
 

Attachments

  • OSMDroid_4_1_MapsForgeTileSource.zip
    173.5 KB · Views: 347
Upvote 0

PABLO2013

Well-Known Member
Licensed User
Longtime User
Hi i try update your sample to 4.1 mapsforge but i cant run it , the InputStream no work , sorry i cant put it in code block , can you some help, tks



CODE:
Sub Globals
Dim MapView1 As OSMDroid_MapView
Private Button1 As Button
Private Button2 As Button
Dim MapCenter As OSMDroid_GeoPoint
Dim MapsForgeTileSourceName As String="MapsForge1"
Dim MapsForgeDatabaseName As String="monaco.map"
Dim MapsForgeDatabasePath As String=File.DirRootExternal
Dim ZoomLevel As Int
End Sub

Sub Activity_Create(FirstTime As Boolean)

Activity.LoadLayout("RENDER")


If File.Exists(MapsForgeDatabasePath, MapsForgeDatabaseName)=False Then
File.Copy(File.DirAssets, MapsForgeDatabaseName, MapsForgeDatabasePath, MapsForgeDatabaseName)
End If

MapView1.Initialize("")

Dim CurrentTilesSources As List=MapView1.GetTileProvider.GetTileSource
If CurrentTilesSources.IndexOf(MapsForgeTileSourceName)=-1 Then
' the MapsForgeTileSource has not been added to the MapView so create it and add it to the map
'
''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Dim InputStream1 As InputStream
InputStream1 = File.OpenInput( File.DirAssets, "osmarender1.xml")
If InputStream1.IsInitialized Then Log("SI")
MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetRenderTheme(InputStream1)
MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetDebugSettings(True,True,True)
MapsForgeTileSource1.Initialize
MapView1.Invalidate
''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX


Dim MapsForgeTileSource1 As MapsForgeTileSource
' set the required MapsForgeTileSourceOptions MapDatabaseFile and TileSourceName
MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetMapDatabaseFile(MapsForgeDatabasePath, MapsForgeDatabaseName)
MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTileSourceName(MapsForgeTileSourceName)

' example of setting an optional MapsForgeTileSourceOptions
' MapsForgeTileSource1.GetMapsForgeTileSourceOptions.SetTextScale(2.0)

' now that the required MapsForgeTileSourceOptionshave been set we can call the MapsForgeTileSource Initialize method
MapsForgeTileSource1.Initialize
MapView1.SetTileSource(MapsForgeTileSource1)
End If


MapView1.Initialize("MapView1")
MapView1.SetBuiltInZoomControls(True)
MapView1.SetMultiTouchControls(True)

If File.Exists(File.DirInternal, SavedMapStateFileName) Then
' restore the saved map state
Dim RandomAccessFile1 As RandomAccessFile
RandomAccessFile1.Initialize(File.DirInternal, SavedMapStateFileName, True)
MapCenter=RandomAccessFile1.ReadObject(0)
ZoomLevel=RandomAccessFile1.ReadInt(RandomAccessFile1.CurrentPosition)
RandomAccessFile1.Close

MapView1.GetController.SetZoom(ZoomLevel)
MapView1.GetController.SetCenter(MapCenter)


Else
MapCenter=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartPosition
ZoomLevel=MapsForgeTileSource1.MapDatabase.MapFileInfo.StartZoomLevel
If MapCenter.IsInitialized And ZoomLevel<>-1 Then
' the map database has a start position and a start zoom set
' we'll use that for the default map state
MapView1.GetController.SetZoom(ZoomLevel)
MapView1.GetController.SetCenter(MapCenter)
Else
' the default map state will be defined by the area covered by the map database
'
''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MapView1.FitMapToBoundingBox(MapsForgeTileSource1.MapDatabase.MapFileInfo.BoundingBox)
''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
MapView1.GetBoundingBox2.BringToBoundingBox(MapsForgeTileSource1.MapDatabase.MapFileInfo.BoundingBox)



End If
End If


Activity.AddView(MapView1, 0, 0, 100%x, 90%y)
Activity.AddMenuItem("Clear saved state", "Menu")

MapView1.Invalidate


End Sub
 
Upvote 0
Top