单击地图时关闭信息框

Nyx*_*yxx 5 javascript jquery google-maps google-maps-api-3

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

当用户在地图上点击信息框之外时,信息框是否过于接近?

MJB*_*MJB 11

如果将infowindow作为全局变量,或者至少保存一个代表您想要在方便的位置添加的单个信息框的变量,它实际上会更容易.

编辑:只是为了澄清:它应该window.myInfoBox是例如.全局我的意思是你引用你的信息框的单点

google.maps.event.addListener(map, 'click', function() {
    if(infowindow){
       infowindow.close();
    }
});
Run Code Online (Sandbox Code Playgroud)

就这样 :-)


Edd*_*die 5

你会想要使用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();
        }
    );
});    
Run Code Online (Sandbox Code Playgroud)

Src: 使用InfoBox插件的Google Maps API v3事件鼠标悬停

您可以使用以下方法检测地图点击:

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

});
Run Code Online (Sandbox Code Playgroud)

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