Camera

new Cesium.Camera(scene)

相机由位置、方向和视锥体定义。

方向形成一个正交归一基,包含视向、上向和右向 = 视向与上向的单位向量叉乘。

视锥体由 6 个平面定义。 每个平面由一个 Cartesian4 对象表示,其中 x、y 和 z 组成 定义平面的单位法向量,w 组成是平面距离原点/相机位置的距离。
Name Type Description
scene Scene 场景。
Example:
// Create a camera looking down the negative z-axis, positioned at the origin,
// with a field of view of 60 degrees, and 1:1 aspect ratio.
const camera = new Cesium.Camera(scene);
camera.position = new Cesium.Cartesian3();
camera.direction = Cesium.Cartesian3.negate(Cesium.Cartesian3.UNIT_Z, new Cesium.Cartesian3());
camera.up = Cesium.Cartesian3.clone(Cesium.Cartesian3.UNIT_Y);
camera.frustum.fov = Cesium.Math.PI_OVER_THREE;
camera.frustum.near = 1.0;
camera.frustum.far = 2.0;
Demo:

Members

static Cesium.Camera.DEFAULT_OFFSET : HeadingPitchRange

相机飞往包含边界球体的位置时使用的默认方位角/俯仰角/范围。

static Cesium.Camera.DEFAULT_VIEW_FACTOR : number

一个乘以相机位置的标量,并在设置相机查看矩形后将其加回。 值为零表示相机会查看整个 Camera#DEFAULT_VIEW_RECTANGLE,大于零的值将使相机离范围更远, 小于零的值将使相机靠近范围。

static Cesium.Camera.DEFAULT_VIEW_RECTANGLE : Rectangle

相机创建时将查看的默认矩形。
获取相机发生变化时将被触发的事件,变化量由 percentageChanged 决定。

constrainedAxis : Cartesian3|undefined

如果设置,相机将无法朝任一方向超过此轴进行旋转。
Default Value: undefined

defaultLookAmount : number

当未提供参数给查看方法时,相机的默认旋转量。
Default Value: Math.PI / 60.0

defaultMoveAmount : number

当未提供参数给移动方法时,相机的默认移动量。
Default Value: 100000.0;

defaultRotateAmount : number

当未提供参数给旋转方法时,相机的默认旋转量。
Default Value: Math.PI / 3600.0

defaultZoomAmount : number

当未提供参数给缩放方法时,相机的默认移动量。
Default Value: 100000.0;
相机的视向。
获取相机在世界坐标中的视向。
当前视野中的空间区域。
Default Value: PerspectiveFrustum()
See:

readonly heading : number

获取相机的方位角(以弧度表示)。

readonly inverseTransform : Matrix4

获取相机的逆变换。
Default Value: Matrix4.IDENTITY

readonly inverseViewMatrix : Matrix4

获取逆视图矩阵。
See:

maximumZoomFactor : number

乘以地图大小的因子,用于确定在从地表缩小时相机位置的限制。 默认值为 1.5。仅在 2D 模式下有效且地图可旋转。
Default Value: 1.5
获取相机停止移动时将被触发的事件。
获取相机开始移动时将被触发的事件。

percentageChanged : number

相机在触发 changed 事件前必须改变的量。该值是 [0, 1] 范围内的百分比。
Default Value: 0.5

readonly pitch : number

获取相机的俯仰角(以弧度表示)。
相机的位置。

readonly positionCartographic : Cartographic

获取相机的 Cartographic 位置,经度和纬度以弧度表示,高度以米为单位。 在 2D 和哥伦布视图中,当相机超出地图范围时,返回的经度和纬度可能会超出有效范围。
获取相机在世界坐标中的位置。
相机的右向。
获取相机在世界坐标中的右向。

readonly roll : number

获取相机的翻滚角(以弧度表示)。
获取相机的参考框架。该变换的逆矩阵附加到视图矩阵中。
Default Value: Matrix4.IDENTITY
相机的上向。
获取相机在世界坐标中的上向。
获取视图矩阵。
See:

