简体   繁体   English

InfoWindow中的DataGrid不显示表数据

[英]DataGrid inside InfoWindow doesn't show table data

I'm using GWT along with the GoogleMaps GWT API ( v3.8 , and no, I can't use the branflakes GoogleMaps API). 我正在使用GWT和GoogleMaps GWT API( v3.8 ,不,我不能使用branflakes GoogleMaps API)。

I'm trying to put a DataGrid table inside an InfoWindow on the map. 我试图将DataGrid表放在地图上的InfoWindow内。 I have the DataGrid working fine as long as I display it outside the map, but whenever I add a DataGrid inside an InfoWindow, none of the table rows show up: 只要在地图外部显示DataGrid,我就可以正常工作,但是每当在InfoWindow中添加DataGrid时,都不会显示任何表行:

在此处输入图片说明

If I right-click the InfoWindow, go to "inspect element", then trudge through the million divs that GWT creates, I can see that the data is there- it's just not visible for some reason. 如果我右键单击InfoWindow,转到“检查元素”,然后在GWT创建的一百万个div中跋涉,我可以看到数据在那里-由于某种原因它是不可见的。

I've done quite a bit of googling, but all I've seen is that a DataGrid has to be a child of a LayoutPanel or ScrollPanel. 我已经做了大量的谷歌搜索工作,但是我所看到的只是DataGrid必须是LayoutPanel或ScrollPanel的子代。 But that's exactly what I'm doing: 但这正是我在做的:

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;
    }
}

Is there some step I'm missing? 我缺少一些步骤吗? How can I get a DataGrid to properly display inside an InfoWindow using the GoogleMaps API? 如何使用GoogleMaps API使DataGrid正确显示在InfoWindow中?

Edit: After not receiving any answers, I've crossposted this question to the GWT discussion board here . 编辑:没有收到任何答案之后,我crossposted就此问题向GWT讨论板这里

If anybody else comes across this problem, I ended up just using a CellTable instead: 如果有人遇到这个问题,我最终只是使用CellTable来代替:

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.CellTable;
import com.google.gwt.user.cellview.client.Column;
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
        CellTable 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);

        CellTable dg = createTable();


        InfoWindowOptions iwo = InfoWindowOptions.create();
        iwo.setPosition(LatLng.create(37.09024, -95.712891));
        iwo.setContent(dg.getElement());

        InfoWindow infoWindow = InfoWindow.create(iwo);
        infoWindow.open(map);

    }

    public CellTable createTable(){
        Column columnA = new Column(new TextCell()){

            @Override
            public Object getValue(Object object) {
                return "one";
            }

        };

        Column columnB = new Column(new TextCell()){

            @Override
            public Object getValue(Object object) {
                return "two";
            }

        };

        Column columnC = new Column(new TextCell()){

            @Override
            public Object getValue(Object object) {
                return "three";
            }

        };

        CellTable dataGrid = new CellTable();
        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;
    }
}

You need to use RootLayoutPanel in onModuleLoad instead of RootPanel. 您需要在onModuleLoad中使用RootLayoutPanel而不是RootPanel。 There need to be layout panels all the way from the root to the DataGrid. 从根到DataGrid一直需要布局面板。 InfoWindow doesn't seem to be a layout panel, so you might need to hook up the resizing yourself, see: InfoWindow似乎不是一个布局面板,因此您可能需要自己调整大小,请参见:

http://www.gwtproject.org/doc/latest/DevGuideUiPanels.html#Resize http://www.gwtproject.org/doc/latest/DevGuideUiPanels.html#Resize

Furthermore, you put the DataGrid inside a scrollpanel. 此外,将DataGrid放在滚动面板中。 You can do that but then you have to give it an explicit size. 您可以这样做,但随后必须给它一个明确的大小。 DataGrid has its own scrollpanel so you can probably also get rid of the explicitly created one. DataGrid有其自己的滚动面板,因此您也可以摆脱显式创建的滚动面板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM