AlejandroVK
AlejandroVK

Reputation: 7605

How to trigger map event on Google Maps < v3

I'm having an issue with an app that loads several google maps. Second of this maps has the famous issue of not displaying well because it seems the div dimensions are not found correctly. I've checked the proposed solutions here and here. None of the proposed solutions work for me because I cannot switch to v3 right now, I'll do some time later on, but can't do it right now.

Thus, how can I trigger the resize event on google maps API < v3? I've tried this already:

HasLatLng center = mapWidget.getMap().getCenter();
Event.trigger(mapWidget.getMap(), "resize");
mapWidget.getMap().setCenter(center);

But my MapWidget class has no getMap() method, besides I don't have an Event class that allows passing a MapWidget and String as arguments.

Lastly, I've also tried this proposed here:

private final native void resizeMap(GoogleMap map) /*-{
    $wnd.google.maps.event.trigger(map, 'resize');
}-*/;

But this does not work either...any clues?

Thanks! Alex

Upvotes: 0

Views: 364

Answers (1)

Dr.Molle
Dr.Molle

Reputation: 117354

I'm not familiar with GWT, but it appears that mapWidget already is a pointer to the MapWidget-instance.

Maybe checkResizeAndCenter() is what you are looking for. At least the description sounds promising:

Notifies the map of a change in the size of its container and moves to the center of the map. Call this method after the size of the container DOM object has changed, so that the map can adjust itself to fit the new size.

mapWidget.checkResizeAndCenter();

Upvotes: 1

Related Questions