KML + 谷歌地球 : Make a Polygon or GroundOverlay clickable?

标签 kml google-earth

很简单的问题。

我在 KML 中定义了一些 Polygons 和 GroundOverlays。有没有办法指定它们应该是可点击的,并且(至少在谷歌地球中)在点击它们时弹出一个信息气球或类似的东西?

同样,是否可以为多边形/地面覆盖提供任何类型的鼠标悬停行为?例如鼠标悬停时更改图标或颜色?

最佳答案

是的。为地标指定名称和说明将使其成为 Google 地球中的可点击对象,并会打开一个显示两者的信息窗口。您可以使用样式图创建鼠标悬停/鼠标悬停行为,这是一个同时执行这两个操作的示例:

<?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>

关于KML + 谷歌地球 : Make a Polygon or GroundOverlay clickable?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2320984/

相关文章:

python - 如何使用 lxml 从 KML 获取元素值

javascript - 将基于文本的 div 放置在圆内的相对位置

google-maps - 带有大陆轮廓/边界的 KML 文件

java - 如何让 servlet 容器从查询字符串而不是 URL 中读取 JSESSIONID

python - 解析 JSON 数据时出错

android - 我如何将 kml 文件发送到 Google 地球,就像 MyTracks(开源)一样?

r - 从 .kml 文件为 R 创建 x 和 y 距离坐标

java - java中的KML解析

kml - 使用 kml 在 Google Earth 中动画一条线

kml - 融合表 : Polygon not displayed as of certain zoom level