放大地图时保持InfoWindow处于可见状态 [英] Keeping the InfoWindow in view when zooming map in

查看:137
本文介绍了放大地图时保持InfoWindow处于可见状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需将我们的地图从API的V2转换为v3.

Just started converting our maps from V2 of the API to v3.

到目前为止,有一个问题是,当打开InfoWindow并将地图放大时,InfoWindow将从地图上移开并最终不可见,这与V2中的行为不同. 在V2中,InfoWindow始终保持在视图中.

Got one issue so far in that when an InfoWindow is open, and the map is zoomed in, the InfoWindow will move off the map and eventually not be visible, this is different behaviour than in V2. In V2 the InfoWindow remains in view all the time.

V2地图: http://www.stroud.gov.uk/docs /housing/tenant_map_v2.asp

V3地图: http://www.stroud.gov.uk/docs /housing/tenant_map_v3.asp

只需单击任何标记以打开它的信息窗口",然后使用普通的缩放控件将地图放大.

Simply click on any marker to open it's InfoWindow, then zoom the map in with the normal zoom controls.

是否有一种方法可以保持V2地图中的行为?

Is there a way to keep the behaviour as in the V2 map?

谢谢, 迈克

我想出了一个行之有效的解决方案.上面的网址,但使用tenant_map.asp

I've come up with a solution that works. URL as above but use tenant_map.asp

var currentInfoWindow = null; // new global scope variable to hold current open infoWindow

在google.maps.event.addListener(newMarker中,我添加了点击"功能:

In the google.maps.event.addListener(newMarker, "click" function I've added:

currentInfoWindow = this;

添加zoom_changed侦听器:

Add a zoom_changed listener:

google.maps.event.addListener(theMap, "zoom_changed", function () {
    if (currentInfoWindow != null) {
        infoWindow.open(theMap, currentInfoWindow);
    }
});

和一个infoWindow closeclick侦听器:

and an infoWindow closeclick listener:

google.maps.event.addListener(infoWindow, "closeclick", function () {
    currentInfoWindow = null;
});

似乎可以正常工作,在缩放时确实会有些平移,但这是到目前为止我唯一要做的事情.

Seems to work ok, do get a little bit of panning when zooming, but this has been the only thing that I've got to work so far.

它看起来不如V2地图好,因此,如果其他人有更好的解决方案,请发布.

It doesn't look as good as the V2 map, so if anyone else has a better solution, please post.

推荐答案

在我看来,因为V2地图在缩放时会直接缩放到最后一个突出显示的标记上. V3会放大到地图当前居中的任何位置.如何使标记单击事件处理程序将地图重新​​定位到该标记上?

It seems to me because the V2 map, when you zoom, zooms directly onto the last highlighted marker. V3 just zooms onto wherever the map is currently centred. What about making the marker click event handler re-centre the map on that marker?

这篇关于放大地图时保持InfoWindow处于可见状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