Javascript 谷歌地图V3API鼠标覆盖多边形。不起作用
我正试图让鼠标悬停在谷歌地图api v3中工作。我试过这篇文章中给出的答案: 这个答案应该有用,但不适合我。有人能发现我辐条上的棍子吗 这是我的密码:Javascript 谷歌地图V3API鼠标覆盖多边形。不起作用,javascript,google-maps,gis,google-maps-api-3,polygon,Javascript,Google Maps,Gis,Google Maps Api 3,Polygon,我正试图让鼠标悬停在谷歌地图api v3中工作。我试过这篇文章中给出的答案: 这个答案应该有用,但不适合我。有人能发现我辐条上的棍子吗 这是我的密码: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"/> <style type="text/css"> html { height
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 100% }
</style>
<title>Google Maps</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
var myLatlng = new google.maps.LatLng(28, -81);
var myOptions = {
zoom: 6,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.HYBRID
}
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
var coords = "-81.182206004858,24.1854100227356 -81.0702140033245,24.7389860153198 -80.8464170098305,25.8438450098038 -80.6222470104694,26.9482280015945 -80.3975859880447,28.0521240234375 -80.1723110079765,29.1555219888687 -80.7749719917774,29.21175801754 -80.9939419925213,28.1075259447098 -81.212574005127,27.0034509897232 -81.4309749901295,25.8995419740677 -81.6492510139942,24.7958129644394 -81.7585659921169,24.243047952652 -81.182206004858,24.1854100227356";
coords = coords.split(" ");
var path = [];
for (var i = 0; i < coords.length; i++) {
var coord = coords[i].split(",");
path.push(new google.maps.LatLng(coord[1], coord[0]));
}
//polygon options
var options = {
clickable: false,
fillColor: '#FFF',
fillOpacity: 0,
geodesic: true,
map: map,
paths: new google.maps.MVCArray(path),
strokeColor: '#FFF',
strokeOpacity: 1,
strokeWeight: 1,
zIndex: 99
}
var polygon = new google.maps.Polygon(options);
var listener = google.maps.event.addListener(polygon, "mouseover", function () { this.setOptions({ strokeColor: '#000' }); });
}
</script>
</head>
<body onload="initialize()">
<div id="map_canvas"></div>
</body>
</html>
html{高度:100%}
正文{高度:100%;边距:0px;填充:0px}
#地图画布{高度:100%}
谷歌地图
函数初始化(){
var mylatng=new google.maps.LatLng(28,-81);
变量myOptions={
缩放:6,
中心:myLatlng,
mapTypeId:google.maps.mapTypeId.HYBRID
}
var map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
变量坐标="-81.182206004858,24.1854100227356 -81.0702140033245,24.7389860153198 -80.8464170098305,25.8438450098038 -80.6222470104694,26.9482280015945 -80.3975859880447,28.0521240234375 -80.1723110079765,29.1555219888687 -80.7749719917774,29.21175801754 -80.9939419925213,28.1075259447098 -81.212574005127,27.0034509897232 -81.4309749901295,25.8995419740677 -81.6492510139942,24.7958129644394 -81.7585659921169,24.243047952652 -81.182206004858,24.1854100227356";
coords=coords.split(“”);
var路径=[];
对于(变量i=0;i
好的,我想出来了。很简单,但不是很直观
您需要在多边形选项中设置“clickable:true”
文档中说明了有关clickable属性的以下内容:
“指示此多边形是否处理单击事件。默认为true。“
它应该说:“此多边形是否处理(任何)事件。”(例如鼠标悬停)
谷歌文档失败