Porting over GE to Cesium using network links with KML files

I have a project that I am converting from GE to Cesium that relies heavily on Network Links...using KML files. I understand there is support for network links using Cesium and KML files. Does anyone have any examples or documentation that supports this ? I would like to try this first to see what the performance is like before possible converting my KML files to CZML.

Hi

Here is a sandcastle example that loads KML

Here is the reference documentation

http://cesiumjs.org/Cesium/Build/Documentation/KmlDataSource.html

Network links should just work. The one caveat is that onRegion updates aren’t yet implemented. If there are a lot of network links updating frequently this has the potential to get slow as we have to create entities on the main thread, since we don’t have access to threading like a native application would.

Thanks

Yes >> I have seen these examples and reference documentation.

There is no much on network links however.

Here is the GE version

// // create a Link object
var link = ge.createLink("");

var kmzUrl = ‘http://’ + server + ‘/aftweb/google_earth/active/’ + tgt + ‘.kmz’;
link.setHref(kmzUrl);

link.setRefreshMode(ge.REFRESH_ON_INTERVAL);

I am looking for examples of using network links with Cesium that I can port over. Also what version of Cesium has network links ?

Thanks

There isn’t a KML API within Cesium, we just load the document into the generic Entity layer of Cesium. NetworkLinks are a special case that is specific to KML and are handled internally within the KmlDataSource.

In order to do what you want, you would need to generate the actual KML and load it into a KmlDataSource like this

// Start document

var kml = ‘<?xml version="1.0" encoding="UTF-8"?>’;

// Add Network Link

kml += ‘’;

kml += ‘http://’ + server + ‘/aftweb/google_earth/active/’ + tgt + ‘.kmz’

kml += ‘onInterval’;

// Close document

kml += ‘’;

var parser = new DOMParser();
KmlDataSource.load(parser.parseFromString(kml, “text/xml”), {

camera : scene.camera,

canvas : scene.canvas

});

–Tom

Hi Tom,

I will give you recommendation a shot. It was not clear to me on how to add the NetworkLink in the KmlDataSource documentation.

This is what I am doing now.

viewer = new Cesium.Viewer(‘geContainer’,
{ timeline: false,
animation: false
});

ge = new Cesium.KmlDataSource();

var options = {
camera : viewer.scene.camera,
canvas : viewer.scene.canvas
};
kmlUrl = ‘google_earth/active/’ + “localTracks” + ‘.kml’;

//follow your instructions up until close document.

// Would the following lines of code work?

 viewer.dataSources.add(ge.load(kmlUrl,options))

