SampledPositionProperty

Hello,

I've been looking at SampledPositionProperty to define positions for an entity at different times. I found a few examples and have got it working but without heading. With the SampledPositionProperty, I can add a sample including time and position, but this does not include the heading/orientation. How can I include this?

var property = new Cesium.SampledPositionProperty();
var position = Cesium.Cartesian3.fromDegrees(latitude, longitude, 0);
var time = new Cesium.JulianDate();
Cesium.JulianDate.now(time);
property.addSample(time, position);

Thank you!

If you are talking about heading for a billboard, then you would simply assign the SampledProperty(Number) to the entity.billboard.rotation property. If you are talking about orientation, like a 3D model, then you would assign a SampledProperty(Quaternion) to the entity.orientation. You can optionally use VelocityOrientationProperty for entity.orientation to derive it from the position property.

Perfect. Thanks again Matthew.

Matthew,

Is it possible to turn off interpolation only for specified timeframes on a per entity basis?

For example, if I have an entity that has data from 12:00:00 to 13:00:00 and generally want interpolation turned on. However, there may be a gap of data from 12:30:00 to 12:40:00 (known ahead of time). Is there a way to tell Cesium to hold the last position during this time range only, instead of slowly interpolating an incorrect path from the position at 12:30:00 to the position at 12:40:00.

Maybe by having 2 adjacent samples with the same location but one set at 12:30:00 and the other at 12:40:00 ? So the interpolation would be zero speed, same as being off.

Hyper Sonic, I haven't tested this yet, but logically it's a good idea and seems like it should work. I can't believe I didn't think of this myself. As usual, thank you for the help!

Hyper’s, solution only works in the case of linear interpolation, which is not usually used for position and orientation (but if that’s what you are using, it will work). The correct way to do this is via CompositePositionProperty, which lets you manage a collection of intervals where each interval is associated with a different property.

Here’s some code to get you started.

//The sampled property is our motion, the constantProperty is the time it’s stopped.

var sampledProperty = new Cesium.SampledPositionProperty();

var constantProperty = new Cesium.ConstantPropertyProperty();

//Create a composite property

var property = new Cesium.CompositePositionProperty();

//Create an interval that covers the entire time span and associated it with our sampledProperty

property.intervals.addInterval(new Cesium.TimeInterval({

start : Cesium.Iso8601.MINIMUM_VALUE,

stop : Cesium.Iso8601.MAXIMUM_VALUE,

data : sampledProperty

}));

//Add a new interval over top of the above. This new interval will now return a constant position for the provided time.

//The sampledProperty interval will actually be split into 2 internally.

property.intervals.addInterval(new Cesium.TimeInterval({

start : new Cesium.JulianDate(), //Start of constant position

stop : new Cesium.JulianDate(), //End of constant position

data : constantProperty

}));

Any further intervals you add will overwrite what’s already in there, so you could easily manage a series of stops and starts. Of course the above is also not completely correct because what you really want to do is separate that sampledProperty into 2 sampled properties (1 for before the stop and 1 for after). This will ensure interpolation does not cross a moment of discontinuity which is created by having a velocity of 0.

Hopefully this all makes sense. It all depends on how much you care about the fidelity of your visualization and whether you are using anything other than linear interpolation or not. I’ll make a note to add a Sandcastle example that does everything correctly with a car model or something.

Matthew, thank you for the detailed explanation and sample code! This is more like what I was hoping for as an official method and yes it makes sense.

Also, thanks again for all your help and patience with my questions while I'm still trying to learn and get familiar with Cesium. Hopefully soon I will start answering the questions instead of asking them :wink: