【问题标题】:Mouseover on custom overlay in Google Maps鼠标悬停在 Google 地图中的自定义叠加层上
【发布时间】:2012-12-17 10:54:58
【问题描述】:

是否可以在 Google 地图 (API v3) 中的自定义叠加层上监听鼠标悬停事件?一个简单的例子:

function HWPMarker(map, coords, text) { […] }
HWPMarker.prototype = new google.maps.OverlayView();
HWPMarker.prototype.draw = function() { […] }

HWPMarker.prototype.onAdd = function() {

  $(this.getPanes().overlayLayer).append(this.marker); // this.marker is a div

  // THIS IS WHERE I TRY TO LISTEN TO THE MOUSEOVER EVENT
  google.maps.event.addListener(this, 'mouseover', function(){ alert('mouseover') });

}

我做错了吗?还是无法在自定义叠加层上监听鼠标悬停?

【问题讨论】:

  • 它是否正常工作或者您没有收到警报。

标签: jquery events google-maps-api-3 custom-overlay


【解决方案1】:

This answer 指出 Maps API v3 不再接受鼠标事件。所以我们要做的就是将 DOM 元素添加到 overlayMouseTarget 并使用 Google Maps DOM 侦听器。它是这样工作的:

HWPMarker.prototype.onAdd = function() {
  this.getPanes().overlayMouseTarget.appendChild(this.marker); // this.marker = my dom el
  google.maps.event.addDomListener(this.marker, 'mouseover', function(){ alert('mouseover') });
}

【讨论】:

    猜你喜欢
    • 2011-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多