2013-10-22 102 views
1

我正在尝试在鼠标悬停上更改地标图像。下面是鼠标悬停事件处理程序:Google Earth API在鼠标悬停上更改地标图像

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

的问题是,该功能运行时,它确实改变形象,但它也完全复位标使其一遍,就好像是做缩放动画一个全新的地标被添加到地图中。

有没有办法来防止这种情况发生?我正在寻找只更改图像,而不是重置地标。那种破坏体验。

回答

2

当然,您可以使用样式在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>