在我的网站上,我有许多 Google 地图 (v3),您可以通过 TabPanel 选择它们(每个选项卡一个),但切换选项卡时会出现问题。当您选择该选项卡时,它不会“唤醒”地图。要解决此问题,我只需使用 ResizeEvent.fire(source, Window.getClientWidth(), Window.getClientHight());这将激活地图上的调整大小监听器并“唤醒它”。我的问题是我无法获取指向浏览器窗口的已注册调整大小处理程序的指针(它在 com.google.gwt.user.client.Window.handlers 中受包保护),因此我不知道使用什么作为我的源。如果有人对我的解决方案或其他可能的解决方案有答案,我将不胜感激。
谢谢,汤姆
On my site I have a number of Google Maps (v3) that you can select via a TabPanel (one per tab) but there is a problem when you switch tabs. When you select the tab it does not "wake up" the map. To fix this I simply need to use ResizeEvent.fire(source, Window.getClientWidth(), Window.getClientHight()); this will active the resize listener on the map and "wake it up." My problem is that I cant get a pointer to the registered resize handlers for the browser window (it is package protected in com.google.gwt.user.client.Window.handlers) therefore I don't know what to use as my source. If anyone has the answer to my solution or another possible solution it would be greatly appreciated.
Thanks, Tom
发布评论
评论(3)
我不确定使用调整大小是否是执行此操作的最佳方法(我之前没有嵌入地图),但您可以考虑使用 TabLayoutPanel 而不是 TabPanel,并调用 panel.onResize() 而不是触发调整大小事件。请注意,您需要使用 *LayoutPanel(或实现 ProvidesResize) 一直到文档的根目录,并且您的页面需要以标准模式呈现。
I am not sure if using resize is the best way of doing this (I haven't embedded a map before), but you could consider using a TabLayoutPanel instead of a TabPanel, and call panel.onResize() instead of firing the resize event. Note that you would need to use *LayoutPanels (or something that implements ProvidesResize) all the way to the root of the document, and your page would need to be rendered in standards mode.
感谢您的回复,但我发现这三行:
HasLatLng center = mapWidget.getMap().getCenter();
Event.trigger(mapWidget.getMap(), "resize");
mapWidget.getMap().setCenter(center);
做这个伎俩。这基本上就是地图最初加载时发生的情况。在 MapWidget 的 onLoad() 方法中,它调用 super.onLoad() 然后执行这三行“唤醒”地图并保留中心点。
Thanks for your reply but I figured out that these three lines:
HasLatLng center = mapWidget.getMap().getCenter();
Event.trigger(mapWidget.getMap(), "resize");
mapWidget.getMap().setCenter(center);
do the trick. This is basically what happens when the map loads initially. In the onLoad() method for MapWidget it makes a call to super.onLoad() then executes these three lines which "wakes up" the map and preserves the center point.
如果您使用 GWT-Maps-V3-Api,则有一个
MapWidget
类中的 >triggerResize() 函数可以实现这一目的。If you are using GWT-Maps-V3-Api, there is a
triggerResize()
function in theMapWidget
class that does the trick.