KML styles and stylemaps

The symbology of polygons can be defined by styles and stylemaps. Styles define specific fill and line settings. There can be as many styles as you want. Each placemark (or in this case polygon) can be defined by a separate style, or one style can be used for all placemarks. StyleMaps are used for mouse-over effects. Since there are two styles for a mouse-over (a normal style, and a highlighted style), a StyleMap defines the relationships. Below are some options for defining Styles and StyleMaps.

Here is a sample style that defines the polygon fill and outline settings:

<Style id=”normal”>
<LineStyle>
<color>64000000</color> !I used the following website to select the colour code. The code also defines the level of transparency. http://www.zonums.com/gmaps/kml_color/
<width>1</width> !Specifies the width of the line. In this case 1 is a thin line.
</LineStyle>
<PolyStyle>
<color>3c14F0FF</color> !Specifies the fill colour. In this case yellow with 60% transparency
</PolyStyle>
</Style>

Here is another style to define highlighted polygons for a mouse-over:

<Style id=”highlight”>
<LineStyle>
<color>ff3f00ff</color> !Red line
<width>4</width> !4 is a thick line
</LineStyle>
<PolyStyle>
<color>3c14F0FF</color> !Red fill with 50% transparency
</PolyStyle>
</Style>

Now we can define the StyleMap:

<StyleMap id=”mouseover”>!The name
<Pair> !Here we specify the normal symbology
<key>normal</key>
<styleUrl>#normal</styleUrl> !Specify the name of the style preceded by a #
</Pair>
<Pair>!Here we specify the highlighted symbology
<key>highlight</key>
<styleUrl>#highlight</styleUrl>
</Pair>
</StyleMap>

In the next post I will describe how to define the location of the polygon placemarks and assign them different styles or stylemaps

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s