GWT谷歌地图Api V3-更改时出现故障

GWT谷歌地图Api V3-更改时出现故障,gwt,google-maps-api-3,gwt-2.5,Gwt,Google Maps Api 3,Gwt 2.5,第一次渲染它对我来说效果很好。 但是,如果我在地图上更改或重新创建任何内容,它将被破坏 下面是它的屏幕截图。 这是我更改每页结果值后的屏幕截图。 这是我的密码 @UiField DivElement mapPanel; private GoogleMap googleMap; public void loadAllMarkers(final List<LatLng> markers) { if(!markers.isEmpty()) { fin

第一次渲染它对我来说效果很好。 但是,如果我在地图上更改或重新创建任何内容,它将被破坏

下面是它的屏幕截图。

这是我更改每页结果值后的屏幕截图。

这是我的密码

@UiField DivElement mapPanel;

private GoogleMap googleMap;

public void loadAllMarkers(final List<LatLng> markers)
{
    if(!markers.isEmpty())
    {
        final MapOptions options = MapOptions.create();
        options.setMapTypeId(MapTypeId.ROADMAP);

        googleMap = GoogleMap.create(mapPanel, options);

        final LatLngBounds latLngBounds = LatLngBounds.create();

        for(LatLng latLng : markers)
        {
        final MarkerOptions markerOptions = MarkerOptions.create();

        markerOptions.setPosition(latLng);
        markerOptions.setMap(googleMap);

        final Marker marker = Marker.create(markerOptions);
        latLngBounds.extend(marker.getPosition());

        }

        googleMap.setCenter(latLngBounds.getCenter());
        googleMap.fitBounds(latLngBounds);

    }
}
@UiField-DivElement映射面板;
私人谷歌地图谷歌地图;
公共void loadAllMarkers(最终列表标记)
{
如果(!markers.isEmpty())
{
final MapOptions=MapOptions.create();
options.setMapTypeId(MapTypeId.ROADMAP);
googleMap=googleMap.create(地图面板,选项);
final LatLngBounds LatLngBounds=LatLngBounds.create();
用于(板条板条:标记)
{
final MarkerOptions MarkerOptions=MarkerOptions.create();
标记选项。设置位置(车床);
markerOptions.setMap(谷歌地图);
最终标记=Marker.create(markerOptions);
extend(marker.getPosition());
}
setCenter(latLngBounds.getCenter());
googleMap.fitBounds(latLngBounds);
}
}
每当需要加载新结果时,我都调用loadAllMarkers()方法


有人能指出我在这里做错了什么吗。

这似乎来自以下几点(我从Google+社区中找到的):

Brandon DonnelsonMar 5号,2013年

我已经忘记了为什么会这样,但是 triggerResize()将重置平铺。这似乎发生了 当onAttach发生且动画存在时,表示div 开始时较小,在侧面增加,但地图已经 附属的。动画结束时,贴图不会自动调整大小。 我一直想调查自动调整大小,但我没有时间 攻击它吧

在您的情况下,您可以在完成更改后调用googleMap.triggerResize()。这解决了我的问题,当我有完全相同的问题。我知道有点晚了,但我希望能有帮助

另一个答案是使用以下内容扩展Map小部件:

   @Override
protected void onAttach() {
    super.onAttach();
    Timer timer = new Timer() {

        @Override
        public void run() {
            resize();
        }
    };
    timer.schedule(5);
}

/*
 * This method is called to fix the Map loading issue when opening
 * multiple instances of maps in different tabs
 * Triggers a resize event to be consumed by google api in order to resize view
 * after attach.
 *
 */
public void resize() {
    LatLng center = this.getCenter();
    MapHandlerRegistration.trigger(this, MapEventType.RESIZE);        
    this.setCenter(center);
}