Trying to use SampledPositionProperty to show most recent path and position from live data source

I'm now experimenting with using a path entity along with an ellipse and a sampled position provider to show the current position and path from a GPS source. I asynchronously load the times / positions into my sampled position property, and set the availability to be a 12 hour range forward from my start time.

I'm confused as to how to use the clock. The last data point I get will be behind the current system clock time. I want to render and hold position of the last data point I got. I've attempted setting the viewer clock's current time to match that last data point's time yet the ellipse & path are not updating to that time.

(I've also experimented with a short time loop and in that case I do see the ellipse traveling along the path)

This must be a solved problem.

Here is the code that updates the data & clock time for a new position:
let cdate = JulianDate.fromIso8601(data.timestamp);
this.viewerWrapper.getRaisedPositions({longitude:data.lon, latitude:data.lat}).then(function(raisedPoint){
        property.addSample(cdate, raisedPoint[0]);
        this.viewerWrapper.viewer.clock.currentTime = cdate.clone();
      }.bind(this));

Running on Chrome with Cesiumjs 1.27

thanks so very much for your help
Tamar Cohen
NASA Ames Research Center

I put in a hack to work around this, where I override the get value function to pull from a stored value if the computed value is undefined, and that seems to work.

property.getValue = function(time, result) {
            let myresult = property.getValueInReferenceFrame(time, ReferenceFrame.FIXED, result);
            if (myresult === undefined){
                myresult = context.cLastPosition[channel];
            }
            return myresult;
        };

However, I still think there must be a more elegant / correct solution ...

thanks

Hi Tamar,

Have you seen the clock demo? The “Reset Current Time” function shows you how to set an exact time with a Julian date object, and you can use a multiplier like in the “Slow down clock” function, but set it to 0 to pause the time.

Does that answer things? Thanks!

Gabby

I did; I tested my code using a ClockViewModel and using the viewer’s clock directly, and despite the fact that I set both of them to the julian date the entity did not move.

Can you explain the reason to use a ClockViewModel versus working with the viewer’s clock directly?

Can you clarify canAnimate and shouldAnimate?

Basically, the real world clock will progress past my last data point; if it is past that point I want to show the last good data that I have.

Thanks for your insight, the documentation was not clear enough for me to understand these things.

Thanks so much

Tamar

Hi Tamar,

The ClockViewModel is to separate the UI layer from the underlying logic, and is a common pattern when using Knockout for UI bindings. It basically watches for changes to the viewModel and then the reflects that change in the UI.

canAnimate and shouldAnimate act similarly. If either is set to false, the animation won’t happen.

I’m thinking that using the clock at all though might be going up the wrong path. Does a callback property look like it would be more appropriate in this situation?

Thanks,

Gabby

Hi Gabby,

Thanks – I left canAnimate and shouldAnimate to true, used the ClockViewModel instead of directly manipulating the clock, and included the custom getValue function to handle if the time is off the end, and it seems to work now!

Thanks for your support.

Tamar

And I’ve just discovered this:
property.forwardExtrapolationType = ExtrapolationType.HOLD;

This does exactly what I want! So I can remove my custom getValue function.

thanks

Tamar

1 Like

Awesome, I didn’t know about that! Thanks for the follow up.