CameraEventAggregator 是 Cesium 中用于管理相机事件的类,可以帮助我们对相机事件进行统一管理和监听。
new Cesium.CameraEventAggregator(element);
| 名称 | 类型 | 描述 |
|---|---|---|
| element | Element |
相机所在 DOM 元素 |
aggregatorCameraEventAggregator 类中通过 aggregator 属性暴露了一个 CameraEventAggregatorService 的实例,可以通过它调用具体的方法,如 isMoving() 方法。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let isMoving = cameraEventAggregator.aggregator.isMoving();
lastMovement获取相机上一次移动的时间。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let lastMovementTime = cameraEventAggregator.lastMovement;
lastTilt获取相机上一次进行俯仰的时间。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let lastTiltTime = cameraEventAggregator.lastTilt;
lastRotate获取相机上一次进行旋转的时间。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let lastRotateTime = cameraEventAggregator.lastRotate;
lastZoom获取相机上一次进行缩放的时间。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let lastZoomTime = cameraEventAggregator.lastZoom;
isMoving()检查相机是否正在移动。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let isMoving = cameraEventAggregator.aggregator.isMoving();
isTilting()检查相机是否正在进行俯仰。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let isTilting = cameraEventAggregator.aggregator.isTilting();
isRotating()检查相机是否正在旋转。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let isRotating = cameraEventAggregator.aggregator.isRotating();
isZooming()检查相机是否正在缩放。
let cameraEventAggregator = new Cesium.CameraEventAggregator(element);
let isZooming = cameraEventAggregator.aggregator.isZooming();
let viewer = new Cesium.Viewer("cesiumContainer");
let cameraEventAggregator = new Cesium.CameraEventAggregator(viewer.scene.canvas);
viewer.clock.onTick.addEventListener(function () {
if (cameraEventAggregator.isMoving()) {
console.log("Camera is moving");
}
});
viewer.camera.changed.addEventListener(function() {
console.log("Camera has changed.");
});
在使用 CameraEventAggregator 类时,需要注意以下几点。
CameraEventAggregator 对象的回调函数中,不要涉及到更改或设置相机的代码,如果需要更改或设置相机,请借助 Clock 类来进行操作。CameraEventAggregator 类只能用于统计相机的操作次数和时间,不能用于做过高过低等操作。CameraEventAggregator 对象创建为全局变量,这样可以在需要监听相机事件时直接调用。