The second call to Google maps does not display the map in the correct size

using gwt-maps-3.8.0 I display the route in a gwt popup. It works on a call once, but does not work on a second call.

What should I do ... some tips for updating mapWidget? defect map

+3
source share
3 answers

When you show the map, fire its resize event.

From the documentation:

Developers should fire this event on the map when the div google.maps.event.trigger(map, 'resize') : google.maps.event.trigger(map, 'resize')

There will be a way to do this in GWT

 Event.trigger(mapWidget.getMap(), "resize"); 

The map is currently zero in size, as far as the API is concerned, so it just displays the fragment buffer around a single pixel at (0,0). resize event causes the API to get the correct size from the browser in order to display the necessary fragments for display.

+5
source

I had the same problem (the map appears in the popup, reload the popup, and the map no longer centers).
In the end, I managed to fix my problem using the triggerResize method from the GoogleMap class. However, it only worked after I called this method from the Idle event.
triggerResize will notify the map to display the correct tiles.
setCenter will verify that the card is centered again.

 gMap.addIdleListenerOnce(new IdleHandler() { @Override public void handle() { gMap.triggerResize(); gMap.setCenter(myLatLng); } }); 
+2
source

Using the GWT-V3-Maps-API , this will be done as follows for the case when the size of the div or window changes:

  /* * Example of how to dynamically resize the map to fit the window - add * your events */ Window.addResizeHandler(new ResizeHandler() { @Override public void onResize(ResizeEvent event) { MapHandlerRegistration.trigger(mapWidget, MapEventType.RESIZE); GWT.log("Window has been resized!"); } }); mapWidget.addResizeHandler(new ResizeMapHandler() { @Override public void onEvent(ResizeMapEvent event) { GWT.log("Map has been resized!"); } }); 
+1
source

Source: https://habr.com/ru/post/1345497/


All Articles