B4J Question OSM Open Street Map for B4J?

ramesh raj

New Member
Licensed User
Longtime User
Running the MapWithMarkers demo resulted in the error:
Cannot get methods of class: uk.co.martinpearman.b4j.jfxtras.labs.map.MapPane, disabling cache.
What could I be doing wrong?
And when would the next tranche of examples follow? - like those for android!
 
Upvote 0

scrat

Active Member
Licensed User
Longtime User
Thank Martin for this library.

I try to draw a polyline with this code
B4X:
Dim ml As DefaultMapLine
Dim lc As List
lc.Initialize
Dim C0,C1 As Coordinate
C0.Initialize(46.0,2.0)
C1.Initialize(46.0,3.0)
lc.Add(C0)
lc.Add(C1)
ml.Initialize(lc)

but I get this error:
B4X:
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.List cannot be cast to java.util.List

in B4J a list is not a java list?

Any idea

Thank you
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
I have this bug report 'logged' in my mind and plan to take a look when i get a chance...

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Thank Martin for this library.

I try to draw a polyline with this code
B4X:
Dim ml As DefaultMapLine
Dim lc As List
lc.Initialize
Dim C0,C1 As Coordinate
C0.Initialize(46.0,2.0)
C1.Initialize(46.0,3.0)
lc.Add(C0)
lc.Add(C1)
ml.Initialize(lc)

but I get this error:
B4X:
java.lang.ClassCastException: anywheresoftware.b4a.objects.collections.List cannot be cast to java.util.List

in B4J a list is not a java list?

Any idea

Thank you

Can you download version 0.10 of the library and try again?
http://www.b4x.com/android/forum/threads/osm-open-street-map-for-b4j.35554/#post-215716
I've updated the DefaultMapLine Initialize methods - that should be the bug fixed.

Martin.
 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
Very useful library Martin!
I was wondering if it is possible to show our own tiles (slippy tiles)
that exists in the directory structure (zoom/x/y.png) on a local disk
Thanks for the library.
George
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
@gvoulg

Yes that's possible.
Here's a snippet that contains everything you need:
B4X:
Sub Process_Globals
	Private fx As JFX
	Private MainForm As Form
	Private MapPane1 As MapPane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
	MainForm = Form1
	MainForm.Title="jFXtrasMapPane demo"
	
	'	the offline tiles used in this example can be downloaded from
	'	http://b4j.martinpearman.co.uk/jfxtras.labs.map/tiles/map_of_the_uk.zip
	'	be sure to modify the path to the offline tiles in CustomTileSource1.Initialize2
	
	Dim CustomTileSource1 As CustomTileSource
	CustomTileSource1.Initialize2("Panorama", "C:\Users\martin\Programming\Basic4Java\jFXtrasMapPane\CustomTileSource-demo\map_of_the_uk", 0, 3)
	
	'	the offline custom tiles are JPG images
	'	so i'll use a CustomTilePathBuilder so jpg tiles are requested
	'	(by default png tile are requested)
	Dim CustomTilePathBuilder1 As CustomTilePathBuilder
	CustomTilePathBuilder1.Initialize
	CustomTilePathBuilder1.SetTileType("jpg")
	
	CustomTileSource1.SetTilePathBuilder(CustomTilePathBuilder1)
	
	MapPane1.Initialize3("", CustomTileSource1, 0, 0, 640, 480, 0)
	MapPane1.SetDisplayPositionByLatLon(0, 0)
	
	MainForm.RootPane.AddNode(MapPane1, 0, 0, 640, 480)
	
	MainForm.Show
End Sub

Martin.
 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
Hi Martin
I have an application with two MapPanes.
One with OsmTiles and an other one on top of it with custom tiles based on my disk
like you show me in your example.
My question is how can I synchronize the pan and zoom between the two panes so the center of the map (and zoom) be the
same ? The MapPAne on foreground receives the mouse events but the backround pane does not.
I Have set the .setShowZoomControls to false for the backround pane (and this is the one with the osmTiles).

Best Regards
George

PS
Found a solution (not very elegant ..)
Inside the MapPane1_MouseReleased event of the primary Mappane1 I wrote
B4X:
''check zoom and center to apply to map pane 1
     Dim zoomscale As Int
     Dim cenPoint As Coordinate
     cenPoint=MapPane1.GetCenterCoordinate
     zoomscale=MapPane1.GetZoom
     MapPane2.SetDisplayPositionByLatLon2(cenPoint.GetLatitude,cenPoint.GetLongitude,zoomscale)
But if I use the zoom controls I must press on screen to adjust things
Maybe I should create my own buttons for zoomin zoomout to have full control.
 
Last edited:
Upvote 0

gvoulg

Member
Licensed User
Longtime User
You can use the MapPane_Rendered event.

Yes
That's the way to go.
This way we can deal with zoom in-out using mouse wheel too.
B4X:
Sub MapPane2_Rendered
     Dim zoomscale As Int
     Dim cenPoint As Coordinate
     cenPoint=MapPane2.GetCenterCoordinate
     zoomscale=MapPane2.GetZoom
     MapPane1.SetDisplayPositionByLatLon2(cenPoint.GetLatitude,cenPoint.GetLongitude,zoomscale)
        
