- KML: Dynamic Updating

Dynamic Updating

Overview

Overlay images, models or entire KML files loaded into Google Earth can be dynamically refreshed based on parameters controlled by view or time-based settings. This is an essential abilities for: files that contain data that is changing with time; providing links to KML without having to immediately access it in Google Earth; updating the KML viewed by clients on the server-side.

New KML: <Change> <cookie> <Create> <Delete> <expires> <flyToView> <httpQuery> <ItemIcon> <Link> <linkDescription> <linkName> <linkSnippet> <maxSessionLength> <message> <minRefreshPeriod> <NetworkLink> <NetworkLinkControl> <refreshInterval> <refreshMode> <refreshVisibility> <state> <Update> <viewBoundScale> <viewFormat> <viewRefreshMode> <viewRefreshTime>

Tutorial

Network Links

(1) The <NetworkLink> element references a KML or KMZ on any local or remote network. In Google Earth create a <NetworkLink> that references one of your KML files (Hint: Use the Add menu).
(2) Copy the <NetworkLink> KML into a text editor and view the basic KML structure.
(3) Swap the <Url> element for <Link> (The <Url> element still works but has been depreciated in KML 2.2 in favor of <Link>).
(4) Add a <LookAt> or <Camera> view into the target KML (i.e. the KML the link references) and under <NetworkLink> add <flyToView>1</flyToView>.
(5) Save and open in Google Earth.
(6) Navigate away from the default view and reload the Network Link.
(7) View your target KML in a text editor and read the documentation on Network Link elements to understand the behavior in step (6).

Refreshing Features

The <Link> element can be used to refresh any image overlay or model directly. An example is show below for a refreshing webcam image shown in a screen overlay.

AugiCam.kml



The icon used in the sidebar list will reflect the state of a link fetch:



The and elements can be used specify the icon and state within for Network Links and Folders.

Links

(8) Create a Network Link that fetches webcams.kml.
(9) Add KML that refreshes the network link every 2 minutes by editing the KML in a text editor (Hint: read the google documentation).
(10) Add KML that refreshes the network link 2 seconds after camera movement stops by editing the KML in a text editor.

Network Link Control

The behavior of files fetched by the Network Link is controlled by <NetworkLinkControl>, which is a direct child of the <kml> element. See Google's documentation on elements specific to <NetworkLinkControl> for a description of the following options:



Updating Previously Loaded KML

The <Update> element specifies an addition, change, or deletion to KML data that has already been loaded into Google Earth using a Network Link. The <targetHref> specifies the file that is to be modified. To identify specific objects to update, these objects must have an explicit "id" defined which is referenced using "targetId". To demonstrate this graphically:



a) A NetworkLink loads the "original" KML file into Google Earth. An element that will later be updated needs to have an explicit id defined when it is first specified. The ids must be unique within a given file.

(b) Another NetworkLink loads a second KML file containing the updates (any combination of Change, Create, and Delete) to the KML object(s) that have already been loaded. The update file contains two references to identify the original KML data,

(c) To locate the objects within Google Earth, the Update element uses the targetHref element to identify the original file that defined the object(s) to be modified. To identify the object(s) to be modified or the container for new objects, the Change, Create, and Delete elements contain a targeted attribute that references the ids of those objects (targeted).

(11) Open Point_nload.kml in Google Earth.
(12) Expand the file in the sidebar and view the list of contents.
(13) Open Update_nload.kml in Google Earth.
(14) View the list of contents of Loads Point. What has changed?
(15) Deselect both Network Links.
(16) Check the box to activate Loads Point. Right click and select "refresh". Now what has happened to the contents?
(17) Check the box to activate Update.
(18) View the KML of these files in a text editor and on Google's example page to understand how it works.

Exercise

Create a KML file that can be used to load three different KML files (e.g. see the KML examples page) through network links.