The KML Behind 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.
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:
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:
<description>This is a KML Network Link Test</description>
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.
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>.
<Point targetId = “point001″>
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.