简体   繁体   中英

Mouseout for infoWindow.close doesn't work on Google Maps v3 in javascript

I have an event listener on 'mouseover' that work and shows the correct text in the infoWindow however these infoWindow's never go away unless you press the x. I want them to disappear after the user moves their mouse away. Below is the code.

Thanks!

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()

};

Store the infoWindow as a property of the marker:

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

then you'll be able to access it later:

google.maps.event.addListener(marker, 'mouseout', function() {
    this.get('iw').close();
  });

This looks wrong.

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

This might work better (not tested, based off the reported working "mouseout" function):

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

  });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM