Google Maps API v3 - InfoWindow内的按钮和文本框? [英] Google Maps API v3 - Buttons and TextBoxes inside InfoWindow?
本文介绍了Google Maps API v3 - InfoWindow内的按钮和文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用 gwt-google-apis 。
是否有可能从GWT捕捉事件InfoWindow内部的小部件?我错过了什么?
以上试过的代码(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(){
$ b @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);
}
}) ;
$ b $ final HTMLPanel html = new HTMLPanel((< div id ='button'>< / div>));
html.add(button,button );
info.setContent(html.getElement());
info.setPosition(posicao);
info.open(map);
}
});
谢谢。
解决方案我必须在InfoWindow上构建一个包装器才能使其工作。
public class NXInfoWindow {
静态类FakePanel扩展ComplexPanel {
public FakePanel(Widget w){
w.removeFromParent();
getChildren()。add(w);
采用(w);
}
@Override
public boolean isAttached(){
return true;
}
public void detachWidget(){
this.remove(0);
}
}
私人InfoWindow信息;
private IsWidget widgetContent = null;
私人长ID;
FakePanel widgetAttacher;
public static NXInfoWindow create(Long id){
NXInfoWindow myInfo = new NXInfoWindow();
myInfo.info = InfoWindow.create();
myInfo.id = id;
返回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 void addListener(JavaScriptObject jso,String whichEvent,Runnable处理程序)
/ * - {
var that = jso;
$ wnd.google.maps.event.addListener(jso,whichEvent,function(){
handler。@ java.lang.Runnable :: run()();
});
} - * /;
}
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?
Tried code above (button.addClickHandler) and it doesn't show the alert:
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);
}
});
Thanks.
解决方案
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()();
});
}-*/;
}
这篇关于Google Maps API v3 - InfoWindow内的按钮和文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文