1. A concise explanation of the problem you’re experiencing.
I met a problem when I use compositeProperty for orientation. The goal is to display vehicles driving according to track data, which has already converted to CZML file. when the vehicles sometimes stop before traffic light, the orientation of vehicles becomes a problem. With Omar’s help, I use the compositeProperty for orientation, and rewrote CZML file with position intervals(moving interval, stop interval ). The scene in my demo is that a vehicle drives from 00:00 to 00:40, stops until 01:26, and then drives again to end. In code I tried to get the orientation of last time point in a moving interval and assign it as the orientation of next stopping interval. But when running to the stop interval, the vehicle turns to the default orientation again. I checked the orientation value of VelocityOrientationProperty and found it has no value at the stop time point: movingOri.getValue(vehicleInterval.stop) undefined, then I tried to assign the orientation of last second time point to the stop interval, but the vehicle shakes a while and suddenly turns 180deg. I don’t know where the problem is, is the problem of time interval definition in CZML again? I uploaded my CZML file here and below is the link of code in Sandcastle. Could anyone help me to get through this? Many thanks in advance!
2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it.
code shared in sandcastle:
3. Context. Why do you need to do this? We might know a better way to accomplish your goal.
4. The Cesium version you’re using, your operating system and browser.
Cesium 1.57, Windows system, chrome/ firefox browser.
It looks like the problem is that you have only one stopOrientation property, but you need the vehicle to have multiple different “stop orientations” depending on what the time is. Take a look at this line:
// use the orientation of second last time point of last moving interval
If you console.log the value of stopOri here, you’ll notice that line of code gets executed twice. But since stopOri is a constant property, each time you set its value, it will overwrite what was before. I manually added a check to make it only execute once, and the vehicle behaves as expected:
// define this variable somewhere at the top of the code
var doneOnce = false;
// Then back to the snippet above, it’s replaced with:
Here’s a Sandcastle where you can see this. I embedded your CZML in the code so this should be a standalone code example. Hopefully this makes sense. I think the solution here would be to create a composite property whose value is a different constant property for different intervals.
I tried your code snippet in sand castle and it didn’t turn around 180deg any more. I will try to create a composite property for stopOri. But there is another thing still looks weird: just before the vehicle stops, it shakes a little bit and then stops, the orientation when it stops seems not the same as the last moving point orientation but a little bit tilted, but actually it is indeed assigned to the orientation value of second last moving point. hope you can understand what I mean. And there is an error in console:’ TypeError: vehicle.position.setInterpolationOptions is not a function’. I really want the vehicle to stop like a normal car in real world, no shaking, no tilted orientation. Is there anyway to do it? Looking forward to your help.
Or just set all your positions outside of CZML directly with the Entity API.
As for the shake, I do believe this is because the velocity of the truck changes in that last part as it slows down, and since orientation is automatically computed from velocity, we see this difference. I’m not entirely sure if it is getting the right orientation, or if it’s not taking enough samples and this change is actually an error. To make debugging this a little easier, here’s a version with a dynamic arrow representing the truck’s computed velocity. It’s clear here that the velocity is jumping around. This is where the velocity is being computed:
It gets two positions in time and subtracts them. So I’m not entirely sure where the problem might be, but hopefully this gives you some direction to look into.
thanks again for your help! For the interpolation, do you mean that I should add interpolation in CZML and delete the ‘setInterpolationOptions’ in App.js? But I saw in Cesium-workshop demo() that interpolation exists in both App.js and CZML file for the drone. In App.js it sets interpolationAlgorithm : Cesium.HermitePolynomialApproximation, and in CZML file it sets “interpolationAlgorithm”:“LAGRANGE”, so I was confused which interpolation algorithm actually works and should set it once or twice.
For the shake, I think maybe there is some problem with the function ‘VelocityOrientationProperty’. I saw the arrows you drew to show the direction of velocity, it was very clear. The CZML file is only track data samples, and from the track samples, we can see the vehicle slows down in front of the light and then stop. I will check the velocity calculating as you suggested to see where the problem is. Thank you once again!