【发布时间】:2023-04-07 17:10:01
【问题描述】:
我正在使用 GWT 和 GoogleMaps GWT API(v3.8,不,我不能使用 branflakes GoogleMaps API)。
我正在尝试将 DataGrid 表放在地图上的 InfoWindow 中。只要将 DataGrid 显示在地图外,我就可以正常工作,但是每当我在 InfoWindow 中添加 DataGrid 时,都不会显示任何表格行:
如果我右键单击信息窗口,转到“检查元素”,然后在 GWT 创建的数百万个 div 中跋涉,我可以看到数据就在那里——只是由于某种原因它不可见。
我已经做了很多谷歌搜索,但我所看到的只是 DataGrid 必须是 LayoutPanel 或 ScrollPanel 的子级。但这正是我正在做的事情:
package com.test.client;
import java.util.Arrays;
import com.google.gwt.ajaxloader.client.AjaxLoader;
import com.google.gwt.ajaxloader.client.AjaxLoader.AjaxLoaderOptions;
import com.google.gwt.cell.client.TextCell;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.dom.client.Document;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.DataGrid;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.maps.gwt.client.GoogleMap;
import com.google.maps.gwt.client.InfoWindow;
import com.google.maps.gwt.client.InfoWindowOptions;
import com.google.maps.gwt.client.LatLng;
import com.google.maps.gwt.client.MapOptions;
import com.google.maps.gwt.client.MapTypeId;
public class GwtTest implements EntryPoint {
@Override
public void onModuleLoad() {
AjaxLoaderOptions options = AjaxLoaderOptions.newInstance();
options.setOtherParms("sensor=false");
Runnable callback = new Runnable() {
public void run() {
createMap();
}
};
AjaxLoader.loadApi("maps", "3", callback, options);
//this works
DataGrid dg = createTable();
RootPanel.get("tableDiv").add(new ScrollPanel(dg));
}
public void createMap() {
MapOptions mapOpts = MapOptions.create();
mapOpts.setZoom(4);
mapOpts.setCenter(LatLng.create(37.09024, -95.712891));
mapOpts.setMapTypeId(MapTypeId.TERRAIN);
mapOpts.setStreetViewControl(false);
GoogleMap map = GoogleMap.create(Document.get().getElementById("map_canvas"), mapOpts);
DataGrid dg = createTable();
InfoWindowOptions iwo = InfoWindowOptions.create();
iwo.setPosition(LatLng.create(37.09024, -95.712891));
iwo.setContent(new ScrollPanel(dg).getElement());
InfoWindow infoWindow = InfoWindow.create(iwo);
infoWindow.open(map);
}
public DataGrid createTable(){
Column columnA = new Column(new TextCell()){
public Object getValue(Object object) {
return "one";
}
};
Column columnB = new Column(new TextCell()){
public Object getValue(Object object) {
return "two";
}
};
Column columnC = new Column(new TextCell()){
public Object getValue(Object object) {
return "three";
}
};
DataGrid dataGrid = new DataGrid();
dataGrid.addColumn(columnA, "A");
dataGrid.addColumn(columnB, "B");
dataGrid.addColumn(columnC, "C");
dataGrid.setRowCount(1);
dataGrid.setRowData(Arrays.asList("one", "two", "three"));
dataGrid.setWidth("200px");
dataGrid.setHeight("100px");
return dataGrid;
}
}
我是否缺少某些步骤?如何使用 GoogleMaps API 让 DataGrid 正确显示在 InfoWindow 中?
编辑:在没有收到任何答案后,我已将此问题交叉发布到 GWT 讨论板 here。
【问题讨论】:
-
以不同方式格式化您的信息窗口会改变什么吗?
-
@Andy 感谢您的回复。以不同方式格式化我的 InfoWindow 到底是什么意思?
-
对不起,我的意思是把内容设置成别的东西,也许用 html 定义。虽然我猜如果你需要它作为一个可滚动的,它可能是没有意义的。
-
@Andy 我不需要它作为可滚动的。但我尝试将表格添加到其他组件,并将这些组件添加到 InfoWindow,但一切似乎都具有相同的效果。
-
@TonyKennah 我非常肯定。
标签: java google-maps gwt datagrid infowindow