代码之家  ›  专栏  ›  技术社区  ›  DanM

KML+googleearth:使多边形或地面覆盖可点击?

  •  5
  • DanM  · 技术社区  · 16 年前

    很简单的问题。

    我在KML中定义了一些多边形和地面覆盖。有没有办法指定它们应该是可点击的,并且(至少在googleearth中)在被点击时弹出一个信息气球或类似的东西?

    类似地,是否可以为多边形/地面覆盖提供任何类型的鼠标悬停行为?e、 g.鼠标滑过时更改图标或颜色?

    1 回复  |  直到 16 年前
        1
  •  10
  •   Community Mohan Dere    12 年前

    对给这个地名一个名称和描述将使它成为googleearth中一个可点击的对象,并将打开一个显示两者的信息窗口。您可以使用样式映射创建滚动/鼠标移动行为,下面是一个同时执行这两个操作的示例:

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    <Document>
    <name>Highlighted Icon</name>
    <description>Place your mouse over the icon to see it display the new
          icon</description>
    <StyleMap id="exampleStyleMap">
      <Pair>
        <key>normal</key>
        <!-- you could also use a <styleUrl> here instead of inlining -->
        <Style>
          <PolyStyle>
            <color>7dff0000</color>
          </PolyStyle>
        </Style>
      </Pair>
      <Pair>
        <key>highlight</key>
        <!-- you could also use a <styleUrl> here instead of inlining -->
        <Style>
          <PolyStyle>
            <color>7dffffff</color>
          </PolyStyle>
        </Style>
      </Pair>
    </StyleMap>
    
    <!-- and now, a Placemark that uses the StyleMap -->
    <Placemark>
      <name>Roll over this polygon</name>
      <description>this will show up when clicked</description>
      <visibility>1</visibility>
      <styleUrl>#exampleStyleMap</styleUrl>
      <Polygon>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>
              -112.3372510731295,36.14888505105317,1784
              -112.3356128688403,36.14781540589019,1784
              -112.3368169371048,36.14658677734382,1784
              -112.3384408457543,36.14762778914076,1784
              -112.3372510731295,36.14888505105317,1784
            </coordinates>
          </LinearRing>
        </outerBoundaryIs>
      </Polygon>
    </Placemark>
    </Document>
    </kml>