GWT Google Map Api V3 – 更改时损坏

第一次呈现它对我来说很好.

但是,如果我在地图上更改任何内容或重新创建它,它就会破碎.

这是它的外观屏幕截图.
 

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

这是我的代码.

@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);

    }
}

每当需要加载新结果时,我都会调用loadAllMarkers()方法.

有人可以指出我在这里做错了什么.

最佳答案 这似乎来自以下(我从Google社区 –
GWT Maps V3 API中提取):

Brandon DonnelsonMar 5, 2013

I’ve had this happen and forgotten why it is, but
mapwidget.triggerResize() will reset the tiles. This seems to happen
when the onAttach occurs and animation exists meaning that the div
started smaller and increases in side, but the map has already
attached. At the end of the animation, the map doesn’t auto resize.
I’v been meaning to investigate auto resize but I haven’t had time to
attack it yet.

在您的情况下,您将在完成更改后调用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);
}
点赞