B4J Question OSM Open Street Map for B4J?

warwound

Expert
Licensed User
Longtime User
I've looked at a few java map viewers over tha past 2 days.
Most are old swing libraries which I'm not sure if they can be used in b4j.
I found 1 javafx map viewer, but it has zero documentation or reference so would need some time to work out how to use it.

I hope to create a b4j map viewer before the new year.

martin.
 
Upvote 0

agraham

Expert
Licensed User
Longtime User
Martin. I don't know if you know, but the JFXtras library I used for jMsgboxes, jFXtrasControls and JFXtrasGauges has a MapPane object and what look like interfaces to Bing and OSM. These are all under jfxtras.labs.map. The javadoc is here in jfxtras-labs-2.2-r5-javadoc.jar

http://central.maven.org/maven2/org/jfxtras/jfxtras-labs/2.2-r5/

although it is pretty much devoid of comment, a problem I struggled with to understand the stuff that I have exposed.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
@agraham yes that's the one and only JavaFX map viewer that i have found.

There's the swing based OSM JMapViewer, but from what i have read it is no longer supported to add swing components to a JavaFX project.
Apparently the older versions of JavaFX had a SwingComponent Interface that could be implemented to convert a swing JComponent into a JavaFX component.
But with the current version of JavaFX that functionality has gone.

I've no experience of JavaFX or the JFXtras library but will do some research - as you said, documentation is rather non-existent :(.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
@Philip Prins and anyone else following this thread.

I have developed a rather basic but functional B4J MapPane library, it's based on the jfxtras 2.2 r5 source.

mappane_screengrab.png


With a choice of Cyclemap, Landcsape, Mapnik and Transport tile sources and support for Markers and Marker Click event tested and working.
No info-window that pops up on a Marker click, and the map drag only occurs when the drag ends not while dragging.
So not perfect but with a little more work it should become a useable library.

Demo project and (alpha) library files attached will be found in my next posts.

Please let me have any bug reports and suggestions.
There's plenty left to wrap into the library and i'll give priority to wrapping features that interested members suggest.

Martin.
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Out of interest, why didn't you just reference the jfxtras 2.2 r5 jar which a lot of people are going to have anyway?

That did cross my mind just after i posted - but i have actually modified just one class so really need the modified source.
I can probably extend the class that i have modified and then reference the external jfxtras 2.2 r5 library - i'll look at that later.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Here's an update, i've done as agraham suggested and referenced the external file jfxtras-labs-2.2-r5.jar instead of compiling the classes from that external file into the jFXtrasMapPane.jar file.

Attached are the original demo project and updated library files.
The library files consist of jFXtrasMapPane.jar, jFXtrasMapPane.xml, jCoreExtras,jar and jCoreExtras.xml.

jCoreExtras wraps some java.awt classes (Dimension and Point) that are required by some of the jFXtrasMapPane methods.
You do not need to check jCoreExtras in the b4j library list in order to use jFXtrasMapPane unless you are using Dimension and/or Point objects.

So jFXtrasMapPane currently depends on jfxtras-labs-2.2-r5.jar and jCoreExtras.jar.

Hope that all makes sense!

Martin.
 
Last edited:
Upvote 0

warwound

Expert
Licensed User
Longtime User
Here i have another update for you all.

The MapPane GetMapMarkerList method is now working and returns an array of MapMarkable objects.
More interesting though is support for custom tile servers and offline tiles.

I've created two demos - one to show use of a custom tile server and one to show use of offline local (file based) tiles.

The updated library files and both demo projects are attached.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
Another update, bug-fix and demo for you all.

This demo shows how to use the CustomTilePathBuilder to create paths to tiles which have a non standard format.
(The 'standard' format being OSM slippy map tile naming format).
There was a bug where the CustomTilePathBuilder didn't raise the 'BuildPath' event - that's fixed.

The library is slowly maturing and once i think it's bug free i shall start a new thread and 'properly' upload it.

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
And here's another update...

