I am investigating gwt libraries for Maps V3 and found the following bug which sadly makes it impossible to use your library.
What steps will reproduce the problem?
InfoWindowOptions options = InfoWindowOptions.newInstance();
Button button = new Button("click me");
button.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
Window.alert("Hello Maps");
}
});
options.setContent(button);
InfoWindow iw = InfoWindow.newInstance(options);
iw.open(mapWidget, marker);
What is the expected output? What do you see instead?
* Expected: The clickhandler on the button is fired, I get an alert dialog
* IS: Nothing happens when I click on the button
What version of the product are you using? On what operating system?
gwt 2.4
Please provide any additional information below.
All handlers on the widgets added to an InfoWindow are lost. This is because InfoWindowOptions.setContent(Widget) implementation: setContent(widget.getElement());
I think the Maps V2 library does some extra work here to preserve the handlers, as there it works.
Is there a workaround for this to add a link / button to the InfoWindow?
Workaround (similar done in v2): Use a 'virtual' panel to attach the content of the InfoWindow and register a close handler to detach the widget when its not needed anymore. ... private final VirtualPanel fVirtualPanel = new VirtualPanel(); private static class VirtualPanel extends ComplexPanel { public void attach(Widget w) { w.removeFromParent(); getChildren().add(w); adopt(w); } @Override public boolean isAttached() { return true; } } ... fVirtualPanel.attach(fInfoWindowContent); ... fInfoWindow.addCloseClickHandler(new CloseClickMapHandler() { @Override public void onEvent(CloseClickMapEvent event) { fVirtualPanel.remove(fInfoWindowContent); } });