Google Maps API v3 - Buttons and TextBoxes inside InfoWindow?

前端 未结 2 687
闹比i
闹比i 2021-01-07 04:10

I\'m using the new maps v3 API from gwt-google-apis.

Is it possible to capture events from GWT widgets that are inside InfoWindow? Am I missing something?

Tr

2条回答
  •  我在风中等你
    2021-01-07 04:39

    I had to build a wrapper over InfoWindow to make it work.

    public class NXInfoWindow {
    
        static class FakePanel extends ComplexPanel {
            public FakePanel(Widget w) {
                w.removeFromParent();
                getChildren().add(w);
                adopt(w);
            }
    
            @Override
            public boolean isAttached() {
                return true;
            }
    
            public void detachWidget() {
                this.remove(0);
            }
        }
    
        private InfoWindow info;
    
        private IsWidget widgetContent = null;
    
        private Long id;
    
        FakePanel widgetAttacher;
    
        public static NXInfoWindow create(Long id){
            NXInfoWindow myInfo = new NXInfoWindow();
            myInfo.info = InfoWindow.create(); 
            myInfo.id = id;
            return myInfo;
        };
    
        private void detachWidget() {
            if (this.widgetAttacher != null) {
                this.widgetAttacher.detachWidget();
                this.widgetAttacher = null;
            }
        }
    
        public void close() {
            info.close();
            detachWidget();
        }
    
        public void setPosition(LatLng posicao) {
            info.setPosition(posicao);
        }
    
        public void open(GoogleMap map) {
            info.open(map);
        }
    
        public void setContent(Widget value) {
            this.widgetContent = value;
            info.setContent(value.getElement());
    
            if (this.widgetAttacher == null) {
                addListener(info, "closeclick", new Runnable() {
                    @Override
                    public void run() {
                        detachWidget();
                    }
                });
                this.widgetAttacher = new FakePanel(value);
            } else if (this.widgetAttacher.getWidget(0) != value) {
                this.widgetAttacher.detachWidget();
                this.widgetAttacher = new FakePanel(value);
            }
        }
    
        private void setContent(Element element) {
            this.setContent(element);
        }
    
        public IsWidget getContentWidget() {
            return widgetContent;
        }
    
        public final native void addListener(JavaScriptObject jso, String whichEvent, Runnable handler)
        /*-{
            var that = jso;
            $wnd.google.maps.event.addListener(jso, whichEvent, function() {
              handler.@java.lang.Runnable::run()();
            });
          }-*/;
    }
    

提交回复
热议问题