动态KML地标名称显示可能吗?

时间:2011-08-09 18:03:41

标签: kml google-earth

我希望有两个地标名称,一个在地标悬停时显示,一个在没有悬停时显示。我能找到的唯一信息是改变突出显示的地标样式的样式(图标类型,颜色,不透明度,比例)。有什么建议?这可能吗?

http://code.google.com/apis/kml/documentation/kml_tut.html#custom_styles

2 个答案:

答案 0 :(得分:1)

您可以使用自定义图标以相同的方式呈现伪名称(您需要的文本的图像)和另一个滚动伪名称。

这被称为“突出显示图标的样式”,使用它你需要创建和上传两个jpg图像

nameImageOver.jpg

nameImageNormal.jpg

kml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>Highlighted Icon</name>
    <description>Mouse over to see the swap</description>
    <Style id="highlightPlacemark">
      <IconStyle>
        <Icon>
        <href>http://www.yourserver.com/nameImageOver.jpg</href>
        </Icon>
      </IconStyle>
    </Style>
    <Style id="normalPlacemark">
      <IconStyle>
        <Icon>
          <href>http://www.yourserver.com/nameImageNormal.jpg</href>
        </Icon>
      </IconStyle>
    </Style>
    <StyleMap id="exampleStyleMap">
      <Pair>
        <key>normal</key>
        <styleUrl>#normalPlacemark</styleUrl>
      </Pair>
      <Pair>
        <key>highlight</key>
        <styleUrl>#highlightPlacemark</styleUrl>
      </Pair>
    </StyleMap>
    <Placemark>
      <styleUrl>#exampleStyleMap</styleUrl>
      <Point>
        <coordinates>-122.0856545755255,37.42243077405461,0</coordinates>
      </Point>
    </Placemark>
  </Document>
</kml>

答案 1 :(得分:0)

我使用Google Earth API实现了这一目标。不知道如何使用KML ...

// On mouse over - show name
google.earth.addEventListener(placemark, 'mouseover', function(event) {
    placemark.setName('My Placemark Label');
});
// On mouse out - hide (remove) name
google.earth.addEventListener(placemark, 'mouseout', function(event) {
    placemark.setName('');
});
相关问题