How to use Camera changed 'percentageChanged'

1. A concise explanation of the problem you’re experiencing.

I’m drawing some routes from gpx files.

I should update the visibility of my routes on the base of the camera distance from them.

Unfortunately the polyline “distanceDisplayCondition” property does not work on mobile.

So, I think to “manually” lerp the opacity of these polylines from 0 (far) to 1 (near).

To do so I think I should get the “map changed” event the most reliable as possible (every single little change),

to next update the opacity of my polylines.

But I can’t understand how to use the ‘percentageChanged’ property on ‘camera changed’ event

2. A minimal code example. If you’ve found a bug, this helps us reproduce and repair it. => {

// now I should update all my polylines opacity on the base of camera distance from them


3. Context. Why do you need to do this? We might know a better way to accomplish your goal.

To show polylines (track routes) only at a some camera distance, with a lerp to make it smoother

4. The Cesium version you’re using, your operating system and browser.


You can set the percent changed to a low value, like 0.01, to trigger camera updates on small changes like in this Sandcastle example:

Thank-you Omar,
but I think that in this way I will change the percentage value for every listener, and I have another function that is triggered by Camera.changed that should be triggered only at 50%.

Is there a way to trigger at different percentage for the same camera?

I think for that you’d set the percentage change to the lowest one you need, and keep track of the camera difference yourself for the ones that require a higher change. You can see how CesiumJS computes the percentage change here: