MapPane SimpleMapMarker extension

23 views
Skip to first unread message

François Guillot

unread,
Nov 18, 2013, 3:52:06 AM11/18/13
to jfxtra...@googlegroups.com
Hi guys


I'm trying to extend the SimpleMapMarker class.

The SimpleMapMarker class displays a sphere at the specified Lat/Long.
It computes the x/y position of the sphere on the screen, so the sphere is at the right location, especially when the map is zoomed or moved.

I tried to implement the onMouseClicked on the sphere to display a "pop up menu" close to the sphere.
This works fine if the PopUp is a Java FX popup.
But then when the map is moved, the Pop up location is not recomputed (Normal !)

So I decided to extend the SimpleMapMarker to ExtendedSimpleMapMarker
When the sphere is clicked, the Node represented by the marker shall be (Sphere + Rectangle Pop up) instead of only sphere.

By looking at the code I changed to protected the visibility of
    @Override
    List<? extends Node> createChildren(Point position){
        sphere.setTranslateX(position.x - this.radius);
        sphere.setTranslateY(position.y - this.radius);
        return Collections.singletonList(sphere);
    }
so it can be overriden.
As far as I understand, when the map is rendered, it loops on all its mapLayers to render them.
Each mapLayer "createChildren" is called and returns the list of nodes that represent this mapLayer, translated to the new position.
Then, this list of nodes is added to the tiles to be rendered.
(By the way, I don't really understand HOW everything is rendered at the end.. If you could explain in more details)

So for my idea of extended marker, I extended

List<? extends Node> createChildren(Point position) in my ExtendedSimpleMapMarker
with a implementation like the folowing:
    @Override
    List<? extends Node> createChildren(Point position){
StackPane stack=new StackPane();
        sphere.setTranslateX(position.x - this.radius);
        sphere.setTranslateY(position.y - this.radius);
rectanglePopup
.setTranslateX(position.x)
        rectanglePopup.setTranslateY(position.y);        
stack.getChildren().add(sphere);
        stack.getChildren().add(rectanglePopup);
        return Collections.singletonList(stack);
    }


But that doesn't seem to work
only the rectanglePopup is displayed, and not only the combination of both (in the stack pane)

What am I missing ?
thanks

François Guillot

unread,
Nov 30, 2013, 12:31:28 PM11/30/13
to jfxtra...@googlegroups.com
Hi

I found a solution to my problem.
I modified the SimpleMapMarker class so that its inner Node is not the Sphere, but a Group, that contains [a sphere] or [a sphere + my custom pop up rectangle], depending on wether it was clicked or not.
This works fine, but I had to modify the SimpleMapMarker class to achieve this.
Reply all
Reply to author
Forward
0 new messages