javascript - Google Earth API 在鼠标悬停时更改地标图像

标签 javascript google-earth google-earth-plugin

我试图在鼠标悬停时更改地标图像。这是鼠标悬停事件处理程序:

function changePlacemark(e){
    e.preventDefault();
    this.getStyleSelector().getIconStyle().getIcon().setHref('myImageURL');
}

问题是当该函数运行时,它确实改变了图像,但它也完全重置了地标,导致它重新做缩放动画,就好像是一个全新的地标被添加到 map 上一样。

有没有办法避免这种情况发生?我只想更改图像,而不是重置地标。有点破坏体验。

最佳答案

当然,您可以使用样式在 KML 中或通过 API 创建滚动图标。您只需要设置功能的样式,而不是更新图标的 href 属性。

在 API 中:

  var style = ge.createStyle("");
  style.getIconStyle().getIcon().setHref('myImageURL');
  feature.setStyleSelector(style);

在 Kml 中:

  <Document>
    <Style id="highlightPlacemark">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/kml/paddle/red-stars.png</href>
        </Icon>
      </IconStyle>
    </Style>
    <Style id="normalPlacemark">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/kml/paddle/wht-blank.png</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>
      <name>Roll over this icon</name>
      <styleUrl>#exampleStyleMap</styleUrl>
      <Point>
        <coordinates>-122.0856545755255,37.42243077405461,0</coordinates>
      </Point>
    </Placemark>
  </Document>

关于javascript - Google Earth API 在鼠标悬停时更改地标图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19523733/

相关文章:

google-earth - 我可以为 google earth 桌面应用程序编写插件吗?

python - 使用 Python 和 PyKML 修改 map 层

javascript - Google 地球插件渴望重新渲染

css - chrome/windows 中的 Google 地球插件 z-index 问题

javascript - 当页面上的链接悬停时,将一个 div 背景更改为多个图像

javascript - 在 react 中在两个外部 css 文件之间切换

javascript - 仅在页面中包含来自已用插件的脚本

java - 将卫星图像或 map 集成到 3D 应用程序中

kml - 获取地标的纬度和经度值 - Google 地球

javascript - 单击添加类,然后延迟删除类(超时功能)