单击地图时关闭信息框

Close Infobox when clicking on the map

本文关键字:信息 地图 单击      更新时间:2023-09-26

我正在使用Google Maps V3 API的Infobox插件(http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html)

当用户像在地图上一样在信息框外点击时,信息框是否太近了?

如果您将信息窗口作为全局变量,或者至少在方便的地方保存一个表示要添加的单个信息框的变量,那么实际上会容易得多。

编辑:只是为了澄清:例如,它应该而不是window.myInfoBox。对于global,我指的是您参考信息框的单个点

google.maps.event.addListener(map, 'click', function() {
    if(infowindow){
       infowindow.close();
    }
});

仅此而已:-(

您需要使用addListener((

http://code.google.com/apis/maps/documentation/javascript/events.html#EventListeners

您可以调整此处的代码:

google.maps.event.addListener(_point.popup, 'domready', function() {
//Have to put this within the domready or else it can't find the div element (it's null until the InfoBox is opened)
    $(_point.popup.div_).hover(
        function() {
            //This is called when the mouse enters the element
        },
        function() {
            //This is called when the mouse leaves the element
            _point.popup.close();
        }
    );
});    

Src:谷歌地图API v3事件鼠标悬停与InfoBox插件

你可以用这个检测地图点击:

google.maps.event.addListener(map, 'click', function() {
});

API信息框:http://google-maps-utility-library-v3.googlecode.com/svn/trunk/infobox/docs/reference.html

这可能对您有用。。

var inside = false;
$('#foo').live('mouseenter',function(){ 
    inside=true; 
}).live('mouseleave', function(){ 
    inside=false; 
});
$("body").mouseup(function(){ 
    if(!inside) $('#foo').remove();
});