lookAt

fun lookAt(target: Cartesian3, offset: Cartesian3)(source)

Sets the camera position and orientation using a target and offset. The target must be given in world coordinates. The offset can be either a cartesian or heading/pitch/range in the local east-north-up reference frame centered at the target. If the offset is a cartesian, then it is an offset from the center of the reference frame defined by the transformation matrix. If the offset is heading/pitch/range, then the heading and the pitch angles are defined in the reference frame defined by the transformation matrix. The heading is the angle from y axis and increasing towards the x axis. Pitch is the rotation from the xy-plane. Positive pitch angles are below the plane. Negative pitch angles are above the plane. The range is the distance from the center.

In 2D, there must be a top down view. The camera will be placed above the target looking down. The height above the target will be the magnitude of the offset. The heading will be determined from the offset. If the heading cannot be determined from the offset, the heading will be north.

// 1. Using a cartesian offset
const center = Cartesian3.fromDegrees(-98.0, 40.0);
viewer.camera.lookAt(center, new Cartesian3(0.0, -4790000.0, 3930000.0));

// 2. Using a HeadingPitchRange offset
const center = Cartesian3.fromDegrees(-72.0, 40.0);
const heading = Math.toRadians(50.0);
const pitch = Math.toRadians(-20.0);
const range = 5000.0;
viewer.camera.lookAt(center, new HeadingPitchRange(heading, pitch, range));

Parameters

target

The target position in world coordinates.

offset

The offset from the target in the local east-north-up reference frame centered at the target.

See also


fun lookAt(target: Cartesian3, offset: HeadingPitchRange)(source)