Using an external Style KML file

If you save a KML from within Google Earth the Styles that you have used, Placemark icons for example, are included in the KML. While this works for simple KMLs it’s not ideal for more complex ones.

A better way to store and reference Styles, especially if you generate them from a source such as a database or have multiple Network Links within your files, is to use an separate KML that is used purely for your styles - no Placemarks or other Features - just Styles.

The Global Challenge uses this method and is the example I’ll be using below.

One of the Styles used is for a Waypoint - a marker along the route to which boats sail towards. These are simple Placemarks that look like this

and the Style Map for it looks like

    <Style id="s_WP_T2">
        <IconStyle>
            <scale>0.8</scale>
            <Icon>
                <href>http://TheKMZ.co.uk/ge/kmlfiles/fgc0809/images/ico_buoy.png</href>
            </Icon>
        </IconStyle>
        <LabelStyle>
            <color>ff0000ff</color>
            <scale>0.4</scale>
        </LabelStyle>
        <BalloonStyle>
            <text>&lt;h1&gt;$[name]&lt;/h1&gt;$[description]</text>
            <bgColor>ffd5efff</bgColor>
        </BalloonStyle>
    </Style>

    <Style id="s_WP_T2_hl">
        <IconStyle>
            <scale>1.0</scale>
            <Icon>
                <href>http://TheKMZ.co.uk/ge/kmlfiles/fgc0809/images/ico_buoy.png</href>
            </Icon>
        </IconStyle>
        <LabelStyle>
            <color>ff0000ff</color>
            <scale>1.0</scale>
        </LabelStyle>
        <BalloonStyle>
            <text>&lt;h1&gt;$[name]&lt;/h1&gt;$[description]</text>
            <bgColor>ffd5efff</bgColor>
        </BalloonStyle>
    </Style>

    <StyleMap id="sm_WP_T2">
        <Pair>
            <key>normal</key>
            <styleUrl>http://TheKMZ.co.uk/ge/kmlfiles/fgc0809/FGC_Styles.kml#s_WP_T2</styleUrl>
        </Pair>
        <Pair>
            <key>highlight</key>
            <styleUrl>http://TheKMZ.co.uk/ge/kmlfiles/fgc0809/FGC_Styles.kml#s_WP_T2_hl</styleUrl>
        </Pair>
    </StyleMap>

This file is called FGC_Styles.kml (it’s full path is www.TheKMZ.co.uk/ge/kmlfiles/fgc0809/FGC_Styles.kml) and also contains the styles for the Ports and various Boat and Tack Markers.

Within the actual Race KML files the style is referenced within the styleUrl tag thus:-

<Placemark>
	<name>Waypoint 1</name>
	<LookAt>
		<longitude>-53.5</longitude>
		<latitude>-37.5</latitude>
		<altitude>300000</altitude>
	</LookAt>
	<visibility>1</visibility>
	<styleUrl>http://TheKMZ.co.uk/ge/kmlfiles/fgc0809/FGC_Styles.kml#sm_WP_T2</styleUrl>
	<Point>
		<coordinates>-53.5,-37.5,0</coordinates>
	</Point>
</Placemark>

When you have a large number of styles in use it’s a useful way of keeping you main data files free of clutter and keeps Style and Content as separate entities.

This entry was posted in Tips and Snippets and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*