【问题标题】:When a marker lies behind open infobox - Event mouseover with InfoBox plugin Google Maps API v3当标记位于打开的信息框后面时 - 带有 InfoBox 插件的事件鼠标悬停 Google Maps API v3
【发布时间】:2011-12-03 05:09:17
【问题描述】:

我在使用 v3 的 Google Maps API 和使用 InfoBox 插件时遇到问题,专门针对这个可用性问题用例:

由于我的地图需要在将鼠标悬停在每个相应的标记上时打开自定义信息框,因此当地图上有 2 个靠近的标记时,即使/如果其中一个标记位于信息框后面将鼠标悬停在另一个附近标记后当前打开,当鼠标悬停在该标记上时会触发它(即使它位于当前打开的信息框后面),并且另一个信息框挡住了当前/以前打开的信息框

我已按照此处另一张海报的问答流程:Google Maps API v3 Event mouseover with InfoBox plugin 并已遵循推荐的代码,但我不知道如何防止打开信息框后面的标记不被触发直到该信息框关闭。

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 中捕获是否正确?

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

【问题讨论】:

    标签: javascript jquery google-maps


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2011-07-22
      • 2011-09-27
      • 1970-01-01
      • 2013-06-07
      • 1970-01-01
      • 2015-05-02
      • 2013-01-07
      • 2010-12-06
      • 2012-02-13
      相关资源
      最近更新 更多