Camera

new Cesium.Camera(scene)

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

方向形成一个具有视图的正交基,向上和向右 = 视图 x 向上单位向量。

视锥体由 6 个平面定义。 每个平面都由一个 Cartesian4 对象表示,其中 x、y 和 z 分量 定义垂直于平面的单位向量,w 分量是 从原点/相机位置开始的平面。
Name Type Description
scene Scene The 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

The default rectangle the camera will view on creation.
获取当相机更改 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 和 Columbus View 中,这是可能的 表示返回的经度和纬度超出有效经度范围 和纬度(当相机位于地图外部时)。
获取相机在世界坐标中的位置。
相机的正确方向。
获取相机在世界坐标中的正确方向。

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 会尝试根据航班要行驶的距离计算理想的持续时间。 See Camera#flyTo
将摄像机从其当前位置飞到新位置。
Name Type Description
options object 对象,具有以下属性:
Name Type Description
destination Cartesian3 | Rectangle 摄像机在世界坐标中的最终位置或从自上而下的视图中可见的矩形。
orientation object optional 一个包含方向和向上属性或航向、俯仰和滚动属性的对象。默认情况下,方向将指向 在 3D 中朝向画面中心,在哥伦布视图中朝向负 z 方向。向上方向将在 3D 中指向局部北方,在正方向上指向 哥伦布视图中的 y 方向。 在无限滚动模式下,2D 中不使用 Orientation。
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)

将相机飞到当前视图包含提供的边界球体的位置。

偏移量是以边界球为中心的本地北向参考系中的 heading/pitch/range。 航向角和俯仰角在当地东西向北向上的参考系中定义。 航向是与 y 轴成的角度,并逐渐沿 x 轴增加。Pitch 是从 xy 平面开始的旋转。正间距 角度低于平面。负俯仰角位于平面上方。范围是距中心的距离。如果范围为 zero,则计算一个范围,使整个边界球体可见。

在 2D 和 Columbus View 中,必须有一个自上而下的视图。相机将放置在向下看的目标上方。高于 target 将是范围。标题将与本地北对齐。

Name Type Description
boundingSphere BoundingSphere 要查看的边界球体,以世界坐标为单位。
options object optional 对象,具有以下属性:
Name Type Description
duration number optional 飞行时间以秒为单位。 如果省略,Cesium 会尝试根据航班要行驶的距离计算理想的持续时间。
offset HeadingPitchRange optional 在以目标为中心的本地east-north-up参考系中与目标的偏移量。
complete Camera.FlightCompleteCallback optional 飞行完成时要执行的函数。
cancel Camera.FlightCancelledCallback optional 航班取消时要执行的函数。
endTransform Matrix4 optional 表示飞行完成时相机将位于的参考帧的 Transform matrix。
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 轴增加。Pitch 是从 xy 平面开始的旋转。正间距 角度低于平面。负俯仰角位于平面上方。范围是距中心的距离。 在 2D 中,必须有一个自上而下的视图。相机将放置在向下看的目标上方。高于 target 将是偏移量的大小。航向将根据偏移量确定。如果标题不能为 根据偏移量确定,航向将为北。
Name Type Description
target Cartesian3 在世界坐标中的目标位置。
offset Cartesian3 | HeadingPitchRange 在以目标为中心的本地east-north-up参考系中与目标的偏移量。
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 轴增加。Pitch 是从 xy 平面开始的旋转。正间距 角度低于平面。负俯仰角位于平面上方。范围是距中心的距离。 在 2D 中,必须有一个自上而下的视图。照相机将放置在参考帧中心的上方。高于 target 将是偏移量的大小。航向将根据偏移量确定。如果标题不能为 根据偏移量确定,航向将为北。
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)

将摄像机的位置平移 amount 沿 direction.
Name Type Description
direction Cartesian3 移动的方向。
amount number optional 要移动的量,以米为单位。默认为 defaultMoveAmount
See:

moveBackward(amount)

将摄像机的位置平移 amount 沿相反方向 的 view vector。 在 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:
如果选择了椭球体或映射, 返回 World 中椭球体或地图表面的点 坐标。如果未选取椭球体或映射,则返回 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 by 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 对象,具有以下属性:
Name Type Description
destination Cartesian3 | Rectangle optional 相机在世界坐标中的最终位置,或从自上而下视图中可见的矩形。
orientation HeadingPitchRollValues | DirectionUp optional 一个包含方向和向上属性或航向、俯仰和滚动属性的对象。默认情况下,方向将指向 在 3D 中朝向画面中心,在哥伦布视图中朝向负 z 方向。向上方向将在 3D 中指向局部北方,在正方向上指向 哥伦布视图中的 y 方向。在无限滚动模式下,2D 中不使用 Orientation。
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 中是无操作,始终为正交。

switchToPerspectiveFrustum()

将视锥体/投影切换到透视。 此函数是 2D 中的无操作,必须始终是正交的。
按量(以弧度为单位)绕其方向向量逆时针旋转相机。
Name Type Description
amount number optional 要旋转的量,以弧度为单位。默认为 defaultLookAmount
See:
按量(以弧度为单位)绕其方向向量顺时针旋转摄像机。
Name Type Description
amount number optional 要旋转的量,以弧度为单位。默认为 defaultLookAmount
See:

viewBoundingSphere(boundingSphere, offset)

设置摄像机,以便当前视图包含提供的边界球体。

偏移量是以边界球为中心的本地北向参考系中的 heading/pitch/range。 航向角和俯仰角在当地东西向北向上的参考系中定义。 航向是与 y 轴成的角度,并逐渐沿 x 轴增加。Pitch 是从 xy 平面开始的旋转。正间距 角度低于平面。负俯仰角位于平面上方。范围是距中心的距离。如果范围为 zero,则计算一个范围,使整个边界球体可见。

在 2D 中,必须有一个自上而下的视图。相机将放置在向下看的目标上方。高于 target 将是范围。航向将根据偏移量确定。如果标题不能为 根据偏移量确定,航向将为北。

Name Type Description
boundingSphere BoundingSphere 要查看的边界球体,以世界坐标为单位。
offset HeadingPitchRange optional 在以目标为中心的本地east-north-up参考系中与目标的偏移量。
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()

将在飞行结束时执行的函数。
Need help? The fastest way to get answers is from the community and team on the Cesium Forum.