I've been thinking about how to display a balloon (infowindow) when a marker is clicked.
The big problem was that by referencing the MapPane source code in jfxtras-labs-2.2-r5.jar i couldn't get access to various classes and methods.

So with this update there is no longer a requirement to have jfxtras-labs-2.2-r5.jar in your additional libraries folder - it won't do any harm of course but is no longer a requirement.
The jFXtrasMapPane library contains modified versions of the original jfxtras classes and that has enabled me to create the MapNodeHost object:

MapNodeHost
Methods:

  • Initialize (Node1 As Node, Latitude As Double, Longitude As Double, OffsetX As Int, OffsetY As Int)
  • IsInitialized As Boolean
  • Render (MapControlable1 As MapControlable)
    Force the MapNodeHost to render itself.
    MapControlable1 - An instance of MapPane.
  • SetLat (Latitude As Double)
  • SetLon (Longitude As Double)
  • SetNode (Node1 As Node)
  • SetOffsetX (OffsetX As Int)
  • SetOffsetY (OffsetY As Int)
Properties:
  • Tag As Object

The MapNodeHost is used to anchor any Node to a geographical position on the map, the Node's position will be updated when the map is panned or zoomed.
In the attached demo i anchor a hidden Label to the map, when a marker is clicked the Label's position is updated to match the clicked marker, it's Text property is updated and it is made visible.
A click on the Label hides it.

So we have a very basic balloon/infowindow.

I did a quick test anchoring a WebView to the map and that worked as expected, i haven't tested other types of Nodes yet but they should all work.
So with a little imagination i think the MapHostNode can be used to create whatever style of balloon you want.
You could also use it to simply anchor Labels to the map with info related to a geographical position.

Other updates include a SetCursor method for both SimpleMapMarker and ImageMapMarker.

Updated library files and demo attached

Martin.
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
And yet another update...

The MapNodeHost anchors a Node to a geographical position - a latitude, longitude - and renders itself with a pixel offset for both X and Y relative to that geographical position.
With a zero offset for both X and Y the Node's top left corner will as default be anchored to the exact geographical position.
This update detects if this default position will leave the Node only partly visible - partly within the map bounds.
If the Node will not be wholly visible then it's position is adjusted so that it is wholly visible.

Take a look at the attached demo.
Pan the map so that a marker is close to either of the map's four corners and click the marker - the Node will always be positioned so that it is wholly visible.

Updated library files and demo attached.

Martin.
 
Upvote 0

warwound

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.
 

Attachments

  • jFXtrasMapPane_demo_20140113.zip
    1,018 bytes · Views: 599
  • jFXtrasMapPane_library_files_0_10.zip
    126 KB · Views: 627
Upvote 0

jandroid

New Member
Licensed User
Longtime User
Hello i think this lib is great.

So dont give up!

I have a question:

I got a database table with coordinates.

I want to loop thru some selected number of rows and plot the
coordinates on the map. And each (ploted)marker should be identified for a click event (and maybe a label).

Is this possible?

Do you have some sample or maybe some pointers.

Thanks
 
Upvote 0

warwound

Expert
Licensed User
Longtime User
@jandroid

I've just removed all the old demo projects from this thread as they'd no longer compile with the current version of the library.

Attached is a new demo that will compile with the current version of the library.
It shows how to add 'SimpleMapMarkers' and 'ImageMapMarkers' to the map and how to detect clicks on them.
It also shows how you can use the MapNodeHost to anchor a label to a clicked marker and display related info.

Martin.
 

Attachments

  • MapWithMarkers.zip
    6.6 KB · Views: 478
Upvote 0

jandroid

New Member
Licensed User
Longtime User
@jandroid

I've just removed all the old demo projects from this thread as they'd no longer compile with the current version of the library.

Attached is a new demo that will compile with the current version of the library.
It shows how to add 'SimpleMapMarkers' and 'ImageMapMarkers' to the map and how to detect clicks on them.
It also shows how you can use the MapNodeHost to anchor a label to a clicked marker and display related info.

Martin.

Thanks. Looks good.
 
Upvote 0
Top