Methods

cameraToWorldCoordinates(cartesian, result)Cartesian4

将向量或点从相机的参考框架转换到世界坐标。
Name Type Description
cartesian Cartesian4 要转换的向量或点。
result Cartesian4 optional 存储结果的对象。
Returns:
转换后的向量或点。

cameraToWorldCoordinatesPoint(cartesian, result)Cartesian3

将点从相机的参考框架转换到世界坐标。
Name Type Description
cartesian Cartesian3 要转换的点。
result Cartesian3 optional 存储结果的对象。
Returns:
转换后的点。

cameraToWorldCoordinatesVector(cartesian, result)Cartesian3

将向量从相机的参考框架转换到世界坐标。
Name Type Description
cartesian Cartesian3 要转换的向量。
result Cartesian3 optional 存储结果的对象。
Returns:
转换后的向量。
取消当前的相机飞行并将相机保持在当前位置。 如果没有飞行正在进行,则此函数不执行任何操作。
完成当前的相机飞行并立即将相机移动到最终目的地。 如果没有飞行正在进行,则此函数不执行任何操作。

computeViewRectangle(ellipsoid, result)Rectangle|undefined

计算椭球体上可见的近似矩形。
Name Type Default Description
ellipsoid Ellipsoid Ellipsoid.default optional 你想要了解可见区域的椭球体。
result Rectangle optional 用于存储结果的矩形。
Returns:
可见的矩形,或者如果椭球体完全不可见则返回 undefined。

distanceToBoundingSphere(boundingSphere)number

返回相机到边界球前面的距离。
Name Type Description
boundingSphere BoundingSphere 世界坐标中的边界球。
Returns:
到边界球的距离。
将相机飞至家园视图。使用 Camera#.DEFAULT_VIEW_RECTANGLE 设置 3D 场景的默认视图。2D 和哥伦布视图的家园视图显示整个地图。
Name Type Description
duration number optional 飞行的持续时间(以秒为单位)。如果省略,Cesium 会尝试根据飞行的距离计算理想的持续时间。参见 Camera#flyTo
将相机从当前位置飞往新位置。
Name Type Description
options object 包含以下属性的对象:
Name Type Description
destination Cartesian3 | Rectangle 相机在世界坐标中的最终位置或从俯视图中可见的矩形。
orientation object optional 包含方向和上向属性或方位角、俯仰角和翻滚角属性的对象。默认情况下,方向将指向 3D 中框架的中心,在哥伦布视图中指向负 z 方向。上向将在 3D 中指向当地北方,在哥伦布视图中指向正 y 方向。 在无限滚动模式下,2D 时不使用方向。
duration number optional 飞行的持续时间(以秒为单位)。如果省略,Cesium 会尝试根据飞行的距离计算理想的持续时间。
complete Camera.FlightCompleteCallback optional 飞行完成时执行的函数。
cancel Camera.FlightCancelledCallback optional 如果飞行被取消时执行的函数。
endTransform Matrix4 optional 表示飞行完成时相机所处参考框架的变换矩阵。
maximumHeight number optional 飞行峰值时的最大高度。
pitchAdjustHeight number optional 如果相机飞得高于该值,飞行过程中会调整俯仰角向下看,以保持地球在视口内。
flyOverLongitude number optional 地球上两点之间总有两种方式。此选项强制相机选择飞越该经度的飞行方向。
flyOverLongitudeWeight number optional 仅在该路径不长于短路径乘以 flyOverLongitudeWeight 时,才飞越通过 flyOverLongitude 指定的经度。
convert boolean optional 是否将目标从世界坐标转换为场景坐标(仅在不使用 3D 时相关)。默认值为 true
easingFunction EasingFunction.Callback optional 控制飞行持续时间内时间的插值方式。
Throws:
  • DeveloperError : 如果给定方向或上向,则两者都是必需的。
Example:
// 1. Fly to a position with a top-down view
viewer.camera.flyTo({
    destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0)
});

