当一个标记位于打开的infobox -事件鼠标悬停与infobox插件谷歌地图API v3



我在使用Google Maps API v3和InfoBox插件时遇到了一些问题,特别是关于这个可用性问题的用例:

因为我的地图需要一个自定义的信息框被打开时,鼠标悬停在每个各自的标记,当地图上有2个标记是接近的,即使当/如果其中一个标记位于当前打开的信息框后,悬停在另一个附近的标记,它被触发当鼠标在它的标记(即使它在当前打开的信息框后面)和另一个信息框阻碍当前/先前打开的信息框

我已经遵循了另一个海报的问答过程:Google Maps API v3事件鼠标移到InfoBox插件,并遵循了推荐的代码,但我不知道如何防止位于打开的信息框后面的标记直到该信息框关闭才被触发。

var gpoints = [];
function initializeMap1() {
    var Map1MileLatLang = new google.maps.LatLng(39.285900,-76.570000);
    var Map1MileOptions = {
      mapTypeControlOptions: {
            mapTypeIds: [ 'Styled']
        },
       mapTypeControl: false,
        zoom: 14,
      center: Map1MileLatLang,
      //mapTypeId: google.maps.MapTypeId.ROADMAP, 
      mapTypeId: 'Styled' 
    };
    var Map1Mile = new google.maps.Map(document.getElementById("map_canvas"), Map1MileOptions);
    var styledMapType = new google.maps.StyledMapType(styles, { name: 'Styled' });//new
    Map1Mile.mapTypes.set('Styled', styledMapType);//new
   for ( var i=0; i<5; i++ ) {
            gpoints.push( new point(Map1Mile) );
            gpoints.push( new point2(Map1Mile) );
   }
function popup(_point) {
        _point.popup = new InfoBox({
            content:            _point.content,
            pane:               'floatPane',
            closeBoxURL:        '',
            alignBottom:        1
        });
        _point.popup.open(_point.marker.map, _point.marker);
            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();
                    }
                );
            });  
   }
 function point(_map) {
        this.marker = new google.maps.Marker({
            position:           new google.maps.LatLng(39.291003,-76.546234),
            map:                _map
        });
        this.content = '<div class="map-popup" style="width:100px;"><div class="map-popup-window"><div class="map-popup-content"><a href="http://www.google.com/">Just try to click me!</a><br/>Hovering over this text will result in a <code>mouseout</code> event firing on the <code>map-popup</code> element and this will disappear.</div></div>';
        // Scope
        var gpoint = this;
        // Events
        google.maps.event.addListener(gpoint.marker, 'mouseover', function() {
            popup(gpoint);
    });
    }

 function point2(_map) {
        this.marker = new google.maps.Marker({
            position:           new google.maps.LatLng(39.295003,-76.545234),
            map:                _map
        });
        this.content = '<div class="map-popup" style="width:100px;"><div class="map-popup-window"><div class="map-popup-content"><a href="http://www.google.com/">Just try to click me!</a><br/>Hovering over this text will result in a <code>mouseout</code> event firing on the <code>map-popup</code> element and this will disappear.</div></div>';
        // Scope
        var gpoint = this;
        // Events
        google.maps.event.addListener(gpoint.marker, 'mouseover', function() {
            popup(gpoint);
        });
    }

在做实验后,我怀疑这个问题与z-index无关…我在理解这需要在javascript中捕获是正确的吗?

任何帮助或建议将不胜感激!

为你的标记添加optimized: false属性应该可以解决这个问题。

this.marker = new google.maps.Marker({
        position:           new google.maps.LatLng(39.295003,-76.545234),
        map:                _map,
        optimized:          false
    });

最新更新