This project has moved. For the latest updates, please go here.

Network Link Refresh

Nov 20, 2013 at 1:23 PM
I have created a network link easily enough with the code, but what I cannot work out is how to set the parameters which allow the link to auto-refresh. I have found the RefreshMode and NetworkLinkControl objects, but can't work out how to connect them to the NetworkLink object.
// create the network link
NetworkLink networkLink = new NetworkLink();
networkLink.Name = "a name";
networkLink.Link = new Link();
networkLink.Link.Href = new Uri("http://somewhere.com/afile.kml");

// parameters to get link to refresh every second
RefreshMode refreshMode = RefreshMode.OnInterval;                                
NetworkLinkControl networkLinkControl = new NetworkLinkControl();
networkLinkControl.RefreshPeriod = 1;

// add to Document and Kml.Feature ....
document.AddFeature(networkLink);
kml.Feature = document
Can anyone help please?
Coordinator
Nov 20, 2013 at 8:38 PM
Just to clarify your question, are you trying how to generate a NetworkLink to send to the client or are you wanting the library to follow any NetworkLink it finds and download the relevant content? If it's the latter than unfortunately there isn't any support for this; the library is for parsing/creating the DOM of the KML document only.

However, if you want to create a document that instructs the earth browser (that's what the standard calls it) to fetch data at regular intervals then I think the process is something like this:
  • Create a Container element (such as Document) that contains a NetworkLink.
  • Point the NetworkLink to another file (I'll call it update.kml).
  • In update.kml the root element must be a Kml element that contains a NetworkLinkControl as its child.
  • The NetworkLinkControl can contain instructions for the earth browser to change its view (with a Camera or LookAt element) and/or update previously loaded Kml data in the original file (see here for some examples.
The above may not be 100% accurate as it's my interpretation from the specification, but it should hopefully point you in the right direction.

Also, there is an extension method on for the Update element in the SharpKml.Engine namespace that will add/change/remove the relevant elements from the KmlFile for you in case you've got to process the NetworkLinkControl yourself.

Hope it helps, let me know if you've got any queries,
Sam
Nov 21, 2013 at 1:20 PM
Sam - thank you for your reply. I was trying to create a document that was to instruct the earth browser.

I have solved the problem, and feel a bit stupid I didn't try it this way first. I took my KML and within Google Earth manually added the refresh parameters then looked at the resultant KML. This showed me that it is not the NetworkLink that has the refresh but the NetworkLink's Link parameter that does. The KML being:
    <NetworkLink>
        <name>My Placemark</name>
        <Link>
            <href>http://somewhere.com/afile.kml</href>
            <refreshMode>onInterval</refreshMode>
            <refreshInterval>7</refreshInterval>
        </Link>
    </NetworkLink>
This meant the SharpKml code had the necessary parameters so my C# code is:
// create the network link
NetworkLink networkLink = new NetworkLink();
networkLink.Name = "a name";
networkLink.Link = new Link();
networkLink.Link.Href = new Uri("http://somewhere.com/afile.kml");

// parameters to get link to refresh every second
networkLink.Link.RefreshInterval = 1;
networkLink.Link.RefreshMode = RefreshMode.OnInterval;

// add to Document and Kml.Feature ....
document.AddFeature(networkLink);
kml.Feature = document
I hope this can help someone else out in the future ;-)
Marked as answer by UKPAD on 11/21/2013 at 6:20 AM