B4J Question OSM Open Street Map for B4J?

ValDog

Active 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!

I run the demo OK, but when I use essentially the same code in my application (as a separate dialog) I also get this error - anyone have any ideas?
 
Upvote 0

ValDog

Active Member
Licensed User
Longtime User
Can you post the full error message?

Have you tried to run it in release mode?

Erel, thanks for responding. I found my problem. I was adding markers using locations from a database file and did not sequence the ImageMapMarker statements correctly.
 
Upvote 0

ivanomonti

Expert
Licensed User
Longtime User
Is anyone still using or interested in using the MapPane?
There's been very little feedback in this thread.
I was gonna upload the library to it's own thread - thinking it was ready for a proper release.
But i think the library is still only beta quality at best so i'll upload the latest update to this thread.

Bad news
This update will break existing apps!
That's mainly because the various MapPane Initialize methods now require an EventName parameter:
  • Initialize (EventName As String)
    Initialize the MapPane.
    The MapPane will have a size of 800x600 and display Mapnik tiles.
  • Initialize2 (EventName As String, TileSource1 As TileSource)
    Initialize the MapPane.
    The MapPane will have a size of 800x600 and display tiles from TileSource1.
  • Initialize3 (EventName As String, TileSource1 As TileSource, X As Int, Y As Int, Width As Int, Height As Int, Zoom As Int)
    Initialize the MapPane.
    The MapPane will have the defined size and display tiles from TileSource1.

Good news
The MapPane now raises various events which add considerably to it's capabilities:
  • MouseClicked (EventData As MouseEvent)
  • MouseDragged (EventData As MouseEvent)
  • MouseMoved (EventData As MouseEvent)
  • MousePressed (EventData As MouseEvent)
  • MouseReleased (EventData As MouseEvent)
  • Rendered
  • Resize (Width As Double, Height As Double)

The MapNodeHost now has a method SetAutoFix (AutoFix As Boolean) which determines whether the MapNodeHost will auto adjust it's position to keep itself wholly displayed on the map.

The SimpleMapMarker and ImageMapMarker MouseClicked event now also passes a MouseEvent to B4J (again this will break existing code):
  • MouseClicked (ImageMapMarker1 As ImageMapMarker, MouseEvent1 As MouseEvent)
  • MouseClicked (SimpleMapMarker1 As SimpleMapMarker, MouseEvent1 As MouseEvent)

The MapPane 'loading tile' image has also been updated and the MapPane now has methods SetErrorTile (ErrorTile As Image) and SetLoadingTile (LoadingTile As Image) to set the 'loading tile' image and also the 'tile failed to load' image.

That sums up the main changes, the library is now at version 0.09 and is attached with a demo project that shows how to turn a mouse click into a latitude, longitude Coordinate.
Also attached in an updated jCoreExtras.

All and any feedback welcomed!

Martin.

Hi,,,
You get the latitude and longitude with this library!
Thank 1000
 
Upvote 0

MichalK73

Well-Known Member
Licensed User
Longtime User
I have a problem with OSM for B4J.
When I do this code:
B4X:
Dim parser As JSONParser
parser.Initialize(res)
Dim m As Map=parser.NextObject
x=m.Get("x")
y=m.Get("y")
lista_sn.Items.Add(m.Get("nazwa"))
MapPane1.SetDisplayPositionByLatLon2(x, y,18)

Data x, y, name properly downloaded from the server B4J.
I have error:

