Search code examples
google-mapskml

Whole world KML with innerboundaries displays wierd in google maps


I have a kml file that looks like the next:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
  <Document>
    <name>KML file with polygon for bird species range</name>
    <description>Source various books and websites</description>
    <Style id="rangecolour">
      <LineStyle><color>660000FF</color><width>1</width></LineStyle>
      <PolyStyle><color>660000FF</color></PolyStyle>
    </Style>
    <Style id="linecolour">
      <LineStyle><color>660000FF</color><width>3</width></LineStyle>
    </Style>
    <Placemark><name>distribution/range</name>
      <description></description>
      <styleUrl>#rangecolour</styleUrl>
      <Polygon>
        <tessellate>1</tessellate>
        <altitudeMode>clampToGround</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>
              -180.0,180.0,0.0 
              -180.0,-180.0,0.0 
              180.0,-180.0,0.0 
              180.0,180.0,0.0 
              -180.0,180.0,0.0 
            </coordinates>
          </LinearRing>
        </outerBoundaryIs>
        <innerBoundaryIs>
          <LinearRing>
            <coordinates>
              153.056374,-27.500658,0.0 
              153.056374,-27.524105,0.0 
              153.093109,-27.524105,0.0 
              153.093109,-27.500658,0.0 
              153.056374,-27.500658,0.0 
            </coordinates>
          </LinearRing>
        </innerBoundaryIs>
      </Polygon>
    </Placemark>
  </Document>
</kml>

My intention is to do a "hole" inside the entire world to get shadded all the world outside a boundaries (this is just an example), but, for some reason that I don't know, in Google Earth works fine, but in google maps (API v3, at least... is the one I'm using with "google.maps.KmlLayer(url.kml)"...) not.

Does anyone know why?


Solution

  • The outer boundary is:

            <coordinates>
              -180.0,180.0,0.0 
              -180.0,-180.0,0.0 
              180.0,-180.0,0.0 
              180.0,180.0,0.0 
              -180.0,180.0,0.0
            </coordinates>
    

    which is a very narrow square (between -180 and +180)

    The KML displayed below uses this for the polygon (the whole world with a small hole):

    <Placemark><name>distribution/range</name>
      <description></description>
      <styleUrl>#rangecolour</styleUrl>
      <Polygon>
        <tessellate>1</tessellate>
        <altitudeMode>clampToGround</altitudeMode>
        <outerBoundaryIs>
          <LinearRing>
            <coordinates>
              180,85 
              90,85 
              0,85 
              -90,85 
              -180,85 
              -180,0 
              -180,-85 
              -90,-85 
              0,-85 
              90,-85 
              180,-85 
              180,0 
              180,85 
            </coordinates>
          </LinearRing>
        </outerBoundaryIs>
        <innerBoundaryIs>
          <LinearRing>
            <coordinates>
              153.056374,-27.500658,0.0 
              153.093109,-27.500658,0.0 
              153.093109,-27.524105,0.0 
              153.056374,-27.524105,0.0 
              153.056374,-27.500658,0.0 
            </coordinates>
          </LinearRing>
        </innerBoundaryIs>
      </Polygon>
    </Placemark>
    

    This works for me with geoxml3, doesn't work with KmlLayer.

    Another example

    I don't know why, the Google Maps KML parser and KmlLayer have pretty much always been broken this way.

    Related question: shading area outside of kml boundary