The KML Behind Network Links

Posted on September 20, 2007. Filed under: Google Earth, Network Links |

In my last post on Google Earth Network Links I covered the basic concepts of how this functionality can be used to provide dynamic access to geographic data in the Google Earth viewer.  We briefly discussed the KML elements that are used to define a Network Link, but in this post I’d like to expand on the KML elements used to enable this functionality.

<NetworkLink>
The <NetworkLink> element inherits from the <Feature> element as do the <Placemark>, <Overlay>, and <Container> elements.  You can get more information on the KML Object Model here.  Because it is descended from <Feature>, <NetworkLink> inherits a number of child elements which define the basic characteristics of a Network Link which I won’t go into detail on here (see the Feature object in the KML Object Model for details).  The elements specific to <NetworkLink> include <Link>, <refreshVisibility>, and <flyToView>.  A <Link> with an <href> child element specifies the KML/KMZ file to load, and this file can either be from a local or remote source.  For example, the following code shows how to create a link to a remote KML source:

<Link>
     <href>http://www.geospatialtraining.com/NetworkLink/SeePlacemarks.kml</href&gt;
</Link>

In addition to linking to an existing KML/KMZ file you can also link to CGI scripts written in languages such as Python, Perl, Ruby, and others which can be created to provide dynamic data.  We’ll save this topic for another post.

Another element of <NetworkLink> is <refreshVisibility> which by default is set to a value of “0″ and leaves the visibility of features within the control of the Google Earth user.  Setting the value to “1″ resets the visibility of features each time the Network Link is refreshed.

The <flyToView> element when set to a value of “1″ causes Google Earth to fly to the view of the root element in the refreshed file.  <LookAt> defines the camera for the view. The camera is the current viewpoint of the Google Earth viewer and includes things like the latitude, longitude the camera is looking at along with the altitude, range, tilt, and heading.

Here then is a quick KML code sample for creating a Network Link:

<NetworkLink>
     <name>Test Placemark</name>
     <visibility>0</visibility>
     <open>0</open>
     <description>This is a KML Network Link Test</description>
     <refreshVisibility>0</refreshVisibility>
     <flyToView>0</flytoView>
     <Link>
          <href>http://www.geospatialtraining.com/NetworkLink/SeePlacemarks.kml</href&gt;
     </Link>
</NetworkLink>

<NetworkLinkControl>
Now let’s move on to the <NetworkLinkControl> element which controls the behavior of files fetched by <NetworkLink>.  There are a handful of child elements of <NetworkLinkControl>, but the most important are <minRefreshPeriod>, <expires>, and <Update>.  Let’s start with <minRefreshPeriod>.  This element specifies the minimum allowed time between fetches of the file in seconds.  Therefore, if you want the minimum update time to be one hour this element would be set to <minRefreshPeriod>3600</minRefreshPeriod>.  The <expires> element is used to specify a date/time when the link should automatically be refreshed. 

<Update>
The child element of <NetworkLinkControl> that I want to highlight in particular is the <Update> element.  <Update> is used add, edit, or delete data from an existing KML file that has already been loaded.  This is powerful stuff! The <targetHref> child element specifies the KML/KMZ file that you would like to alter in some way.  Three child elements (<Change>, <Create>, and <Delete>) of <Update> are used to perform the editing tasks.  The <Change> element modifies the values of a geographic object that has already been loaded with <NetworkLink>.  Within the <Change> element, the object to be modified must include a targetID attribute that references the original element’s id.  The <Create> element is used to add new objects, and the <Delete> element deletes features that have already been loaded.  Here is an example of using the <Change> element with <Update>.

<NetworkLinkControl>
     <Update>
          <targetHref>http://www.geospatialtraining.com/GE/Data/Points.kml</targetHref&gt;
          <Change>
               <Point targetId = “point001″>
                    <coordinates>-97.23,35.35,0</coordinates>
               </Point>
           </Change>
     </Update>
</NetworkLinkControl>

The ability to add, edit, and delete data from an existing KML/KMZ file served through a Network Link opens up a lot of possibilities for delivering dynamic Google Earth applications to your end users.  This functionality combined with CGI scripting through Network Links makes it even more powerful.  For more information on the update functionality provided through <NetworkLinkControl> please click here.

In the next post on Network Links I’ll show you how to use a CGI script to dynamically generate data served through a Network Link.

Our “Mastering KML for Google Earth” course covers Network Links in great detail along with all the other ways that you can create custom Google Earth applications using KML.

About these ads

Make a Comment

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Liked it here?
Why not try sites on the blogroll...

Follow

Get every new post delivered to your Inbox.

Join 47 other followers

%d bloggers like this: