API to Zoom level on TrackedEntity?

1. A concise explanation of the problem you're experiencing.
(Not a bug, a question on how to access and set zoom level)
When you select a new tracked entity, the viewer is set to a fixed zoom level that it keeps while tracking the moving entity.
Using the scroll wheel on the mouse you can change this zoom level for the current tracking sequence. However if I try to do this by code "viewer.camera.Zoomout(1000);", this zoom-out is quickly replaced with the previous zoom-level on the next frame.

How can I access current zoom level, and how can I adjust zoom level with a similar result as when I scroll the mouse wheel?

2. A minimal code example. If you've found a bug, this helps us reproduce and repair it.
(Not a bug, a question on how to access and set zoom level)

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

Check this as an example: http://www.paralogg.se/cesium/0F300687F300491
(default Zoom level is too close to start with, and when you have multiple entities and switches entity to follow, the zoom levels gets too close again...)

4. The Cesium version you're using, your operating system and browser.
Current Cesium version, running on Google Cloud (Appengine), and you choose your browser... :slight_smile:

Replying to my own question, to help others having the same problem:
"viewer.camera.position.clone()" and "viewer.camera.position" did the trick.

By cloning current viewer camera position, it could be applied to the following of another entity. My code below (on toggle of entity to follow):

function toggleFollow(flNumber) {

    if (follow==flNumber) {
    follow = "0"
    savedCamera = viewer.camera.position.clone(); // save camera offset before we unfollow all (else we would loose this)
    viewer.trackedEntity = undefined;
    //console.log(savedCamera);
    showPPCfor('');
    } else {
    follow = flNumber;
    viewer.trackedEntity = wingEntity[flNumber];
    // if we unfollowed all, no camera offset is available, so use the saved one
    if (Math.abs(viewer.camera.position['x'])+Math.abs(viewer.camera.position['y'])+Math.abs(viewer.camera.position['z']) > 100000) {
          wingEntity[flNumber].viewFrom= savedCamera;
    } else { // use the latest if available
          wingEntity[flNumber].viewFrom= viewer.camera.position;
    }

2 Likes

If I used viewForm, It is invalid when I modify again

I’m not sure what you mean. Can you post your code or ideally a Sandcastle example so I can try it out?

You might also try some of these suggestions in this thread:

https://groups.google.com/d/msg/cesium-dev/rOaa0L8_SAg/x5WSAzGOBQAJ

If you find something that works please do post what it was here.

Thanks from 2021, I spent a couple of days on my different solutions. But it didn’t work - I had to go back to the standard viewer.trackedEntity and your answer helped me. Have a nice day.

Glad to hear!

/Staffan

1 Like