在Google Maps V3中创建可点击的OverlayView

时间:2013-04-12 11:08:17

标签: javascript google-maps google-maps-api-3

我正在尝试将鼠标悬停事件侦听器添加到Google地图覆盖视图中。我一直following this question,但无法让听众工作。这是我的代码:

InfoWindow.prototype = new google.maps.OverlayView;
InfoWindow.prototype.onAdd = function() {
  this.getPanes().overlayMouseTarget.appendChild(this.$content.get(0));
  this.getPanes().overlayMouseTarget.parentNode.style.zIndex = 100000;
  google.maps.event.addListener(this, 'mouseover', function() {
    console.log('MOUSEOVER');
  });
};

这不会产生任何错误,但也不会对鼠标悬停做任何事情。我也尝试过使用this.listeners

this.listeners = [
    google.maps.event.addDomListener(this, "mouseover", function (e) {
       console.log('MOUSEOVER');
    })
];

但它也没有帮助。我做错了什么?

1 个答案:

答案 0 :(得分:0)

要使domListener正常工作,您需要将其附加到dom节点:

google.maps.event.addDomListener(this。$ content.get(0),“mouseover”,function(e){        的console.log( '鼠标悬停');     });