Advanced uses of KML tags
 

Defining the default view

<LookAt> defines a camera position (your view) that can be associated with any feature created by KML elements. In Google Earth, double-clicking an item in the Places panel (or double-clicking an icon in the 3D viewer) causes the view to "fly to" the LookAt viewpoint. These values can be changed for a feature within GE through the properties GUI or by using taking a Snapshot of the current view.

<LookAt id="ID">
  <longitude></longitude>       <!-- Angle from -180 to 180 degrees-->
  <latitude></latitude>         <!-- Angle from -90 to 90 degrees-->
  <altitude>0</altitude>        <!-- Distance above earth's surface in meters; default=0 --> 
  <range></range>               <!-- Distance in meters from the point specified by <longitude>, 
				     <latitude>, and <altitude> to the LookAt position -->
  <tilt>0</tilt>                <!-- float -->
  <heading>0</heading>          <!-- float -->
  <altitudeMode></altitudeMode> <!-- Specifies how the <altitude> specified for the LookAt point is interpreted; 
				     clampToGround, relativeToGround, absolute -->
</LookAt>

For more information: http://earth.google.com/kml/kml_tags_21.html#lookat


 

Removing the header and footer in balloons

The default header (the feature's name) and footer (directions) can be removed by defining a <BalloonStyle>

Example

goldengate.kml

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
<name>San Francisco</name>
    <Style id="yellow">
        <IconStyle>
            <scale>1.1</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
        </IconStyle>
        <LabelStyle>
            <color>00ffffff</color>
        </LabelStyle>
        <BalloonStyle>
            <text>$[description]</text>
        </BalloonStyle>

    </Style>   
    <Placemark>
    <name>A Bridge</name>
        <description>This is the Golden Gate Bridge</description>
        <styleUrl>#yellow</styleUrl>
        <Point>
            <coordinates>-122.4784418363343,37.81888070994548,0</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>

 

 

Using HTML within balloons

The <description> element supports plain text as well as a subset of HTML formatting elements, including tables (see KML example below). It does not support other web-based technology, such as dynamic page markup (PHP, JSP, ASP), scripting languages (VBScript, Javascript), nor application languages (Java, Python). If a description contains no HTML markup, Google Earth attempts to format it, replacing newlines with <br> and wrapping URLs with anchor tags. A valid URL string for the World Wide Web is automatically converted to a hyperlink to that URL (e.g., http://www.google.com). When using HTML to create a hyperlink around a specific word, or when including images in the HTML, you must use HTML entity references or the CDATA element to escape angle brackets, apostrophes, and other special characters. Currently, the best way to create rich content for the <Placemark> balloons is to use CDATA with <table> HTML.

Examples

yellowstone_notable.kml

yellowstone_table.kml


Follow this link for more information


 

Removing description text from beneath the feature name in the Places panel

Normally the first two lines of <description> text will appear in the Place pane:

However, using the <Snippet> tag allows separate text to be shown and to define the number of lines shown.

Example

snippet.kml

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">  
<Placemark>
    <name>A Bridge</name>
    <Snippet maxLines="4">
        The snippet is a way of
        providing an alternative
        description that will be
        shown in the List view.
    </Snippet>

    <description>This is the Golden Gate Bridge</description>
    <Point>
        <coordinates>-122.4784418363343,37.81888070994548,0</coordinates>
    </Point>
</Placemark>
</kml

For more information:  http://earth.google.com/kml/kml_tags_21.html#snippet


 

Creating folders with radio button style access to content

Using the radioFolder option within the <listItemType> tag allows only one of the folder's items to be visible at a time.

Example

webcams.kml

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Folder>
    <name>Webcams</name>
    <visibility>0</visibility>
    <open>1</open>
    <Style>
        <ListStyle>
            <listItemType>radioFolder</listItemType>
        </ListStyle>

    </Style>
    <ScreenOverlay>
        <name>Augustine</name>
        <visibility>0</visibility>
        <Icon>
            <href>http://www.avo.alaska.edu/webcam/augustine.jpg</href>
            <refreshMode>onInterval</refreshMode>
            <refreshInterval>60</refreshInterval>
        </Icon>
        <overlayXY x="1" y="0" xunits="fraction" yunits="fraction"/>
        <screenXY x="1" y="0.1" xunits="fraction" yunits="fraction"/>
        <size x="0" y="0.3" xunits="fraction" yunits="fraction"/>
    </ScreenOverlay>
    <ScreenOverlay>
        <name>Veniaminof</name>
        <visibility>0</visibility>
        <Icon>
            <href>http://www.avo.alaska.edu/webcam/veni.jpg</href>
            <refreshMode>onInterval</refreshMode>
            <refreshInterval>60</refreshInterval>
            </Icon>
        <overlayXY x="1" y="0" xunits="fraction" yunits="fraction"/>
        <screenXY x="1" y="0.1" xunits="fraction" yunits="fraction"/>
        <size x="0" y="0.3" xunits="fraction" yunits="fraction"/>
    </ScreenOverlay>
    <ScreenOverlay>
        <name>None</name>
        <visibility>0</visibility>
        <Icon>
            <href>http://squarepeg.net.images.alaska.edu/googlearth/alertstatus/blank.png</href>
            <refreshMode>onInterval</refreshMode>
            <refreshInterval>60</refreshInterval>
        </Icon>
        <overlayXY x="1" y="1" xunits="fraction" yunits="fraction"/>
        <screenXY x="0" y="0" xunits="fraction" yunits="fraction"/>
        <rotationXY x="0.5" y="0.5" xunits="fraction" yunits="fraction"/>
        <size x="0" y="0" xunits="fraction" yunits="fraction"/>
        </ScreenOverlay>
</Folder>
</kml>

For more information: http://earth.google.com/kml/kml_tags_21.html#listItemType


 

Highlighting a different icon when mousing over an icon

Using the <StyleMap> tag it is possible to map between two different (normal and highlighted) icon styles for a <Placemark>. The normal highlighted version appears when the user mouses over the icon, otherwise the normal style icon is shown.

Example

rollover.kml

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
<Document>
    <name>UAF</name>
    <open>1</open>
    <Style id="yellow_pin">
        <IconStyle>
            <scale>1.1</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/ylw-pushpin.png</href>
            </Icon>
        </IconStyle>
    </Style>
    <Style id="red_pin">
        <IconStyle>
            <scale>1.5</scale>
            <Icon>
                <href>http://maps.google.com/mapfiles/kml/pushpin/red-pushpin.png</href>
            </Icon>
        </IconStyle>
    </Style>
    <StyleMap id="turn_red">
        <Pair>
            <key>normal</key>
            <styleUrl>#yellow_pin</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#red_pin</styleUrl>
        </Pair>
    </StyleMap>
    <StyleMap id="no_change">
        <Pair>
            <key>normal</key>
            <styleUrl>#yellow_pin</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>#yellow_pin</styleUrl>
        </Pair>
    </StyleMap>
    <Placemark>
        <name>West Ridge Research Building</name>
        <styleUrl>#turn_red</styleUrl>
        <Point>
            <coordinates>-147.8498255123336,64.8598193164168,0</coordinates>
        </Point>
        </Placemark>
        <Placemark>
            <name>International Arctic Research Center</name>
            <styleUrl>#no_change</styleUrl>
            <Point>
                <coordinates>-147.8510859736088,64.85918960333235,0</coordinates>
            </Point>
        </Placemark>
        <Placemark>
            <name>Geophysical Institute</name>
            <styleUrl>#turn_red</styleUrl>
            <Point>
                <coordinates>-147.8494756948915,64.85935860296708,0</coordinates>
            </Point>
        </Placemark>
</Document>
</kml>

For more information: http://earth.google.com/kml/kml_tags_21.html#stylemap


 

 Importing data using Web Mapping Services (WMS)

WMS data can be accessed through the Google Earth GUI that creates the <GroundOverlay> feature.