Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

KML + Google Earth: Make a Polygon or GroundOverlay clickable?

Pretty simple question.

I've got some Polygons and GroundOverlays defined in KML. Is there a way to specify that they should be clickable, and (in Google Earth, at least) pop up an info balloon or similar when they are clicked?

Similarly, is it possible to give polygons/GroundOverlays any sort of mouseover behavior? e.g. change the icon or color when moused over?

like image 500
DanM Avatar asked Feb 23 '10 19:02

DanM


People also ask

Can you move polygons in Google Earth?

You can't conveniently move polygons in Google Earth Pro. The polygon vertices are written in the code. Circles are actually a many sided polygon. Jason, one of our Product Experts has written a circle generator that might help.

How do I edit a KML file in Google Earth?

To edit a line or shape, mouse over it and drag the points (click 'Edit lines' first). Click on a point to delete it. The imported kml-file will not be affected. Copy and paste the new coordinates in the local kml-file.


1 Answers

Yes. Giving the Placemark a name and description will make it a clickable object in Google Earth and will open with an info window showing both. You can create rollover/mouseover behavior using stylemaps, here is an example that does both:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<name>Highlighted Icon</name>
<description>Place your mouse over the icon to see it display the new
      icon</description>
<StyleMap id="exampleStyleMap">
  <Pair>
    <key>normal</key>
    <!-- you could also use a <styleUrl> here instead of inlining -->
    <Style>
      <PolyStyle>
        <color>7dff0000</color>
      </PolyStyle>
    </Style>
  </Pair>
  <Pair>
    <key>highlight</key>
    <!-- you could also use a <styleUrl> here instead of inlining -->
    <Style>
      <PolyStyle>
        <color>7dffffff</color>
      </PolyStyle>
    </Style>
  </Pair>
</StyleMap>

<!-- and now, a Placemark that uses the StyleMap -->
<Placemark>
  <name>Roll over this polygon</name>
  <description>this will show up when clicked</description>
  <visibility>1</visibility>
  <styleUrl>#exampleStyleMap</styleUrl>
  <Polygon>
    <tessellate>1</tessellate>
    <altitudeMode>absolute</altitudeMode>
    <outerBoundaryIs>
      <LinearRing>
        <coordinates>
          -112.3372510731295,36.14888505105317,1784
          -112.3356128688403,36.14781540589019,1784
          -112.3368169371048,36.14658677734382,1784
          -112.3384408457543,36.14762778914076,1784
          -112.3372510731295,36.14888505105317,1784
        </coordinates>
      </LinearRing>
    </outerBoundaryIs>
  </Polygon>
</Placemark>
</Document>
</kml>
like image 56
Ossama Avatar answered Sep 17 '22 01:09

Ossama