Reputation: 63
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()
};
Upvotes: 1
Views: 3828
Reputation: 117314
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();
});
Upvotes: 4
Reputation: 161334
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();
});
Upvotes: 0