1

我在“鼠标悬停”上有一个事件监听器,它可以在 infoWindow 中显示正确的文本,但是这些 infoWindow 永远不会消失,除非你按下 x。我希望它们在用户移开鼠标后消失。下面是代码。

谢谢!

iPark.makeMarker = function (lat, long, street, location, description ) {
  var myLatlng = new google.maps.LatLng(lat, long)
  var marker = new google.maps.Marker({
    position: myLatlng,
    title: 'Click to Zoom'
  });
  marker.setMap(this.map)

  google.maps.event.addListener(marker, 'click', function() {
    iPark.map.setZoom(18);
    iPark.map.setCenter(marker.getPosition());
    google.maps.event.addListener(marker, 'click', function() {
      iPark.map.setZoom(13)
      iPark.map.setCenter(37.7833, -122.4167)
    })
  });

  google.maps.event.addListener(marker, 'mouseover', function() {
    iPark.infoWindow(street).open(iPark.map, marker)
  });
  google.maps.event.addListener(marker, 'mouseout', function() {
    console.log("hello")
    iPark.closeinfoWindow
  });
}

iPark.infoWindow = function(street){
  return new google.maps.InfoWindow({
    content: String(street)
})

iPark.closeinfoWindow = InfoWindow.close()

};
4

2 回答 2

4

将 infoWindow 存储为标记的属性:

google.maps.event.addListener(marker, 'mouseover', function() {
    if(!this.get('iw'))this.set('iw',iPark.infoWindow(street));
    this.get('iw').open(iPark.map, this);
  });

那么您以后就可以访问它了:

google.maps.event.addListener(marker, 'mouseout', function() {
    this.get('iw').close();
  });
于 2013-10-20T01:52:03.147 回答
0

这看起来不对。

  google.maps.event.addListener(marker, 'mouseout', function() {
    console.log("hello")
    iPark.closeinfoWindow
  });

这可能会更好(未经测试,基于报告的工作“mouseout”功能):

  google.maps.event.addListener(marker, 'mouseout', function() {
    iPark.infoWindow(street).close();

  });
于 2013-10-20T01:20:35.023 回答