Search code examples
kmlgoogle-earth

How to made KML doesnt import order of multigeometry


Hello Im writing some KML and when and I create the multigeomtry in the order

PlaceMark A PlaceMark B

I cant select PlMark A beceause B is bigger, but when I have

PlaceMark B PlaceMark A

Yes, because I think A is smaller and it was the last in be grapicated, my question is I cant have the Placemarks In order,there are any option in Kml to made selectable all the elements.

Thanks.

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Document>
<StyleMap id="StyF1"><Pair><key>normal</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7d0000ff</color></PolyStyle></Style></Pair><Pair><key>highlight</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7aFFFF8C</color></PolyStyle></Style></Pair></StyleMap>
<StyleMap id="StyU1"><Pair><key>normal</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7d0000ff</color></PolyStyle></Style></Pair><Pair><key>highlight</key><Style><IconStyle><Icon></Icon></IconStyle><PolyStyle><color>7aFFFF8C</color></PolyStyle></Style></Pair></StyleMap>

<Placemark>
    <name>A</name>
    <description>
    </description>
    <visibility>1</visibility>
    <tessellate>1</tessellate>
    <styleUrl>#StyU1</styleUrl>
    <MultiGeometry>
        <Point>
            <coordinates>-0.18806,39.78366</coordinates>
        </Point>
        <Polygon>
        <outerBoundaryIs>
            <LinearRing>
                <coordinates>-0.18806,39.78261
                -0.18701,39.7844286533479
                -0.18911,39.7844286533479
                -0.18806,39.78261</coordinates>
            </LinearRing>
        </outerBoundaryIs>
        </Polygon>
    </MultiGeometry>
</Placemark>

<Placemark>
    <name>B</name>
    <description>
    </description>
    <visibility>1</visibility>
    <tessellate>1</tessellate>
    <styleUrl>#StyF1</styleUrl>
    <MultiGeometry>
        <Point>
            <coordinates>-0.18806,39.78501</coordinates>
        </Point>
        <Polygon>
        <outerBoundaryIs>
        <LinearRing>
            <coordinates>-0.18806,39.78261
            -0.18566,39.7867669219382
            -0.19046,39.7867669219382
            -0.18806,39.78261</coordinates>
            </LinearRing>
        </outerBoundaryIs>
        </Polygon>
    </MultiGeometry>
</Placemark>

</Document></kml>

Solution

  • If you want to order one line or polygon over another you can use the <gx:drawOrder> element.

    Features with higher <gx:drawOrder> values are drawn on top of those with lower values so for example if you use a drawOrder of 2 for A and 1 for B then A is drawn on top of B. In other words, the features with lower drawOrder values are drawn first.

    Don't forget to add the xmlns:gx="http://www.google.com/kml/ext/2.2" declaration to the kml tag and note that the documentation says it only applies to LineStrings but it also applies to Polygons and LinearRings.

    
        <?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">
         ...
          <Placemark>
            <name>A</name>
            <MultiGeometry>   
                <Point>
                    <coordinates>-0.18806,39.78366</coordinates>
                </Point>
                <Polygon>
                    <gx:drawOrder>2</gx:drawOrder>
                    ...
                </Polygon>
             </MultiGeometry>
          </Placemark>
    
          <Placemark>
            <name>B</name>
            <MultiGeometry>
                <Point>
                    <coordinates>-0.18806,39.78501</coordinates>
                </Point>
                <Polygon>
                    <gx:drawOrder>1</gx:drawOrder>
                    ...
                </Polygon>
             </MultiGeometry>
          </Placemark>
    
    

    Reference: https://developers.google.com/kml/documentation/kmlreference#gxdraworder