Google Maps API: infoWindow flickers/closes automatically because of mouseout event

匿名 (未验证) 提交于 2019-12-03 08:46:08

问题:

I'm in the midst of creating polygons on a spiffy new project I am working on. The problem arises whenever you hover over the infoWindow, the mouseout event on the polygon fires. I don't want the mouseout event to fire unless the mouse moves outside of the polygon AND the infoWindow. Any ideas? Here's 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();     }); 

回答1:

Instead of mouseout of the polygon observe mousemove for the map(this will not fire when the mouse moves over the polygon or 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();       }); }); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!