【问题标题】:GWT map marker callout displayed blank when page first loaded首次加载页面时,GWT 地图标记标注显示为空白
【发布时间】:2013-12-21 10:59:38
【问题描述】:

我是gwt 的新手,我有一个带有gwt map 小部件和标记位置的页面。首次加载页面时,会显示标记标注,其中只有一个 X 表示错误。

当我关闭标注并重新打开它时,会显示正确的数据。

这是gwt代码:

LatLng location = new LatLng(39.565537, -79.426603);


// Init the map options
final MapOptions options = new MapOptions();
// Zoom level. Required
options.setZoom(12);
options.setCenter(location);
// Map type. Required.
options.setMapTypeId(new MapTypeId().getRoadmap());

// Enable maps drag feature. Disabled by default.
options.setDraggable(true);
// Enable and add default navigation control. Disabled by default.
options.setNavigationControl(true);
// Enable and add map type control. Disabled by default.
options.setMapTypeControl(true);

// Create map with options & set as control
final MapWidget retval = new MapWidget(options);

marker.setPosition(location);
marker.setMap(retval.getMap());

String html = "<br />Y Device location at " + loc.updateTime;
if (loc.dmTime != null) {
    html += "<br />Y Received at " + loc.dmTime;
}

infoWindow.setContent(html);
infoWindow.setPosition(location);

infoWindow.open(retval.getMap(), marker);

marker.setTitle("Whatever");

Event.addListener(marker, "click", new EventCallback() {
    @Override
    public void callback() {
        infoWindow.open(retval.getMap(), marker);
    }
});

return retval;

第一次加载页面时,我需要做什么才能使其正确显示?

【问题讨论】:

    标签: java gwt google-maps-api-3


    【解决方案1】:

    GoogleMap 对象完成渲染时运行MapWidget.open。要在 GoogleMap 对象完成时调用它,您需要使用 scheduleDeferredaddIdleListenerOnce, 可选,但最好在 onLoad 内部:

    GoogleMap retval;
    
    @Override
    protected void onLoad() {
        ...
        Scheduler.get().scheduleDeferred(new ScheduledCommand() {                
            @Override
            public void execute() {
                retval.addIdleListenerOnce(new IdleHandler() {
                    @Override
                    public void handle() {
                        infoWindow.setContent(html);
                        infoWindow.setPosition(location);
                        infoWindow.open(retval.getMap(), marker);
                    }
                });
            }
        });
    }
    

    【讨论】:

    【解决方案2】:

    retval 是您的 MapWidget 并在函数末尾返回,所以我认为您稍后会在代码中执行 setWidget。然后 infoWindow.open 在 MapWidget 显示之前完成... 也许你可以试试:

    Scheduler.get().scheduleDeferred(new ScheduledCommand() {                
       @Override
       public void execute() {
           infoWindow.open(retval.getMap(), marker);
       }
    });
    

    在地图显示后显示信息窗口。

    【讨论】:

      猜你喜欢
      • 2012-05-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-23
      • 2016-07-07
      • 2018-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多