Pri Santos
Pri Santos

Reputation: 409

Get rotation in Cesium

I want to know the rotation angle from Cesium when I turn the map using ctrl+mouseLeft. Like I did on this image: enter image description here

I tried viewer.camera.roll but doesn't seem to be right. It's always zero.

Any tips in how I can get that value in 2D and 3D? I would also like to set this value.

Thanks in advance!

EDIT: I have used the solution suggested and now I'm getting different values (in radians). It works both on 2D and 3D maps.

EDIT2: How to set the rotation to an specific angle

    setRotation(angle: number): void {
        viewer.camera.setView({
            heading: (angle / (180 / Math.PI)) // east, default value is 0.0 (north)
        })
    };

Based on this doc

EDIT 3: I'm using the following code to get the current heading of the map:

public getAngle(): number {
    return viewer.camera.heading;
}

When I call this function and my map is not rotated, as the image shows, I get the result of "6.283185307179586" radians. I thought it should be zero, because it's not rotated at all. If I move the map around with the mouse (pan) and call the getAngle function again it gives differents results, as "1.4612025367455317e-8" if I move it north. Any thoughts about it? I would like to get the heading of the map.

Thanks a lot!

enter image description here

Upvotes: 1

Views: 2121

Answers (1)

emackey
emackey

Reputation: 12418

This value is available from viewer.camera.heading and is expressed in radians. You can twist the camera like this using the twistLeft and twistRight functions on the camera.

Upvotes: 3

Related Questions