Question

I've been looking at this for so long I can't see it any more.

It looks like valid KML style, the URIs look fine, but it does not work.

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://earth.google.com/kml/2.2">
<Document>
    <name>Style Test</name>

    <PolyStyle>
        <color>776d8f77</color>
        <outline>0</outline>
    </PolyStyle>

    <PolyStyle id="counties">
        <color>776d8f77</color>
        <outline>0</outline>
    </PolyStyle>

</Document>
</kml>

This file is referenced by KML:

<?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2"><Document>
    <Placemark>
        <name>Viburnum australe US Distribution</name>
        <styleUrl>/_/maps/style.kml#counties</styleUrl>
            <Polygon> ....

Why does neither style get applied?

TIA.....

Was it helpful?

Solution

<PolyStyle> style elements are not valid outside the context of a parent <Style> element. A feature (e.g. Placemark) cannot refer to a PolyStyle element directly but via a Style or StypeMap reference or inlined element. Also, use the proper KML namespace URL as http://www.opengis.net/kml/2.2 rather than http://earth.google.com/kml/2.2.

Instead rewrite the "style.kml" file like this:

<?xml version="1.0" encoding="utf-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
    <name>Style Test</name>

    <Style id="s1">
      <PolyStyle>
        <color>776d8f77</color>
        <outline>0</outline>
      </PolyStyle>
    </Style>

    <Style id="counties">
      <PolyStyle>
        <color>776d8f77</color>
        <outline>0</outline>
      </PolyStyle>
    </Style>

</Document>
</kml>

Now a reference to the style will work:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
  <Placemark>
    <name>Viburnum australe US Distribution</name>
    <styleUrl>style.kml#counties</styleUrl>
    <Polygon>....

Google provides an example of a KML document of styles used by other KML files:
http://kml-samples.googlecode.com/svn/trunk/kml/Style/styles.kml
http://kml-samples.googlecode.com/svn/trunk/kml/Style/remote-style.kml

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top