简体   繁体   English

如何在Google Maps <v3上触发地图事件

[英]How to trigger map event on Google Maps < v3

I'm having an issue with an app that loads several google maps. 我在加载多个Google地图的应用程序时遇到问题。 Second of this maps has the famous issue of not displaying well because it seems the div dimensions are not found correctly. 此地图的第二个著名问题是显示不正确,因为似乎无法正确找到div尺寸。 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. 由于我现在无法切换到v3,因此我没有一个建议的解决方案,我会在一段时间后再做,但是现在不能。

Thus, how can I trigger the resize event on google maps API < v3? 因此,如何在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. 但是我的MapWidget类没有getMap()方法,此外我没有Event类,该类允许传递MapWidget和String作为参数。

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 亚历克斯

I'm not familiar with GWT, but it appears that mapWidget already is a pointer to the MapWidget-instance. 我不熟悉GWT,但似乎mapWidget已经是MapWidget实例的指针。

Maybe checkResizeAndCenter() is what you are looking for. 也许checkResizeAndCenter()是您想要的。 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. 更改容器DOM对象的大小后,请调用此方法,以便地图可以调整自身以适应新的大小。

mapWidget.checkResizeAndCenter();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM