ScreenSpaceCameraController是CesiumJS中的摄像机控制器,可以通过鼠标和触摸屏交互来控制场景中的摄像机。
要使用ScreenSpaceCameraController,请在Cesium Viewer对象上调用screenSpaceCameraController
属性。例如:
var viewer = new Cesium.Viewer('cesiumContainer');
viewer.screenSpaceCameraController.enableTranslate = true;
ScreenSpaceCameraController具有以下属性:
enableRotate
Boolean
true
enableTranslate
Boolean
true
enableZoom
Boolean
true
enableTilt
Boolean
true
enableLook
Boolean
true
minimumZoomDistance
Number
0.0
maximumZoomDistance
Number
Infinity
maximumPickingDistance
Number
Number.POSITIVE_INFINITY
minimumCollisionTerrainHeight
Number
0.0
minimumCollisionObjectHeight
Number
Number.NEGATIVE_INFINITY
minimumTrackBallHeight
Number
0.0
enableCollisionDetection
Boolean
true
enableLookAround
Boolean
true
enableDistanceReset
Boolean
true
enableCompass
Boolean
true
enableZoomOut
Boolean
true
enableZoomIn
Boolean
true
enableRotateLeft
Boolean
true
enableRotateRight
Boolean
true
enableRotateUp
Boolean
true
enableRotateDown
Boolean
true
enableTiltLeft
Boolean
true
enableTiltRight
Boolean
true
enableTiltUp
Boolean
true
enableTiltDown
Boolean
true
minimumPickingTerrainHeight
Number
Number.NEGATIVE_INFINITY
tiltEventTypes
Array
[Cesium.CameraEventType.LEFT_DRAG, Cesium.CameraEventType.PINCH]
rotateEventTypes
Array
[Cesium.CameraEventType.LEFT_DRAG, Cesium.CameraEventType.PINCH]
translateEventTypes
Array
[Cesium.CameraEventType.RIGHT_DRAG]
zoomEventTypes
Array
[Cesium.CameraEventType.WHEEL, Cesium.CameraEventType.PINCH]
lookEventTypes
Array
[Cesium.CameraEventType.RIGHT_DRAG]
ScreenSpaceCameraController具有以下方法:
lookAt
destination
: 待查看位置的Cartesian3,或与direction一起用于确定目标轴向的Matrix4。offset
: 相机与目标位置的偏移量。默认为Cesium.Cartesian3.ZERO
。orientation
: 相机的方向角。默认为Cesium.Matrix4.IDENTITY
。getPickRay
windowPosition
: 屏幕位置。ScreenSpaceCameraController定义了以下事件:
tiltStart
Event
tiltEnd
Event
rotateStart
Event
rotateEnd
Event
translateStart
Event
translateEnd
Event
zoomStart
Event
zoomEnd
Event
lookStart
Event
lookEnd
Event
activate
Event
deactivate
Event
以下是一个使用ScreenSpaceCameraController的简单示例:
var viewer = new Cesium.Viewer('cesiumContainer');
viewer.screenSpaceCameraController.rotateEventTypes = [Cesium.CameraEventType.RIGHT_DRAG];
viewer.screenSpaceCameraController.translateEventTypes = [Cesium.CameraEventType.LEFT_DRAG];
viewer.screenSpaceCameraController.zoomEventTypes = [Cesium.CameraEventType.MOUSE_WHEEL, Cesium.CameraEventType.PINCH];
viewer.screenSpaceCameraController.enableTranslate = true;
viewer.screenSpaceCameraController.enableZoom = true;
viewer.screenSpaceCameraController.enableTilt = true;
viewer.screenSpaceCameraController.enableRotate = true;
viewer.screenSpaceCameraController.tiltEventTypes = [Cesium.CameraEventType.RIGHT_DRAG, Cesium.CameraEventType.PINCH, Cesium.CameraEventType.LEFT_DRAG];
viewer.screenSpaceCameraController.rotateEventTypes = [Cesium.CameraEventType.RIGHT_DRAG, Cesium.CameraEventType.PINCH];
viewer.screenSpaceCameraController.translateEventTypes = [Cesium.CameraEventType.RIGHT_DRAG];
viewer.screenSpaceCameraController.changed.addEventListener(function() {
console.log("Camera changed.");
});
viewer.camera.setView({
destination: Cesium.Cartesian3.fromDegrees(-122.4194, 37.7749, 10000.0)
});
在这个例子中,我们将rotateEventTypes
设置为RIGHT_DRAG
,将translateEventTypes
设置为LEFT_DRAG
,将zoomEventTypes
设置为MOUSE_WHEEL
和PINCH
,以使这些事件触发相应的控制器操作。我们还启用了平移、缩放、倾斜和旋转控制器,设置了支持倾斜和旋转的事件类型,并注册了一个回调函数,以便在相机状态更改时记录消息。最后,我们设置了相机的初始视图并创建了一个新的Cesium Viewer。