End Sub
 
Upvote 0

gvoulg

Member
Licensed User
Longtime User
I made a little program based on all the above.
The program creates an mbtile format file from separate tiles
located in directories with the known format (zoom/x/y.png) on local disk
We can see the tiles over osm map and select the area of interest ,zoom levels and destinaton file name of type mbtiles.
You will need to have these tile structure on your computer or a server
However I would like to ask for something .
I haven't managed to create a progress bar .Not good enough with Threading library :(
All additions welcome ;)
George
PS
egsa87 library translates points between WGS84 and ggrs87 (Greek Datum)
and is not necessary for outside Greece users
I use it to zoom on a point on map using local system coordinates
 

Attachments

  • egsa87.zip
    5.2 KB · Views: 429
  • mbtiler.zip
    12.1 KB · Views: 441
Last edited:
Upvote 0

Spinter

Active Member
Licensed User
Longtime User
@gvoulg

Yes that's possible.
Here's a snippet that contains everything you need:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private MapPane1 As MapPane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Title="jFXtrasMapPane demo"
   
    '    the offline tiles used in this example can be downloaded from
    '    http://b4j.martinpearman.co.uk/jfxtras.labs.map/tiles/map_of_the_uk.zip
    '    be sure to modify the path to the offline tiles in CustomTileSource1.Initialize2
   
    Dim CustomTileSource1 As CustomTileSource
    CustomTileSource1.Initialize2("Panorama", "C:\Users\martin\Programming\Basic4Java\jFXtrasMapPane\CustomTileSource-demo\map_of_the_uk", 0, 3)
   
    '    the offline custom tiles are JPG images
    '    so i'll use a CustomTilePathBuilder so jpg tiles are requested
    '    (by default png tile are requested)
    Dim CustomTilePathBuilder1 As CustomTilePathBuilder
    CustomTilePathBuilder1.Initialize
    CustomTilePathBuilder1.SetTileType("jpg")
   
    CustomTileSource1.SetTilePathBuilder(CustomTilePathBuilder1)
   
    MapPane1.Initialize3("", CustomTileSource1, 0, 0, 640, 480, 0)
    MapPane1.SetDisplayPositionByLatLon(0, 0)
   
    MainForm.RootPane.AddNode(MapPane1, 0, 0, 640, 480)
   
    MainForm.Show
End Sub

Martin.

is possible .map file?
 
Upvote 0

scrat

Active Member
Licensed User
Longtime User
Since the rewrite branch (0.4+) mapsforge is less dependent on android.
There is a wrapper for AWT (see swingmapviewer example).
Unfortunately there is no wrapper for JavaFX.
My knowledge of Java / JavaFX are not sufficient to determine whether it is possible to create this wrapper.
If Martin be bored during the long winter evenings .....:)
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
If Martin be bored during the long winter evenings .....

That's a possibility - i've thought before about creating a b4j library based on the new MapsForge library.
It'd be a lot of pretty boring work to begin with as there's just so many objects to wrap.
Let's say it's on the back burner.

Martin.
 
Upvote 0

scrat

Active Member
Licensed User
Longtime User
Let's say it's on the back burner.

Yes, that's a lot of work and mapsforge is constantly changing.
Using java library in B4A / B4j would be a better approach and a big enhancement but definitely a lot of work to Erel.
 
Upvote 0

Magma

Expert
Licensed User
Longtime User
@gvoulg

Yes that's possible.
Here's a snippet that contains everything you need:
B4X:
Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private MapPane1 As MapPane
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.Title="jFXtrasMapPane demo"
   
    '    the offline tiles used in this example can be downloaded from
    '    http://b4j.martinpearman.co.uk/jfxtras.labs.map/tiles/map_of_the_uk.zip
    '    be sure to modify the path to the offline tiles in CustomTileSource1.Initialize2
   
    Dim CustomTileSource1 As CustomTileSource
    CustomTileSource1.Initialize2("Panorama", "C:\Users\martin\Programming\Basic4Java\jFXtrasMapPane\CustomTileSource-demo\map_of_the_uk", 0, 3)
   
    '    the offline custom tiles are JPG images
    '    so i'll use a CustomTilePathBuilder so jpg tiles are requested
    '    (by default png tile are requested)
    Dim CustomTilePathBuilder1 As CustomTilePathBuilder
    CustomTilePathBuilder1.Initialize
    CustomTilePathBuilder1.SetTileType("jpg")
   
    CustomTileSource1.SetTilePathBuilder(CustomTilePathBuilder1)
   
    MapPane1.Initialize3("", CustomTileSource1, 0, 0, 640, 480, 0)
    MapPane1.SetDisplayPositionByLatLon(0, 0)
   
    MainForm.RootPane.AddNode(MapPane1, 0, 0, 640, 480)
   
    MainForm.Show
End Sub

Martin.

Hi there - ok this works... but somehow i remember that in android osmdroid.. when no tiles offline ... trying to get from internet... is that possible in b4j ?
 
Upvote 0
Top