Hey guys,
I have a question. I am working on this application that tries to plot the location of aircraft in 3D. Please refer to the code below:
The issue I have right now is; i am able to show the CZML points as necessary. However, when update (setInterval), the old CZML points remain and the new ones are also added. This makes it like a chain. I however, need to stop displaying the old points. i.e. @ i when i++ occurs.
function getData(){
var data = null;
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener(“readystatechange”, function () {
if (this.readyState === this.DONE) {
console.log(this.responseText);
//JSON.parse(this.responseText);
var data_one = JSON.parse(this.responseText);
//var data_done = Object.values(data_one);
console.log(data_one);
var total_numb=data_one.total;
console.log(total_numb);
console.log(data_one.ac[0].lon);
var plane_lon = ;
var plane_lat = ;
var plane_alt = ;
for(var i=0;i<=total_numb;i++)
{
// czml.show = false,
plane_lon.push(parseFloat(data_one.ac[i].lon));
plane_lat.push(parseFloat(data_one.ac[i].lat));
plane_alt.push(parseFloat(data_one.ac[i].alt));
//console.log(plane_lon[i]);
var czml = viewer.entities.add({
name : ‘Green cylinder with black outline’,
position: Cesium.Cartesian3.fromDegrees(plane_lon[i],plane_lat[i],plane_alt[i]),
cylinder : {
length : 20.0,
topRadius : 20.0,
bottomRadius : 20.0,
material : Cesium.Color.RED.withAlpha(0.5),
outline : true,
outlineColor : Cesium.Color.DARK_GREEN
}
});
var dataSourcePromise = Cesium.CzmlDataSource.load(czml);
viewer.dataSources.add(dataSourcePromise);
//viewer.dataSource.remove(czml)
}
}
});
xhr.open(“GET”, “https://adsbexchange-com1.p.rapidapi.com/json/lat/43.6285/lon/-79.3960/dist/10/”);
xhr.setRequestHeader(“x-rapidapi-host”, “adsbexchange-com1.p.rapidapi.com”);
xhr.setRequestHeader(“x-rapidapi-key”, “----------------------------------------------------------”);
xhr.send(data);
var body = XMLHttpRequest.response;
}
setInterval(getData, 10000);
Please let me know what I am doing wrong here.
Kind Regards
Vamshi