Modify position data from loaded czml file

Is it possible to modify the position data from a czml entity loaded into the viewer? I’m able to query the position at a given time but haven’t been able to figure out how to get the array of position points and then modify them.

Here is how I’m loading the czml:

var czmlDataSource = new Cesium.CzmlDataSource();

czmlDataSource.processUrl("…/czml/test.czml");

viewer.dataSources.add(czmlDataSource);

I can then get to an entity to get things like the id or query the position:

var czmlEntities = czmlDataSource.entities.entities;

var entity = czmlEntities[0];

var id = entity.id;

var position = entity.position;

var cartesian = position.getValue(viewer.clock.currentTime);

Thank you in advance for any guidance or if this is even possible at all.

I am not sure of a way to actually get the array of position points out of a loaded czml, but I can help you with updating the position of an existing object.

To send new positions for a previously loaded czml object, you can just load another czml containing the same id as the object you want to modify. For example, lets say you loaded a czml object called ‘car’ that is set at a particular position, not moving. To change that position write a czml that contains only the id and new position property.

[

{

“id”:“car”,

"position":{

  "cartesian":[

    -2379754.6637012,-4665332.88013588,3628133.68924173

  ]

}

}

]

``

If you’re using a time-stamped one the same thing applies, just add the time-since-epoch into your czml. This way you can either extend the time boundary or add more points in between existing positions for more accurate interpolations. You can write the czml’s however you like, with the writer tools or with an in-line javascript function like some of the sandbox examples.

This property also extends to any other czml option, you can change a path color, lead times, etc. Hopefully that makes sense and someone else can help with retrieving the array of positions for you.

Depending on how your data is defined, you may or may not be able to change it in-place. For example, ConstantProperty and ConstantPositionProperty have a setValue function.

Alternatively, you can replace the property with a new property containing your new data, to redefine how an entity’s position is calculated.

var newPosition = new Cesium.SampledPositionProperty();

newPosition.addSample(…)

entity.position = newPosition;

Thanks guys!

Here is what I did to update the dynamic position data from my entity so that it sits on terrain. The only issue is that I lose my original points in the position property and replace them with a fixed step size of 0.1 seconds. Not too big of a deal but its no longer the original data with the updated height as I was going for.

var position = entity.position;

var start = entity.availability.start;

var stop = entity.availability.stop;

var time = start;

var positionArray = ;

var timeArray = ;

while (Cesium.JulianDate.lessThanOrEquals(time,stop)) {

var cartesian = position.getValue(time);

var height = scene.globe.getHeight(Cesium.Ellipsoid.WGS84.cartesianToCartographic(cartesian));

var cartographic = ellipsoid.cartesianToCartographic(cartesian);

positionArray.push(new Cesium.Cartesian3.fromDegrees(Cesium.Math.toDegrees(cartographic.longitude),Cesium.Math.toDegrees(cartographic.latitude), height));

timeArray.push(time);

time = Cesium.JulianDate.addSeconds(time, .1, new Cesium.JulianDate());

}

var newPosition = new Cesium.SampledPositionProperty();

newPosition.addSamples(timeArray, positionArray)

entity.position = newPosition;

``

Looks like this is causing some sort of memory issue which ends up crashing the browser. Below is a link to sample code that you can paste into Sandcastle. Once the terrain is loaded, click the ‘Update Position’ position button. Then as the scene animates you should see the browser memory increase until the browser crashes. I’m sure I could be doing something wrong but it seems to happen only if I send the following line of code to change the entity position.

entity.position = newPosition;

``

You can skip the first minute or so of time but then let the scene animate at 1x and the browser should crash after another minute or so.

https://drive.google.com/file/d/0BwlMkc-EFmSkNWJtUFdPbjh0OTQ/view?usp=sharing

Are you using Chrome? There is a memory leak that has not been fixed in stable (Chrome 39) yet but will hopefully be fixed with Chrome 40. If you are using Chrome, can you try this in Firefox and see if it still crashes?

Thanks Matt! I was using Chrome and just tried it in Firefox and no longer see the crashing behavior.

Glad to hear it. This has been a long standing issue; but is definitely fixed in their development builds. Hopefully in a month it will be in stable.

Hi Kevin…

I know it has been awhile but I am trying to change the position of an multiple entities periodically by reading the new file with new coordinates.

I selected your link and that code is not available.

Would you be able to send me your example code so I can test it out in the sandcastle ?

This may be what I need to get my google kml network link data to work without performance or browser crashing issures

Thank You

Carlo

Try this: https://drive.google.com/file/d/0BwlMkc-EFmSkaEtWRmZWdUk2NnM/view?usp=sharing