-1

I am trying to figure out how to highlight a line segment when I hover over it in Google Earth.

This is what it currently looks like when I hover over it. Notice that the whole line stays blue: Imgur

This is what I want it to look like when I hover over it. The segment should change color: Imgur

Is there a way to do this with code? Do I need to convert it to a different file type?

1 Answers1

0

To change a line in Google Earth when you mouse over or hover on it then you need the KML to define a StyleMap that with a style for "normal" mode and another for "highlight" mode.

In the example below, the line shows a thin blue line by default showing the normal style, but changes to a thicker purple line when you hover the mouse over the line which then switches to the highlight style.

Example:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
       <Style id="sn">
          <LineStyle>
            <color>7fff0000</color>         
            <width>2</width>
          </LineStyle>
          <PolyStyle>
            <color>7fff0000</color>
          </PolyStyle>
        </Style>
        <Style id="sh">         
          <LineStyle>
            <color>7fff00ff</color>
            <width>8</width>
          </LineStyle>
          <PolyStyle>
            <color>7f00ff00</color>
          </PolyStyle>
        </Style>          
        <StyleMap id="msn">
            <Pair>
                <key>normal</key>
                <styleUrl>#sn</styleUrl>
            </Pair>
            <Pair>
                <key>highlight</key>
                <styleUrl>#sh</styleUrl>
            </Pair>
        </StyleMap>

    <Placemark>
      <name>Style Map example</name>
      <styleUrl>#msn</styleUrl>
      <LineString>
        <tessellate>1</tessellate>
        <altitudeMode>absolute</altitudeMode>
        <coordinates>
          -112.265654928602,36.09447672602546,2357
          -112.2660384528238,36.09342608838671,2357
          -112.2668139013453,36.09251058776881,2357
          -112.2677826834445,36.09189827357996,2357
          -112.2688557510952,36.0913137941187,2357
          -112.2694810717219,36.0903677207521,2357
          -112.2695268555611,36.08932171487285,2357
          -112.2690144567276,36.08850916060472,2357
          -112.2681528815339,36.08753813597956,2357
          -112.2670588176031,36.08682685262568,2357
          -112.2657374587321,36.08646312301303,2357
        </coordinates>
      </LineString>
    </Placemark>
  </Document>
</kml>
CodeMonkey
  • 22,825
  • 4
  • 35
  • 75