Google Maps API: Windows information flickers / closes automatically due to mouseout event

I am going to create polygons in a new project that I am working on. The problem arises whenever you hover over the infoWindow event, the mouseout event on polygons. I do not want the mouseout event to fire if the mouse does not move outside the polygon AND infoWindow. Any ideas? Here is most of the relevant code.

infoWindow = new google.maps.InfoWindow({ content: myContent }); var polygon = new google.maps.Polygon({ paths: polygonPath, strokeColor: data.color, strokeOpacity: 0.5, strokeWeight: 0, fillColor: data.color, fillOpacity: 0.5, id:polygonId, name: data.name, shortDesc: data.short_desc, map: map }); google.maps.event.addListener(polygon, 'click', function(e){ infoWindow.open(map); infoWindow.setPosition(e.latLng); }); google.maps.event.addListener(polygon, 'mouseout', function(){ infoWindow.close(); }); 
+6
source share
1 answer

Instead of a mouseout for a polygon, observe a mousemove for the map (this does not work when the mouse moves across the polygon or to the infowindow)

 google.maps.event.addListener(polygon, 'click', function(e){ infoWindow.open(map); infoWindow.setPosition(e.latLng); google.maps.event.addListenerOnce(map, 'mousemove', function(){ infoWindow.close(); }); }); 
+15
source

Source: https://habr.com/ru/post/947533/


All Articles