// 2. Fly to a Rectangle with a top-down view
viewer.camera.flyTo({
    destination : Cesium.Rectangle.fromDegrees(west, south, east, north)
});

// 3. Fly to a position with an orientation using unit vectors.
viewer.camera.flyTo({
    destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
    orientation : {
        direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734),
        up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339)
    }
});

// 4. Fly to a position with an orientation using heading, pitch and roll.
viewer.camera.flyTo({
    destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
    orientation : {
        heading : Cesium.Math.toRadians(175.0),
        pitch : Cesium.Math.toRadians(-35.0),
        roll : 0.0
    }
});

flyToBoundingSphere(boundingSphere, options)

将相机飞往一个位置,使当前视角包含提供的边界球。

偏移量是指在以边界球中心为中心的局部东-北-上参考框架中的方位角/俯仰角/范围。 方位角和俯仰角是在局部东-北-上参考框架中定义的。 方位角是从 y 轴开始并朝 x 轴增加的角度。俯仰角是从 xy 平面旋转的角度。正俯仰角 代表在平面下方。负俯仰角代表在平面上方。范围是从中心的距离。如果范围为零, 将计算一个范围,以便整个边界球可见。

在 2D 和哥伦布视图下,必须是俯视图。相机会位于目标上方并朝下看。相对于目标的高度将是范围。 方位角将与当地北方对齐。

Name Type Description
boundingSphere BoundingSphere 要查看的边界球,使用世界坐标表示。
options object optional 包含以下属性的对象:
Name Type Description
duration number optional 飞行的持续时间(以秒为单位)。如果省略,Cesium 会尝试根据飞行的距离计算理想的持续时间。
offset HeadingPitchRange optional 在以目标为中心的局部东-北-上参考框架中的偏移量。
complete Camera.FlightCompleteCallback optional 飞行完成时执行的函数。
cancel Camera.FlightCancelledCallback optional 如果飞行被取消时执行的函数。
endTransform Matrix4 optional 表示飞行完成时相机所处参考框架的变换矩阵。
maximumHeight number optional 飞行峰值时的最大高度。
pitchAdjustHeight number optional 如果相机飞得高于该值,飞行过程中会调整俯仰角向下看,以保持地球在视口内。
flyOverLongitude number optional 地球上两点之间总有两种飞行方式。此选项强制相机选择飞越该经度的飞行方向。
flyOverLongitudeWeight number optional 仅在该路径不长于短路径乘以 flyOverLongitudeWeight 时,才飞越通过 flyOverLongitude 指定的经度。
easingFunction EasingFunction.Callback optional 控制飞行持续时间内时间的插值方式。

getMagnitude()number

获取相机位置的大小。在 3D 中,这是向量的大小。在 2D 和 哥伦布视图中,这是到地图的距离。
Returns:
位置的大小。

getPickRay(windowPosition, result)Ray|undefined

从相机位置通过在世界坐标中指定的像素 windowPosition 创建一条射线。
Name Type Description
windowPosition Cartesian2 像素的 x 和 y 坐标。
result Ray optional 存储结果的对象。
Returns:
返回射线的 Cartesian3 位置和方向,如果无法确定拾取射线,则返回 undefined。

getPixelSize(boundingSphere, drawingBufferWidth, drawingBufferHeight)number

返回以米为单位的像素大小。
Name Type Description
boundingSphere BoundingSphere 世界坐标中的边界球。
drawingBufferWidth number 绘图缓冲区宽度。
drawingBufferHeight number 绘图缓冲区高度。
Returns:
以米为单位的像素大小。

getRectangleCameraCoordinates(rectangle, result)Cartesian3

获取查看椭球体或地图上矩形所需的相机位置。
Name Type Description
rectangle Rectangle 要查看的矩形。
result Cartesian3 optional 查看该矩形所需的相机位置。
Returns:
查看该矩形所需的相机位置。
角度 旋转相机的每个方向向量。
Name Type Description
axis Cartesian3 要绕其旋转的轴。
angle number optional 旋转的角度,以弧度为单位。默认值为 defaultLookAmount
See:

