How to detect when SampledPositionProperty reaches it's last sample

I’m setting up an animation of points along a polyline. I do this by precalculating the time offset for each point of the animation and then creating a new SampledPositionProperty for every point with the sample times adjusted by an offset.
However I want to ‘restart’ the animation for each point when it reaches the end of the polyline. Since there are multimple entities animating at the same time, I can’t let the Viewer’s clock loop back as in this sandcastle, because each instance needs to have it’s own loop.
I was initially thinking I might listen for an event that indicates the final sample of the SampledPositionProperty is reached, and then creating a new SampledPositionProperty with new times for the instance.
Is there a way to determine that a SampledPositionProperty has reached it’s end time?
Or is there a better way to achieve what I want.
This sandcastle illustrates what I’m trying to achieve.
For each point I want it to recalculate it’s SampledPositionProperty after it reaches the end of the polyline so that it’s animation starts over at the beginning.

Hello @markchagers , It’s just because you are not setting viewer’s clock’s current, start and endtime. I’ve modified your sandcastle example.

Increasing sampledPropert time on reaching endPosition will be good idea to create flawless animation. It will require to compare each poin’t current position. You can approach following method to compare current time with end or start time:

// Just to comapre endTime and currentTime
viewer.clock.onTick.addEventListener(function (clock) {
  console.log(, endTime));
  • Regards
1 Like

@Jacky Apologies for not responding earlier (I was on holiday).
Thanks for the help, this looks like the missing part, I’ll be working on this later.