So, I’m using a TimeIntervalCollectionPositionProperty for an Entity.
Since I only need the last 10 intervals, after reaching that limit, each added interval, I want to remove the first interval, but once
the first ever interval is removed, subsequent calls to this line won’t remove the first element since it becomes empty
timeIntervalCollection.removeInterval(timeIntervalCollection.get(0)); // Works only once
``
I think that somewhere around here, the interval created wrong, but I don’t get it. Maybe the stop and start times are wrong?
My sandcastle example creates ten intervals and then tries to remove the first until the collection would become empty. But the second interval
becomes empty once the first removed.
Sandcastle code :
var viewer = new Cesium.Viewer(‘cesiumContainer’);
// For the example, I will use 10 intervals
var INTERVALS_LIMIT = 10;
var timeIntervalCollection = new Cesium.TimeIntervalCollection();
var index =0;
// A function to create stub intervals data -
// adds ten intervals, one hour apart of each other.
function initData(){
var now = Cesium.JulianDate.now();
var startTime = new Cesium.JulianDate();
var endTime = new Cesium.JulianDate();
Cesium.JulianDate.addHours(startTime,2,endTime);
// Add 10 intervals, one hour apart of eachother
for (index = 0; index < INTERVALS_LIMIT; index++){
// Notice, the interval duration is two hours, but when the next added,
// all the magic sets stop time of the previous to the start time of the new one.
Cesium.JulianDate.addHours(now, index,startTime);
Cesium.JulianDate.addHours(now,index+2,endTime);
// Create the interval - data is not important
var interval = new Cesium.TimeInterval({
start : startTime,
stop : endTime,
data : Cesium.Cartesian3.fromDegrees(39, -75)
});
// Add the interval to my collection
timeIntervalCollection.addInterval(interval);
}
}
initData();
// Now, after some time in my application, I want to remove the oldest intervals, since they are no longer
for (index = 0; index < INTERVALS_LIMIT; index++){
// Each iteration, I want to remove the first interval
var firstInterval = timeIntervalCollection.get(0);
var isRemoved = timeIntervalCollection.removeInterval(firstInterval);
if (!isRemoved){
console.error("failed to remove at index 0 because the interval’s isEmpty === " + firstInterval.isEmpty );
} else {
console.log("successfully removed leading interval, left : " + timeIntervalCollection.length);
}
}
console.log("expected to be 0, but actual length is " + timeIntervalCollection.length);
``
If something is unclear I can clarify.
Thanks,
Mati