可以动态显示KML位置标记名称



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

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

您可以使用自定义图标来显示一个伪名称(您需要的文本图像),并以相同的方式显示另一个滚动伪名称。

这被称为"高亮图标样式",要使用它,你需要创建并上传两个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>

我已经使用Google Earth API实现了这一点。

// 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('');
});

最新更新