0
votes
<?xml version="1.0" encoding="UTF-8"?>
<kml 
  xmlns="http://www.opengis.net/kml/2.2" 
  xmlns:gx="http://www.google.com/kml/ext/2.2">

  <Document>

    <Style id="Line1">
      <LineStyle>
        <color>ffff0000</color>
        <width>4</width>
      </LineStyle>
    </Style>
    <Style id="Line2">
      <LineStyle>
        <color>ff00ff00</color>
        <width>4</width>
      </LineStyle>
    </Style>   
    <Style id="Poly1">
      <PolyStyle>
        <color>ff0000ff</color>
      </PolyStyle>
    </Style>    
    <Style id="Poly2">
      <PolyStyle>
        <color>ffffffff</color>
      </PolyStyle>
    </Style>   



   <Placemark>
      <name>Line 1</name>
      <styleUrl>#Line1</styleUrl>
      <LineString>
        <coordinates>
          -112.265654928602,36.09447672602546,2357
          -112.2660384528238,36.09342608838671,2357
          -112.2668139013453,36.09251058776881,2357
          -112.2677826834445,36.09189827357996,2357
          -112.2688557510952,36.0913137941187,2357
          -112.2694810717219,36.0903677207521,2357
          -112.2695268555611,36.08932171487285,2357
          -112.2690144567276,36.08850916060472,2357
          -112.2681528815339,36.08753813597956,2357
          -112.2670588176031,36.08682685262568,2357
          -112.2657374587321,36.08646312301303,2357
        </coordinates>
        <gx:drawOrder>2</gx:drawOrder>
      </LineString>
    </Placemark>

    <Placemark>
      <name>Polygon 1</name>
      <styleUrl>#Poly1</styleUrl>
      <Polygon>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>  
              -112.265654928602,36.09447672602546,2357
              -112.2660384528238,36.09342608838671,2357
              -112.2668139013453,36.09251058776881,2357
              -112.2677826834445,36.09189827357996,2357
              -112.2688557510952,36.0913137941187,2357
              -112.2694810717219,36.0903677207521,2357
              -112.2695268555611,36.08932171487285,2357
              -112.2690144567276,36.08850916060472,2357
              -112.2681528815339,36.08753813597956,2357
              -112.2670588176031,36.08682685262568,2357
              -112.2657374587321,36.08646312301303,2357   
            </coordinates>
          </LinearRing>
        </outerBoundaryIs>
        <gx:drawOrder>4</gx:drawOrder> 
      </Polygon>
    </Placemark>

    <Placemark>
      <name>Line 2</name>
      <styleUrl>#Line2</styleUrl>
      <LineString>
        <coordinates>
          -112.265654928602,36.09447672602546,2357
          -112.2660384528238,36.09342608838671,2357
          -112.2668139013453,36.09251058776881,2357
          -112.2677826834445,36.09189827357996,2357
          -112.2688557510952,36.0913137941187,2357
          -112.2694810717219,36.0903677207521,2357
          -112.2695268555611,36.08932171487285,2357
          -112.2690144567276,36.08850916060472,2357
          -112.2681528815339,36.08753813597956,2357
          -112.2670588176031,36.08682685262568,2357
          -112.2657374587321,36.08646312301303,2357
        </coordinates>
        <gx:drawOrder>4</gx:drawOrder>
      </LineString>
    </Placemark>

    <Placemark>
      <name>Polygon 2</name>
      <styleUrl>#Poly2</styleUrl>
      <Polygon>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>  
              -112.265654928602,36.09447672602546,2357
              -112.2660384528238,36.09342608838671,2357
              -112.2668139013453,36.09251058776881,2357
              -112.2677826834445,36.09189827357996,2357
              -112.2688557510952,36.0913137941187,2357
              -112.2694810717219,36.0903677207521,2357
              -112.2695268555611,36.08932171487285,2357
              -112.2690144567276,36.08850916060472,2357
              -112.2681528815339,36.08753813597956,2357
              -112.2670588176031,36.08682685262568,2357
              -112.2657374587321,36.08646312301303,2357   
            </coordinates>
          </LinearRing>
        </outerBoundaryIs>
        <gx:drawOrder>8</gx:drawOrder> 
      </Polygon>
    </Placemark> 

  </Document>
</kml>

So As you can see in the above kml I've tried to use the gx:drawOrder element to sort the line strings & the polygons into drawing layers. BUT... if you load this in the kml interactive sampler or even Google Earth (free desktop edition) the geometry primitives only z order sort among "like primitives". That is, the line strings are sorted only against other line strings and the polygons are only sorted against other polygons.

In this case you can see that both "line 1" and "line 2" have draw orders of < "Polygon 2" & I as such I was expecting "polygon 2" to draw over the top of everything. But that is NOT the case.

In the end I've had to use altitude values to implement the z order that I want, but it's quite an unsatisfactory solution as most people view kml geometry using an isometric projection & the altitude values cause my geometry to skew.

What I'd like to know is this:

  1. Is this the expected behavior of gx:drawOrder? The document around the element is sparse & it even says that it's only applicable to the line string, but according to the xsd is should be applicable to all geometry primitives (which it appears to be... well at least to polygons as well anyway...)

  2. Is there a way to get the gx:drawOrder to be applicable over all geometry primitives?

Thanks in advance!

1
Note the documentation only mentions gx:drawOrder with line strings not polygons nor does it mention the behavior of drawOrder across different geometries (lines. rings, and polygons). You would expect the drawOrder to work the same over all primitives but looks like GE draws the features in groups by type: overlays first, then polygons, followed by lines and point data where drarOrder is applied only within a group. - CodeMonkey

1 Answers

0
votes

The KML documentation only mentions <gx:drawOrder> with respect to line strings not polygons nor does it mention the behavior of drawOrder across different geometries (lines, rings, and polygons). The drawOrder support for Polygons is undocumented but was reported as an issue in the bug tracker.

You would naturally expect the drawOrder to work the same over all geometry primitives, but looks like Google Earth draws the features in groups by type: polygons, then ground overlays, followed by lines and point data where drawOrder is applied only within a group. ScreenOverlays are drawn last so they are always on top.

This means that a polygon with drawOrder=2 overlapping a line with drawOrder=1 still shows the polygon under the line. Also, even if a polygon has a higher value drawOrder and overlaps a GroundOverlay (aka Image Overlay), the polygon is drawn first and hidden under the GroundOverlay.

gx:DrawOrder is not part of the OGC KML 2.2 standard. It's a Google KML Extension so Google defines how it works. Also means Google can change how it works.