1

我在地图上添加了一个叠加层并更改了叠加层的颜色。我想知道是否可以向叠加层添加悬停事件?基本上,当您将鼠标悬停在美国某个州上时,如果它是蓝色的,它将变为绿色。类似的东西。这就是我现在所拥有的。

http://www.opsdivina.net/soum/

提前致谢

4

3 回答 3

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

于 2012-04-05T18:08:08.433 回答
0

http://groups.google.com/group/kml-support-getting-started/browse_thread/thread/66e7a7ab1b269104/d050e85ab54679a1

出于某种原因,下面的引用没有直接格式化并跳过一些 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

于 2012-04-05T16:26:21.610 回答
0

KMZ 和 KML 中的悬停状态在 V3 中不起作用。真正实现这一点的唯一方法是直接在脚本中调用多边形。这样做将允许您内联添加侦听器。

于 2014-03-14T13:29:29.007 回答