highlight a polygon - mouse over

1,787 views
Skip to first unread message

dz

unread,
Jun 7, 2011, 10:26:55 AM6/7/11
to kml-support-g...@googlegroups.com
I'm new at this, so this may sound redundant. I have a polygon kml file that I would like to be highlighted upon mouse-over. All I have been able to find is how to do this action with the place marker balloons. I'm unsure of what to use for my <href>

Jason M

unread,
Jun 7, 2011, 3:06:10 PM6/7/11
to KML Developer Support - Getting Started with KML
Hi.

If you want to highlight a polygon upon mouse-over you need to add a
StyleMap to the feature with that polygon geometry.

Here's an example:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Style id="sn_style">
<PolyStyle>
<color>00ff8080</color>
<fill>0</fill>
</PolyStyle>
</Style>

<Style id="sh_style">
<PolyStyle>
<color>7fff8080</color>
</PolyStyle>
</Style>

<StyleMap id="msn_style">
<Pair>
<key>normal</key>
<styleUrl>#sn_style</styleUrl>
</Pair>
<Pair>
<key>highlight</key>
<styleUrl>#sh_style</styleUrl>
</Pair>
</StyleMap>

<Placemark>
<name>Polygon with fade in/out</name>
<styleUrl>#msn_style</styleUrl>
<Polygon>
<outerBoundaryIs>
<LinearRing>
<coordinates>
138.64,-34.93 138.64,-34.94 138.63,-34.94 138.62,-34.94
138.62,-34.95 138.62,-34.96 138.61,-34.97 138.60,-34.97
138.59,-34.97 138.58,-34.97 138.57,-34.97 138.57,-34.96
138.57,-34.95 138.57,-34.94 138.57,-34.93 138.57,-34.92
138.57,-34.91 138.56,-34.91 138.56,-34.90 138.57,-34.90
138.57,-34.89 138.56,-34.88 138.57,-34.88 138.58,-34.87
138.58,-34.86 138.58,-34.85 138.60,-34.85 138.61,-34.85
138.63,-34.85 138.64,-34.86 138.64,-34.87 138.63,-34.87
138.63,-34.88 138.62,-34.88 138.62,-34.89 138.63,-34.89
138.63,-34.90 138.64,-34.90 138.64,-34.91 138.64,-34.92
138.64,-34.93
</coordinates>
</LinearRing>
</outerBoundaryIs>
</Polygon>
</Placemark>
</Document>
</kml>

You can also combine technique that with a Region to only show when
polygon is "active" in user's view.
Examples at http://kml-samples.googlecode.com/svn/trunk/kml/Region/

Related references:
http://code.google.com/apis/kml/documentation/kmlreference.html#stylemap
http://code.google.com/apis/kml/documentation/kmlreference.html#region

--jason
Reply all
Reply to author
Forward
0 new messages