Hello,
At this time, I success to use new Cesium.SampledPositionProperty(); to get smooth moving of my model.
But as soon I'm trying to use orientation: new Cesium.VelocityOrientationProperty(position)
I receive error:
Unable to get property 'addEventListener' of undefined or null reference (on line 97 of https://cesiumjs.org/Cesium/Source/DataSources/VelocityVectorProperty.js)
do you know why or what I did wrong?...
var newLat=49.451413;
var newLong=2.111137;
var track_old=0;
var delta_track=0;
var track=0;
var res4=49.451413; //latitude_value
var res5=2.111137; // longitude_value
var res6=0;
var res7=150;
var res8=0;
var res9=0;
var timer=0;
var camtime=Date.now();
var datatime=0;
var datatimeold=0;
var cameraAngle = 1;
var dataAvailable=0;
var position= Cesium.Cartesian3.fromDegrees( 2.111137, 49.451413, 200);
var timerimmat= 0;
var registration= 'OE-ICU';
var start=Date.now();
var stop = Cesium.JulianDate.addSeconds(start, 360, new Cesium.JulianDate());
var time = Cesium.JulianDate.addSeconds(start, 45, new Cesium.JulianDate());
var timermodel=0;
var i=0;
var vspeed=0;
var viewer = new Cesium.Viewer('cesiumContainer', {
infoBox: false, //Disable InfoBox widget
selectionIndicator: false, //Disable selection indicator
shouldAnimate: true, // Enable animations
terrainProvider: Cesium.createWorldTerrain()
});
//Enable lighting based on sun/moon positions
viewer.scene.globe.enableLighting = true;
//Enable depth testing so things behind the terrain disappear.
viewer.scene.globe.depthTestAgainstTerrain = true;
//Set the random number seed for consistent results.
Cesium.Math.setRandomNumberSeed(3);
flightradar();
function clocking(){
stop = Cesium.JulianDate.addHours(datatime,12,new Cesium.JulianDate());
time = datatime;//Cesium.JulianDate.addSeconds(start, 45, new Cesium.JulianDate());
//Make sure viewer is at the desired time.
viewer.clock.startTime = start.clone();
viewer.clock.stopTime = stop.clone();
viewer.clock.currentTime = start.clone();
//viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP; //Loop at the end
viewer.clock.multiplier = 1;
//Set timeline to simulation bounds
viewer.timeline.zoomTo(start, stop);
}
//Generate a random circular pattern with varying heights.
var property = new Cesium.SampledPositionProperty();
function computeCirclularFlight(lon, lat, radius, height, timedata) {
//time = timedata;//;//timedata;
position = Cesium.Cartesian3.fromDegrees(lon, lat, height);
property.addSample(time, position);
//Also create a point for each sample we generate.
viewer.entities.add({
position : position,
point : {
pixelSize : 8,
color : Cesium.Color.TRANSPARENT,
outlineColor : Cesium.Color.YELLOW,
outlineWidth : 3
}
});
return property;
}
//Actually create the entity
var entity = viewer.entities.add({
//Use our computed positions
position : position,
//Automatically compute orientation based on position movement.
// orientation : new Cesium.VelocityOrientationProperty(position),
//Load the Cesium plane model to represent the entity
model : {
uri : '../../SampleData/models/CesiumAir/Cesium_Air.gltf',
minimumPixelSize : 64
}
});
viewer.trackedEntity = entity;
function flightradar()
{
var date= Date.now();
var res;
var url = 'https://data-live.flightradar24.com/zones/fcgi/feed.js?reg=!’+registration;
var doc= new XMLHttpRequest();
doc.onreadystatechange = function(){
if(doc.readyState == XMLHttpRequest.DONE){
res=doc.responseText;//JS.data(doc.responseText);
//console.log(res);
dataAvailable=res.length
if(dataAvailable>40)
{
var res1=res.split("[");
var res2=res1[1];
var res3=res2.split(",");
res4=parseFloat(res3[1]); //latitude_value
res5=parseFloat(res3[2]); // longitude_value
res6=parseFloat(res3[3]); // track_value
res7=parseFloat(res3[4])*0.3048; // altitude_value
res8=parseFloat(res3[5]); // speed_value
res9=parseInt((parseFloat(res3[15])*0.4*100)/100); // Vspeed_value
datatime=Cesium.JulianDate.fromDate(new Date(parseInt(res3[10])*1000));// timestamp of data recorded
if(datatime!==undefined && datatime!==0 && datatimeold<parseInt(res3[10]))
{
start=datatime;
datatimeold=parseInt(res3[10]);
}
}
}
};
doc.open('GET', url, true);
doc.send();
}
viewer.clock.onTick.addEventListener(function(clock){
if(Date.now()>=timer+500)
{
flightradar();
if(datatime!==undefined && datatime!==0)
{
clocking();
computeCirclularFlight(res5,res4,0.03,res7,datatime);
datatimeold=datatime;
//i=0;
}
//viewer.trackedEntity = entity;
entity.viewFrom= new Cesium.Cartesian3(30, 30, 10);
timer=Date.now();
}
if(Date.now()>=timermodel+10)
{
if(Date.now()<=timer+500)
{
if(datatime!==undefined && datatime!==0)
{
i=i+0.01;
entity.position=property.getValue(Cesium.JulianDate.addSeconds(start, i, new Cesium.JulianDate()));
timermodel=Date.now();
}
}
}
});