lookAt(target, offset)

使用目标和偏移量设置相机的位置和方向。目标必须以世界坐标给出。 偏移量可以是笛卡尔坐标或以目标为中心的局部东-北-上参考框架中的方位角/俯仰角/范围。 如果偏移量是笛卡尔坐标,则它是由变换矩阵定义的参考框架中心的偏移量。如果偏移量 是方位角/俯仰角/范围,则方位角和俯仰角是在由变换矩阵定义的参考框架中定义的。 方位角是从 y 轴开始并朝 x 轴增加的角度。俯仰角是从 xy 平面旋转的角度。正俯仰角 代表在平面下方。负俯仰角代表在平面上方。范围是从中心的距离。 在 2D 中,必须是俯视图。相机会位于目标上方并朝下看。相对于目标的高度将是偏移量的大小。 方位角将根据偏移量确定。如果无法从偏移量确定方位角,则方位角将是北。
Name Type Description
target Cartesian3 世界坐标中的目标位置。
offset Cartesian3 | HeadingPitchRange 在以目标为中心的局部东-北-上参考框架中 从目标的偏移量。
Throws:
Example:
// 1. Using a cartesian offset
const center = Cesium.Cartesian3.fromDegrees(-98.0, 40.0);
viewer.camera.lookAt(center, new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0));

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

lookAtTransform(transform, offset)

使用目标和变换矩阵设置相机的位置和方向。偏移量可以是笛卡尔坐标或方位角/俯仰角/范围。 如果偏移量是笛卡尔坐标,则它是由变换矩阵定义的参考框架中心的偏移量。如果偏移量 是方位角/俯仰角/范围,则方位角和俯仰角是在由变换矩阵定义的参考框架中定义的。 方位角是从 y 轴开始并朝 x 轴增加的角度。俯仰角是从 xy 平面旋转的角度。正俯仰角 代表在平面下方。负俯仰角代表在平面上方。范围是从中心的距离。 在 2D 中,必须是俯视图。相机会位于参考框架的中心上方。相对于目标的高度将是偏移量的大小。 方位角将根据偏移量确定。如果无法从偏移量确定方位角,则方位角将是北。
Name Type Description
transform Matrix4 定义参考框架的变换矩阵。
offset Cartesian3 | HeadingPitchRange optional 在以目标为中心的参考框架中 从目标的偏移量。
Throws:
Example:
// 1. Using a cartesian offset
const transform = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-98.0, 40.0));
viewer.camera.lookAtTransform(transform, new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0));

// 2. Using a HeadingPitchRange offset
const transform = Cesium.Transforms.eastNorthUpToFixedFrame(Cesium.Cartesian3.fromDegrees(-72.0, 40.0));
const heading = Cesium.Math.toRadians(50.0);
const pitch = Cesium.Math.toRadians(-20.0);
const range = 5000.0;
viewer.camera.lookAtTransform(transform, new Cesium.HeadingPitchRange(heading, pitch, range));
绕相机的右向按 (以弧度为单位)旋转,如果不在 2D 模式下,则旋转方向为其上向的相反方向。
Name Type Description
amount number optional 旋转的量,以弧度为单位。默认值为 defaultLookAmount
See:
绕相机的上向按 (以弧度为单位)旋转,如果不在 2D 模式下,则旋转方向为其右向的相反方向。
Name Type Description
amount number optional 旋转的量,以弧度为单位。默认值为 defaultLookAmount
See:
绕相机的上向按 (以弧度为单位)旋转,如果不在 2D 模式下,则旋转方向为其右向的方向。
Name Type Description
amount number optional 旋转的量,以弧度为单位。默认值为 defaultLookAmount
See:
绕相机的右向按 (以弧度为单位)旋转,如果不在 2D 模式下,则旋转方向为其上向的方向。
Name Type Description
amount number optional 旋转的量,以弧度为单位。默认值为 defaultLookAmount
See:

