我在地图上添加了一个叠加层并更改了叠加层的颜色。我想知道是否可以将悬停事件添加到叠加层?基本上当你将鼠标悬停在美国州时,如果是蓝色,它将变为绿色。类似的东西。这就是我现在所拥有的。
http://www.opsdivina.net/soum/
提前致谢
答案 0 :(得分:4)
我认为这会奏效!
google.maps.event.addListener(polygon,"mouseover",function(){
this.setOptions({fillColor: "#00FF00"});
tooltip.style.visibility = 'visible';
});
google.maps.event.addListener(polygon,"mouseout",function(){
this.setOptions({fillColor: "#FF0000"});
tooltip.style.visibility = 'hidden';
});
以下链接将有所帮助! http://econym.org.uk/gmap/example_mouseover.htm,http://philmap.000space.com/gmap-api/poly-hov.html,http://econym.org.uk/gmap/example_hoverchange75.htm
答案 1 :(得分:0)
由于某种原因,下面的引用不是直接格式化并跳过一些xml,所以你只想转到上面列出的链接以获得精确的解决方案。试图在这里正确格式化。
如果要在鼠标悬停时突出显示多边形,则需要添加一个 具有该多边形几何体的要素的StyleMap。
以下是一个例子:
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="sn_style">
<PolyStyle>
<color>00ff8080</color>
<fill>0</fill>
</PolyStyle>
</Style>
<Style id="sh_style">
<PolyStyle>
<color>7fff8080</color>
</PolyStyle>
</Style>
<StyleMap id="msn_style">
<Pair>
<key>normal</key>
<styleUrl>#sn_style</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_style</styleUrl>
</Pair>
</StyleMap>
<Placemark>
<name>Polygon with fade in/out</name>
<styleUrl>#msn_style</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
138.64,-34.93 138.64,-34.94 138.63,-34.94 138.62,-34.94
138.62,-34.95 138.62,-34.96 138.61,-34.97 138.60,-34.97
138.59,-34.97 138.58,-34.97 138.57,-34.97 138.57,-34.96
138.57,-34.95 138.57,-34.94 138.57,-34.93 138.57,-34.92
138.57,-34.91 138.56,-34.91 138.56,-34.90 138.57,-34.90
138.57,-34.89 138.56,-34.88 138.57,-34.88 138.58,-34.87
138.58,-34.86 138.58,-34.85 138.60,-34.85 138.61,-34.85
138.63,-34.85 138.64,-34.86 138.64,-34.87 138.63,-34.87
138.63,-34.88 138.62,-34.88 138.62,-34.89 138.63,-34.89
138.63,-34.90 138.64,-34.90 138.64,-34.91 138.64,-34.92
138.64,-34.93
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>
您还可以将区域技术与仅显示时间结合起来 多边形在用户视图中处于“活动状态”。例子 http://kml-samples.googlecode.com/svn/trunk/kml/Region/
相关参考资料: http://code.google.com/apis/kml/documentation/kmlreference.html#stylemap http://code.google.com/apis/kml/documentation/kmlreference.html#region
答案 2 :(得分:0)
KMZ中的悬停状态和KML在V3中不起作用。真正实现这一目标的唯一方法是直接在脚本中调用多边形。这样做可以让你内联添加监听器。