gpt4 book ai didi

gwt - Google Maps API v3 - InfoWindow 内的按钮和文本框?

转载 作者:行者123 更新时间:2023-12-04 05:38:59 24 4
gpt4 key购买 nike

我正在使用来自 gwt-google-apis 的新 map v3 API .

是否可以从 InfoWindow 内的 GWT 小部件捕获事件?我错过了什么吗?

尝试了上面的代码(button.addClickHandler),但没有显示警报:

    Marker m = Marker.create();
m.setIcon(MarkerImage.create(icone));
m.setPosition(LatLng.create(posicao.lat(), posicao.lng()));
m.setMap(map);

m.addClickHandler(new ClickHandler() {

@Override
public void handle(MouseEvent event) {

InfoWindow info = InfoWindow.create();

Button button = new Button("Desativar");
button.addClickHandler(new com.google.gwt.event.dom.client.ClickHandler() {

@Override
public void onClick(ClickEvent event) {
Window.alert("click");

}
});

final HTMLPanel html = new HTMLPanel(("<div id='button'></div>"));
html.add(button, "button");

info.setContent(html.getElement());
info.setPosition(posicao);
info.open(map);

}
});

谢谢。

最佳答案

问题是小部件之间的层次结构损坏,通常的方法是通过附加/分离小部件。您可以通过设置小部件的元素来实现。这也是 Google Maps API 的问题。

这可以通过使用假面板来解决,这将是 InfoWindow 的一部分。 ,所以当你做 setContent(Widget widget)假面板将被更新,并且小部件的元素将被设置为内容(如前所述)。

请看一下这个类:

public class MyInfoWindow extends InfoWindow {

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 IsWidget widgetContent = null;

FakePanel widgetAttacher;

public MyInfoWindow() {
super(InfoWindowImpl.impl.construct());
}

private void detachWidget() {
if (this.widgetAttacher != null) {
this.widgetAttacher.detachWidget();
this.widgetAttacher = null;
}
}

public void close() {
super.close();
detachWidget();
}

public void setContent(String content) {
this.widgetContent = null;
this.detachWidget();
super.setContent(content);
}

/** */
public void setContent(Widget value) {
this.widgetContent = value;
setContent(value.getElement());

if (this.widgetAttacher == null) {
addListener(getJso(), "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) {
InfoWindowImpl.impl.setContent(getJso(), 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()();
});
}-*/;

}

关于gwt - Google Maps API v3 - InfoWindow 内的按钮和文本框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11528637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com