move(direction, amount)

沿着 方向 移动相机的位置。
Name Type Description
direction Cartesian3 移动的方向。
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:

moveBackward(amount)

沿着相机视向的相反方向按 移动相机的位置。 在 2D 模式下,这将缩小相机而不是移动相机的位置。
Name Type Description
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:
沿着相机上向的相反方向按 移动相机的位置。
Name Type Description
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:
沿着相机的视向按 移动相机的位置。 在 2D 模式下,这将缩放相机而不是移动相机的位置。
Name Type Description
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:
沿着相机右向的相反方向按 移动相机的位置。
Name Type Description
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:
沿着相机的右向按 移动相机的位置。
Name Type Description
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:
沿着相机的上向按 移动相机的位置。
Name Type Description
amount number optional 移动的量,单位为米。默认值为 defaultMoveAmount
See:

pickEllipsoid(windowPosition, ellipsoid, result)Cartesian3|undefined

选择一个椭球体或地图。
Name Type Default Description
windowPosition Cartesian2 像素的 x 和 y 坐标。
ellipsoid Ellipsoid Ellipsoid.default optional 要选择的椭球体。
result Cartesian3 optional 存储结果的对象。
Returns:
如果选择了椭球体或地图, 返回椭球体或地图表面在世界坐标中的点。如果未选择椭球体或地图,则返回 undefined。
Example:
const canvas = viewer.scene.canvas;
const center = new Cesium.Cartesian2(canvas.clientWidth / 2.0, canvas.clientHeight / 2.0);
const ellipsoid = viewer.scene.ellipsoid;
const result = viewer.camera.pickEllipsoid(center, ellipsoid);
旋转相机 角度。相机位置到相机参考框架中心的距离保持不变。
Name Type Description
axis Cartesian3 要绕其旋转的轴,使用世界坐标表示。
angle number optional 旋转的角度,以弧度为单位。默认值为 defaultRotateAmount
See:
绕相机参考框架中心向下旋转相机 角度
Name Type Description
angle number optional 旋转的角度,以弧度为单位。默认值为 defaultRotateAmount
See:
绕相机参考框架中心向左旋转相机 角度
Name Type Description
angle number optional 旋转的角度,以弧度为单位。默认值为 defaultRotateAmount
See:
绕相机参考框架中心向右旋转相机 角度
Name Type Description
angle number optional 旋转的角度,以弧度为单位。默认值为 defaultRotateAmount
See:
绕相机参考框架中心向上旋转相机 角度
Name Type Description
angle number optional 旋转的角度,以弧度为单位。默认值为 defaultRotateAmount
See:
设置相机的位置、方向和变换。
Name Type Description
options object 包含以下属性的对象:
Name Type Description
destination Cartesian3 | Rectangle optional 相机在世界坐标中的最终位置,或从俯视图中可见的矩形。
orientation HeadingPitchRollValues | DirectionUp optional 一个对象,包含方向和上向属性或方位角、俯仰角和翻滚角属性。默认情况下,方向将指向 3D 中框架的中心,在哥伦布视图中指向负 z 方向。上向将在 3D 中指向当地的北方,在哥伦布视图中指向正 y 方向。在无限滚动模式下,2D 时不使用方向。
endTransform Matrix4 optional 表示相机参考框架的变换矩阵。
convert boolean optional 是否将目标从世界坐标转换为场景坐标(仅在不使用 3D 时相关)。默认值为 true.
Example:
// 1. Set position with a top-down view
viewer.camera.setView({
    destination : Cesium.Cartesian3.fromDegrees(-117.16, 32.71, 15000.0)
});

// 2 Set view with heading, pitch and roll
viewer.camera.setView({
    destination : cartesianPosition,
    orientation: {
        heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north)
        pitch : Cesium.Math.toRadians(-90),    // default value (looking down)
        roll : 0.0                             // default value
    }
});

