kmlgoogle-earth

Google Earth Web - network link


Question: do network links work in Google Earth Web (Web, not desktop)?

In Google Earth Web, I would like to call a kml file with network link.

Here is the code of init.kml the file imported manually in Google Earth:

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Folder>
    <name>QI01</name>
    <visibility>1</visibility>
    <open>1</open>
    <NetworkLink>
        <name>test</name>
        <visibility>1</visibility>
        <Link>
          <href>zzz.kml</href>
          <refreshMode>onInterval</refreshMode>
          <refreshInterval>5</refreshInterval>
        </Link>
        <flyToView>1</flyToView>
    </NetworkLink>
</Folder>
</kml>

And the zzz.kml code :

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
    <Placemark>
        <name>Place 1</name>
        <description>
        <![CDATA[
        Place number 1
        ]]>
        </description>
        <Point>
            <coordinates>-76.661005,46.428222,0</coordinates>
        </Point>
    </Placemark>
    <Placemark>
        <name>Place 2</name>
        <description>
        <![CDATA[
        Place number 2
        ]]>
        </description>
        <Point>
            <coordinates>-72.661005,42.468222,0</coordinates>
        </Point>
    </Placemark>
</Document>
</kml>

The two files are in the same folder on my Google Drive. I tried replacing <href>zzz.kml</href> by the url <href>https://drive.google.com/file/d/1bqcyrkqgNh9N8zKEr1gCI3o.../</href>, without success.

It does not work (zzz.kml alone works very well, but I can not open it with init.kml).

EDIT 1 :

I tried loading a public file (http://developers.google.com/kml/documentation/Point.kml). Code of my file calling point.kml is :

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<NetworkLink>
  <name>Loads Point.kml</name>
  <Link>
    <href>http://developers.google.com/kml/documentation/Point.kml</href>
  </Link>
</NetworkLink>
</kml>

It is a exemple from https://developers.google.com/kml/documentation/updates.

It doesn't work either.

EDIT 2 :

I did a copy/paste of the code in Notepad++ and I save the file with kml extension. I import the file using "New Project" button > "Import KML file from computer". The file opens in Google Earth, but not the data :

enter image description here

When I copy download the file pbs_lcet_trails.kml and I open it directly using using "New Project" button > "Import KML file from computer", not via an other file, it works :

enter image description here

After I import the KML file, I open devTool and :

enter image description here

I noticed that I have the same errors when I directly import the KML file with data, except "Unknown RPC Service : picker".

About the fact to create an object, I tried, but I can not import a KML file in a project. I have to manually add data, and it is not a workable solution.

Thanks again for your time.


Solution

  • Loading a KML or KMZ file via NetworkLink in Google Earth for web requires that the file be publicly accessible on the internet, AND it requires that the host server send appropriate CORS headers with the file, allowing the Earth client code to load the file. As a web app in the browser, Google Earth web enforces CORS (Cross Origin Resource Sharing), while the desktop app Earth Pro does not.

    The issue with files on your company intranet is probably that they are not accessible on the public web, which is required for the Earth web client to be able to fetch and render them.

    In the case of the public sample file you tried (http://developers.google.com/kml/documentation/Point.kml), it is NOT served with the correct CORS headers, since it was set up before Earth Web existed.

    You can see the CORS errors in your browser's dev console, like at the bottom of this screenshot: KML NetworkLink CORS error screenshot

    To show that NetworkLinks can work in Earth web, here is a public KML file served with CORS headers, that should work: https://www.gstatic.com/earthfeed/pbs/kml/pbs_lcet_trails.kml

    And here is a sample KML NetworkLink that will load it (save this as a local KML file and load it into Earth web):

    <?xml version="1.0" encoding="UTF-8"?>
    <kml xmlns="http://www.opengis.net/kml/2.2">
    <NetworkLink>
      <name>Lewis and Clark Trails</name>
      <Link>
        <href>https://www.gstatic.com/earthfeed/pbs/kml/pbs_lcet_trails.kml</href>
      </Link>
    </NetworkLink>
    </kml>
    

    Note that the requirements for public accessibility and CORS headers apply to many types of files loaded in Earth web, including image files used in balloons/panels, as overlays, or for icons; any audio or video files used in balloons; and of course any additional KML or KMZ files loaded via NetworkLinks.