1
votes

I am looking to have two names for a placemark, one displayed when the placemark is hovered over, and one when it is not hovered over. The only information I've been able to find is changing the style (icon type, color, opacity, scale) for a highlighted placemark style. Any suggestions? Is this possible?

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

2

2 Answers

1
votes

You could use custom icons to present a pseudo name (an image of the text you require) and another roll over pseudo name in the same manner.

This is called "styles for Highlighted Icons", to use it you would need to create and upload the two jpg images

nameImageOver.jpg

and

nameImageNormal.jpg

The kml would look like so:

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

I have achieved this using the Google Earth API. Not sure how this plays in with using 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('');
});