trailTime of PathGraphics entity

Hi,

I am using a PathGraphics entity with SampledPositionProperty() to show a real-time line.

Depending on the situation I’d like to show the whole line, or only the last X seconds. The trailTime should be the way to make that happen.

I assumed that setting the (optional) trailTime to undefined would result in showing the complete line. But this does not work.

Should I simply set trailTime to e.g. 365 days, or are there other ways?

Thanks, Willem

Sandcastle example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var sampledPositions = new Cesium.SampledPositionProperty();

sampledPositions.setInterpolationOptions({

interpolationDegree: 1,

interpolationAlgorithm: Cesium.LinearApproximation

});

sampledPositions.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD;

sampledPositions.forwardExtrapolationDuration = 0;

var jsonTimedPoints = ‘[{“TimeStampUTC”:“2015-09-20T14:53:26.0000000Z”,“Latitude”:20.0,“Longitude”:7.0},{“TimeStampUTC”:“2015-10-20T14:53:26.0000000Z”,“Latitude”:44.0,“Longitude”:8.0}]’;

var latLonArrayDegrees = JSON.parse(jsonTimedPoints);

var scratchC3 = new Cesium.Cartesian3();

for (var idx = 0; idx < latLonArrayDegrees.length; idx++) {

var timedPoint = latLonArrayDegrees[idx]; // array with timestamp, latitude and longitude.

console.log('point  t=' + timedPoint['TimeStampUTC'] + '  lon=' + timedPoint['Longitude']);

sampledPositions.addSample(Cesium.JulianDate.fromIso8601(timedPoint['TimeStampUTC']), Cesium.Cartesian3.fromDegrees(timedPoint['Longitude'], timedPoint['Latitude'], 0.0, undefined, scratchC3));

}

var entity = viewer.entities.add({

id: ‘TestLine’,

path: { // this is a PathGraphics

material: new Cesium.Color(1, 0, 0, 1),

leadTime: 0,

//trailTime: 3652460*60, // works

    trailTime: undefined, // does not work

show: true,

width: 5

},

position: sampledPositions

});

Hi Willem,

Hmm, I’m not sure why this isn’t working. I’ll take a close look at it tomorrow.

-Hannah

Hi Hannah,

Do you have any news on this issue? The 365-days workaround works fine but it would be good to know if this will be improved some day.

Thanks, Willem

Hi Willem,

Sorry I didn’t get back to you! I thought I made a note somewhere but I must have lost it.

After some digging, I finally figured out what is going on.

There is a comment in the PathVisualizer that states:

        //Objects need to have either defined availability or both a lead and trail time in order to
        //draw a path (since we can't draw "infinite" paths.
        show = hasAvailability || (hasLeadTime && hasTrailTime);

``

So if you use the availability option on your paths, they should show up. Just set the stop date significantly far in the future. I think that’s a better workaround than using a super long trail time.

Here’s an example:

var viewer = new Cesium.Viewer(‘cesiumContainer’);

var sampledPositions = new Cesium.SampledPositionProperty();

sampledPositions.setInterpolationOptions({

interpolationDegree: 1,

interpolationAlgorithm: Cesium.LinearApproximation

});

sampledPositions.forwardExtrapolationType = Cesium.ExtrapolationType.HOLD;

sampledPositions.forwardExtrapolationDuration = 0;

var jsonTimedPoints = ‘[{“TimeStampUTC”:“2015-09-20T14:53:26.0000000Z”,“Latitude”:20.0,“Longitude”:7.0},{“TimeStampUTC”:“2015-10-20T14:53:26.0000000Z”,“Latitude”:44.0,“Longitude”:8.0}]’;

var latLonArrayDegrees = JSON.parse(jsonTimedPoints);

var scratchC3 = new Cesium.Cartesian3();

for (var idx = 0; idx < latLonArrayDegrees.length; idx++) {

var timedPoint = latLonArrayDegrees[idx]; // array with timestamp, latitude and longitude.

sampledPositions.addSample(Cesium.JulianDate.fromIso8601(timedPoint['TimeStampUTC']), Cesium.Cartesian3.fromDegrees(timedPoint['Longitude'], timedPoint['Latitude'], 0.0, undefined, scratchC3));

}

var entity = viewer.entities.add({

availability: new Cesium.TimeIntervalCollection([

    new Cesium.TimeInterval({

        start: Cesium.JulianDate.fromIso8601("2012-08-04T10:00:00Z"),

        stop: Cesium.JulianDate.fromIso8601("2016-08-04T15:00:00Z")

    })]),

id: ‘TestLine’,

path: { // this is a PathGraphics

    material: new Cesium.Color(1, 0, 0, 1),

    leadTime: 0,

    width: 5

},

position: sampledPositions

});

``

If you know your paths are done drawing and you want them to just show up, maybe consider converting them to Polylines. That would be more efficient.

Either way, I think I am going to put in an issue to remove the availability or lead+trailtime restriction. Or it at least needs to be better documented. I don’t know all of the details, but I can’t think of any reason why we can’t just draw the whole path if trailTime is undefined.

Best,

Hannah

Okay! So the path has to either have an availability or a lead+trail time because not all property types you can use for the position have time information associated with the positions.
So the path decides which positions to draw based on either the availability option or on lead/trail time.

So it sounds like your best bet is to just use the availability property for your paths.

Or, depending on your use case, it might make more sense to use a Polyline instead of a Path.

-Hannah

Hi Hannah,

Thank you for the thorough investigation. With the availability property set, all works fine now!

Willem

Is it possible to add samples after the array has been created? I want to move an object dynamically as data becomes available and have the trail update.

I tried this minor hack to your code but it didn't work:

var lat = 0;
var lon = 0;

sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);
sampledPositions.addSample(Cesium.JulianDate.fromIso8601("2015-10-20T14:53:26.0000000Z"),
                        Cesium.Cartesian3.fromDegrees(lon++, lat++), 0.0, undefined, scratchC3);

Yes, sampledPositions.addSample() will add samples. But it looks like you have the parenthesis wrong, should be:

sampledPositions.addSample(Cesium.JulianDate.fromIso8601(“2015-10-20T14:53:26.0000000Z”), Cesium.Cartesian3.fromDegrees(lon++, lat++, 0.0, undefined, scratchC3));

``

I also suspect that you will need to have increasing time-stamp values for the positions, in your example they are all the same.

Willem