.then( function (dataSource) {
viewer.flyTo(dataSource.entities);

Thank You!!

I’m a little lost by your question.

You can either load a KML document (‘google_earth/active/’ + “localTracks” + ‘.kml’) like your code does or you can generate a KML document with a network link in it like my code does. You cannot load an existing document and add a network link to it, which it appears you are trying to do. I would need to see the full code example to be sure.

Hi Tom,

Here is the GE code I am trying to port.

function createNetworkLink(tgt) {
var networkLink = ge.createNetworkLink("");
networkLink.setDescription(“NetworkLink open to fetched content”);
networkLink.setName(“Open NetworkLink”);
networkLink.setFlyToView(false);
//
// // create a Link object
var link = ge.createLink("");

var kmlUrl = ‘http://’ + server + ‘/aftweb/google_earth/active/’ + tgt + ‘.kml’;

link.setHref(kmlUrl);

link.setRefreshMode(ge.REFRESH_ON_INTERVAL);

link.setRefreshInterval(3.0);

// attach the Link to the NetworkLink
networkLink.setLink(link);
//
currentKmlObjects[tgt] = networkLink;

//
//add the NetworkLink feature to Earth
ge.getFeatures().appendChild(networkLink);

What I am doing now is I have a KML file that is written to periodically… The network link will automatically update the kml icon on the

google map based on the periodic rate.

Right now the code I sent you gets called every 5 seconds (so it refreshes the location since I may have a new file with a different lat/long in )

This is not ideal for many reasons. Once being the browser will eventually run out of memory and crash.

So I was trying to find an example to port over the network link to cesium using a KML file that is lat/long is updated periodically so the movement shows up on the map.

I hope this is clear… You can see what I am doing with Cesium to get the kml data lat/long to show up on the map.

Let me know…

Thank you

Hi Tom,

I am assuming there is no equivalent code for Cesium to accomplish what I have for GE ?

How do you recommend I port this code over to Cesium… Right now I am refreshing the Map

and re-read the KML that may have changed and displaying it on the map… The network links on GE

will update the map with the new data periodically with out refreshing the Map for its new position

Thanks

Hello,

Sorry, but I don’t have a good way to recreate this functionality. Cesium has KML network link support, but we don’t have the capability to create a nework link on the fly the way the Google Earth Plugin does.

Instead, you can use CZML and WebSockets to update the CZML periodically. See the discussion in this forum post: https://groups.google.com/forum/#!topic/cesium-dev/fntbTCvo1Qk

You can call CzmlDataSource.process to process a new packet of czml whenever a message is posted by the WebSocket. The packet can include a new position and icon for the entity.

Best,

Hannah

Hi Hannah,

Thank you for your reply… I will look into your suggestions.

Regards,

Carlo

Ok I am back looking at this… So we are staring to convert the kml file to a CZML format.

I want to make sure I understand how to do this with CZML since we are converting the code.

Our present system works as follows.

We have an application running on the same server we are running the Cesuim map and web application on the same machine as well.

The present application is writing to a file in a particular directory (KML file) The Web application sets up at initialization a network link for this data
and

The google network link reads this file periodically using Google network Link periodic refresh interval also set up at initialization.

At the interval the positon(lat/long) of the element us updated on the map via an icon.

So over time we can see the element moving on the map. (again google map)

So to be clear is the only way to get this functionality to run with Cesium is to use WebSockets ? If the Web application periodically

Has a thread running and reads the CZML file in a particular directory and then displays the data with new position would this work as well

Without refreshing the browser to show the movement ? So would I be able to call the czmlDataStreamSource.process by parsing the file?

The application running will have to create czml_writer function in C++ and since on the same machine as Web browser did not know if we needed WebSockets

Interface to make the element move on the Cesium map.

I hope this is clear,

Thank you for your help,

Carlo

On Behalf Of Hannah Pinkos

If you’re simply trying to refresh a data file periodically, you can do that using the normal setInterval function. In the callback, then you can reload the KmlDataSource or CzmlDataSource into Cesium, whichever format you’re using.

WebSockets would allow for a more sophisticated approach where the server pushes more specific targeted updates, rather than reloading all the data every time.

I do not want to refresh the browser… the data file is being refreshed by another application running on the

The same machine that has the apache server running on it. My web application will read this file from a directory and display it on the

Cesium map. (Again this was done on Google map with network links.)

I just want the element’s lat/long updated on the Cesium map to show it moving over time by reading the

Kml or czml file to get the updated lat/long then display it on the Cesium map with the new lat/long so it moves.

Right now I have a periodic call in my web page to read the file in (kml) and in order for it to update on the Cesium map to the new position I have to

Refresh the Web page… and over time I run out of memory.

Does this make sense ?

Do you have an example on the setInterval function if will do the job ?

Thanks,

Carlo

On Behalf Of Scott Hunter

setInterval is a standard browser function, and not specific to Cesium.

https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setInterval

Does this function support all the major browsers ?

On Behalf Of Scott Hunter

Yes, it’s a standard browser function. MDN pages usually have a compatibility table at the bottom of the page.

I am using kml files… The interval seems to work fine.

Another question I have is I select the icon on the map to show me the KML data. Pops up on the Cesium screen.

I have a 3 second interval. Once the refresh occurs the popup screen goes away. Is there a way to keep this information up on the screen

So I can see the information change. Thanks…

On Behalf Of Scott Hunter

Looks like the map eventually crashes using the browser interval… Also at every interval everything on the map gets refreshed.

Ran for a while and the map then disappeared in my web page.

Any other suggestions ?

Thanks

Carlo

On Behalf Of Scott Hunter

Here is the error I get.

An error occurred while rendering. Rendering has stopped.

RuntimeError: Program failed to link. Link log: Internal linking error Error at t (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:418:7991) at p (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:432:1662)
at _ (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:432:3651) at C.prototype._bind (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:432:5384) at G (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:451:9085) at q.prototype.draw (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:451:17598)
at r.prototype.execute (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:431:4930) at m.prototype.execute (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:454:29390) at we (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:461:9320) at Ae (http://10.37.208.115/aftweb/Build/Cesium/Cesium.js:461:10424)

OK

On Behalf Of Scott Hunter

Looks like I am at a dead end with .KML functionality.

I am trying to find out if CZML will help me.

The refresh interval will refresh browser and display new data location on the map but clears and redraws every time.

What I am asking is with Google Earth Plugin we used Network Links and Network links interval to

Read the new position file and update the display. This did not update the browser like refresh interval does.

Network links in google plugin refreshed the position entry on the map and not the whole map so other items

Displayed did not clear on refresh.

Is there an equivalent in Cesium with CZML (kml network links is not there) that this can be done.

I have an application I am trying to port over.

If not is there any suggestions or any idea if network links (google/.kml) will be ported to Cesium or any work around I can use in

The meantime.

Thank You

Carlo