1.跟隨視角
let firstView:any;
const firstPerspective = (entity: any) => {firstView = () => {let curTime = window.viewer.clock.currentTime;const pos = entity.position.getValue(curTime);const orientation = entity.orientation.getValue(curTime);if (pos && orientation) {const transform = Cesium.Matrix4.fromRotationTranslation(Cesium.Matrix3.fromQuaternion(orientation),pos);window.viewer.scene.camera.lookAtTransform(transform,new Cesium.HeadingPitchRange(Cesium.Math.toRadians(90),Cesium.Math.toRadians(-30),80));}};window.viewer.scene.preRender.addEventListener(firstView);}
2.視角清除
if (firstView) {window.viewer.scene.preRender.removeEventListener(firstView);firstView = null; // 清空引用window.viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
}