B4X:
Program started.
Cannot get methods of class: uk.co.martinpearman.b4j.jfxtras.labs.map.MapPane, disabling cache.
java.lang.NoClassDefFoundError: uk/co/martinpearman/b4j/java/awt/Point
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.privateGetMethodRecursive(Class.java:3048)
    at java.lang.Class.getMethod0(Class.java:3018)
    at java.lang.Class.getMethod(Class.java:1784)
    at anywheresoftware.b4a.shell.Shell$MethodCache.getMethod(Shell.java:864)
    at anywheresoftware.b4a.shell.Shell.getMethod(Shell.java:524)
    at anywheresoftware.b4a.shell.Shell.runVoidMethod(Shell.java:653)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:232)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:159)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:93)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:442)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:516)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.ClassNotFoundException: uk.co.martinpearman.b4j.java.awt.Point
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 26 more
java.lang.RuntimeException: java.lang.RuntimeException: java.lang.NoClassDefFoundError: uk/co/martinpearman/b4j/java/awt/Point
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:471)
    at anywheresoftware.b4a.keywords.Common.access$0(Common.java:442)
    at anywheresoftware.b4a.keywords.Common$CallSubDelayedHelper.run(Common.java:516)
    at com.sun.javafx.application.PlatformImpl.lambda$null$173(PlatformImpl.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.application.PlatformImpl.lambda$runLater$174(PlatformImpl.java:294)
    at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$148(WinApplication.java:191)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.RuntimeException: java.lang.NoClassDefFoundError: uk/co/martinpearman/b4j/java/awt/Point
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:114)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:90)
    at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:462)

Any ideas?
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Hello,
How can i get the coordinates in Lat and Lon when some one clicks the mouse in the map, i don't mean on a marker but the point the user has clicked on in the map?

Regards,
Philip
 
Upvote 0

Philip Prins

Active Member
Licensed User
Longtime User
Found it;
B4X:
Sub MapPane1_MouseClicked(EventData As MouseEvent)
    Log(MapPane1.GetCoordinate(EventData.X,EventData.Y))
   
    Log(EventData)
End Sub
 
Upvote 0

Artigala

Member
Licensed User
Longtime User
Is anyone still using or interested in using the MapPane?
...
The MapNodeHost now has a method SetAutoFix (AutoFix As Boolean) which determines whether the MapNodeHost will auto adjust it's position to keep itself wholly displayed on the map.

The SimpleMapMarker and ImageMapMarker MouseClicked event now also passes a MouseEvent to B4J (again this will break existing code):
  • MouseClicked (ImageMapMarker1 As ImageMapMarker, MouseEvent1 As MouseEvent)
  • MouseClicked (SimpleMapMarker1 As SimpleMapMarker, MouseEvent1 As MouseEvent)
...

Martin.

Dear Martin,
When I try to use your example or create mine, the sub Mouseclicked (EventIcon_MouseClicked (ImageMapMarkerlocal As ImageMapMarker, MouseEvent1 As MouseEvent) ") works only with the right button, not with the left.
In addition, is it possible to add an EventName_MouseMoved (ImageMapMarkerlocal As ImageMapMarker, EventData As MouseEvent) method?
Thank you very much,
 
Upvote 0

Starchild

Active Member
Licensed User
Longtime User
Just downloaded the OSM library wrapper for JFxtras and demo. Post #14
Really amazing.
I have just gone down the road of evaluating using Google Maps JavaScript API (thru jGoogleMaps b4j lib) and after discussion with google I discovered the outrageous license costs.
Is the current version B4j library still (0.10)?
 
Last edited:
Upvote 0

Philip Prins

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.

Hello Martin,

With Mobile Atlas Creator what format should i choose to make the custom map?

Regards,
Philip
 
Upvote 0

javiers

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.

I would like to be able to execute your code to incorporate offline tiles, but I can not download the example in 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

With MOBAC, in what format should I create the offline map?

Thanks in advance!
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Upvote 0

javiers

Active Member
Licensed User
Longtime User
THANKS!!

Thank you. It works perfectly. However I thought that it allowed to see aerial images offline, but I see that the coordinates are not "real".
Is there any way to have tile source (aerial images) locally created with MOBAC?
OpenStreetMap does not have a hybrid mode ... and I would like to make an app with this control, not with GoogleMap (may be paid)
 
Upvote 0

js486dog

Active Member
Licensed User
Longtime User
THANKS!!

Thank you. It works perfectly. However I thought that it allowed to see aerial images offline, but I see that the coordinates are not "real".
Is there any way to have tile source (aerial images) locally created with MOBAC?
OpenStreetMap does not have a hybrid mode ... and I would like to make an app with this control, not with GoogleMap (may be paid)
Please is it possible to use zip map file format like in Osmdroid for B4A ? - I can use zip file in Osmdroid for B4A. I do not have to unzip it.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Never post to existing threads. Especially if it is a 7 years old thread.

You always should create a new thread for any question you have.
 
Last edited:
Upvote 0
Top