Google Map Widget - add a Listener

Hi all,

first of let me say how much I love Vaadin - I’ve been using it for a couple of months and love how quick, flexible and easy it makes development.

My question is a simple one -

Using the googlemap widget is there a way to add a listener and retrieve the clicked marker?

I’ve looked throught the source and can’t see that functionality implemented.

just want to check before I spend time adding it in (If I actually can!):lol:

thanks in advance…

Patrick

Hi Patrick,

The current implementation autowires marker clicks to open info windows. The browser widget captures the click events and sends a variable “marker” with the value of clicked marker’s id to the server, and GoogleMap.changeVariables() then handles the info window stuff.

It’s quite easy to modify the server side component to just yield the marker instead of opening the info window. In GoogleMap.java line 272 or so it says

if (variables.containsKey("marker")) {
    clickedMarker = markerSource.getMarker(variables.get("marker").toString());
    if (clickedMarker != null && clickedMarker.getInfoWindowContent() != null) {
        requestRepaint();
    }
}

replace that with something like

if (variables.containsKey("marker")) {
    Marker marker = markerSource.getMarker(variables.get("marker").toString());
    // TODO Do something with marker
}

Note that you should not set the clickedMarker field, because if it’s set the component will open info window on next repaint.

edit: minor typo fix.

Thanks for the solution Henri - clear ,enlightening and very quick,

I’ll give it a go.

many thanks again.

regards,

Patrick.