deivids11 / gwt-maps-api

Automatically exported from code.google.com/p/gwt-maps-api
0 stars 0 forks source link

Widgets added to InfoWindow loose handlers #3

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
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?

Original issue reported on code.google.com by googelyb...@gmail.com on 16 Mar 2012 at 6:10

GoogleCodeExporter commented 8 years ago
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);
    }
});

Original comment by z...@comerge.net on 30 Mar 2012 at 4:14

GoogleCodeExporter commented 8 years ago
i am facing similar problem

Original comment by niranjan...@gmail.com on 24 Jul 2014 at 1:24