// 3. Change heading, pitch and roll with the camera position remaining the same.
viewer.camera.setView({
    orientation: {
        heading : Cesium.Math.toRadians(90.0), // east, default value is 0.0 (north)
        pitch : Cesium.Math.toRadians(-90),    // default value (looking down)
        roll : 0.0                             // default value
    }
});


// 4. View rectangle with a top-down view
viewer.camera.setView({
    destination : Cesium.Rectangle.fromDegrees(west, south, east, north)
});

// 5. Set position with an orientation using unit vectors.
viewer.camera.setView({
    destination : Cesium.Cartesian3.fromDegrees(-122.19, 46.25, 5000.0),
    orientation : {
        direction : new Cesium.Cartesian3(-0.04231243104240401, -0.20123236049443421, -0.97862924300734),
        up : new Cesium.Cartesian3(-0.47934589305293746, -0.8553216253114552, 0.1966022179118339)
    }
});

switchToOrthographicFrustum()

将视锥/投影切换为正交模式。 在 2D 模式下,此函数无操作,因为 2D 模式将始终是正交的。

switchToPerspectiveFrustum()

将视锥/投影切换为透视模式。 在 2D 模式下,此函数无操作,因为 2D 模式必须始终是正交的。
沿着相机的方向向量逆时针旋转相机,旋转量以弧度为单位。
Name Type Description
amount number optional 旋转的量,以弧度为单位。默认值为 defaultLookAmount
See:
沿着相机的方向向量顺时针旋转相机,旋转量以弧度为单位。
Name Type Description
amount number optional 旋转的量,以弧度为单位。默认值为 defaultLookAmount
See:

viewBoundingSphere(boundingSphere, offset)

设置相机,使当前视角包含提供的边界球。

偏移量是指在以边界球中心为中心的局部东-北-上参考框架中的方位角/俯仰角/范围。 方位角和俯仰角是在局部东-北-上参考框架中定义的。 方位角是从 y 轴开始并朝 x 轴增加的角度。俯仰角是从 xy 平面旋转的角度。正俯仰角 代表在平面下方。负俯仰角代表在平面上方。范围是从中心的距离。如果范围为零, 将计算一个范围,以便整个边界球可见。

在 2D 模式下,必须是俯视图。相机会位于目标上方并朝下看。相对于目标的高度将是范围。 方位角将根据偏移量确定。如果无法从偏移量确定方位角,则方位角将是北。

Name Type Description
boundingSphere BoundingSphere 要查看的边界球,使用世界坐标表示。
offset HeadingPitchRange optional 在以目标为中心的局部东-北-上参考框架中的偏移量。
Throws:

worldToCameraCoordinates(cartesian, result)Cartesian4

将向量或点从世界坐标转换到相机的参考框架。
Name Type Description
cartesian Cartesian4 要转换的向量或点。
result Cartesian4 optional 存储结果的对象。
Returns:
转换后的向量或点。

worldToCameraCoordinatesPoint(cartesian, result)Cartesian3

将点从世界坐标转换到相机的参考框架。
Name Type Description
cartesian Cartesian3 要转换的点。
result Cartesian3 optional 存储结果的对象。
Returns:
转换后的点。

worldToCameraCoordinatesVector(cartesian, result)Cartesian3

将向量从世界坐标转换到相机的参考框架。
Name Type Description
cartesian Cartesian3 要转换的向量。
result Cartesian3 optional 存储结果的对象。
Returns:
转换后的向量。
沿着相机的视向缩放
Name Type Description
amount number optional 移动的量。默认值为 defaultZoomAmount
See:
沿着相机视向的相反方向缩放
Name Type Description
amount number optional 移动的量。默认值为 defaultZoomAmount
See:

Type Definitions

Cesium.Camera.FlightCancelledCallback()

飞行被取消时将执行的函数。

Cesium.Camera.FlightCompleteCallback()

飞行完成时将执行的函数。
需要帮助?获得答案的最快方法是来自社区和团队 Cesium Forum.