Camera

new Cesium.Camera(scene)

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

方向通过 view、up 和 right = view x up 单位向量构成正交规范基。

视锥体由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

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

defaultMoveAmount : number

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

defaultRotateAmount : number

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

defaultZoomAmount : number

当未向 zoom 方法提供参数时,移动相机的默认量。
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 Object with the following properties:
Name Type Description
destination Cartesian3 | Rectangle 相机在世界坐标中的最终位置,或从俯视图可见的矩形。
orientation object optional 包含 direction 和 up 属性或 heading、pitch 和 roll 属性的对象。默认情况下,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 仅当经由 flyOverLongitude 指定的经度路径不比短路径乘以 flyOverLongitudeWeight 更长时,才飞越该经度。
convert boolean optional 是否将目标从世界坐标转换为场景坐标(仅在非3D模式下相关)。默认为 true
easingFunction EasingFunction.Callback optional 控制飞行持续时间内时间的插值方式。
Throws:
  • DeveloperError : 如果提供了 direction 或 up 中的任一个,则两者都必须提供。
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 Object with the following properties:
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 仅当经由 flyOverLongitude 指定的经度路径不比短路径乘以 flyOverLongitudeWeight 更长时,才飞越该经度。
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:
查看矩形所需的相机位置
将相机的每个方向向量绕 axis 旋转 angle
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)

沿 direction 方向将相机位置平移 amount
Name Type Description
direction Cartesian3 移动方向。
amount number optional 移动量(米)。默认为 defaultMoveAmount
See:

moveBackward(amount)

沿相机视图向量的反方向将相机位置平移 amount。 在2D模式下,这将缩小相机而不是平移相机位置。
Name Type Description
amount number optional 移动量(米)。默认为 defaultMoveAmount
See:
沿相机上向量的反方向将相机位置平移 amount
Name Type Description
amount number optional 移动量(米)。默认为 defaultMoveAmount
See:
沿相机视图向量方向将相机位置平移 amount。 在2D模式下,这将放大相机而不是平移相机位置。
Name Type Description
amount number optional 移动量(米)。默认为 defaultMoveAmount
See:
沿相机右向量的反方向将相机位置平移 amount
Name Type Description
amount number optional 移动量(米)。默认为 defaultMoveAmount
See:
沿相机右向量方向将相机位置平移 amount
Name Type Description
amount number optional 移动量(米)。默认为 defaultMoveAmount
See:
沿相机上向量方向将相机位置平移 amount
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);
axis 旋转相机 angle。相机位置到相机参考坐标系中心的距离保持不变。
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 Object with the following properties:
Name Type Description
destination Cartesian3 | Rectangle optional 相机在世界坐标中的最终位置,或从俯视图可见的矩形。
orientation HeadingPitchRollValues | DirectionUp optional 包含 direction 和 up 属性或 heading、pitch 和 roll 属性的对象。默认情况下,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:
变换后的向量。
沿相机视图向量缩放 amount
Name Type Description
amount number optional 移动量。默认为 defaultZoomAmount
See:
沿相机视图向量的反方向缩放 amount
Name Type Description
amount number optional 移动量。默认为 defaultZoomAmount
See:

Type Definitions

Cesium.Camera.FlightCancelledCallback()

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

Cesium.Camera.FlightCompleteCallback()

飞行完成时将执行的函数。
需要帮助?获取答案的最快方式是在 Cesium 论坛 上向社区和团队提问。