cesium 相机以某点为中心旋转

发布时间 2023-07-20 10:43:44作者: 博客sl
 renderTargetCamera() {
        const { viewer } = this.state
        const _this = this

        viewer.camera.moveEnd.addEventListener(function () {

            const { gpsamera, cameraHeightInit } = _this.state
            let cameraHeight = cameraHeightInit
            let gpsPoint = gpsamera[0][0]
            if (!gpsamera) { return }
            // console.log('cameraHeight--', gpsPoint, cameraHeight)
            if (!cameraHeight) {
                // 倾斜之后,需调整相机高度
                cameraHeight = Math.round(viewer.camera.positionCartographic.height);
                // viewer.zoomTo(_labelEntity, new Cesium.HeadingPitchRange(0.0, Cesium.Math.toRadians(-25.0), cameraHeight));
                _this.setState({ cameraHeightInit: cameraHeight })
                setTimeout(function () {
                    let center = Cesium.Cartesian3.fromDegrees(gpsPoint.lng, gpsPoint.lat, 1000.0);
                    viewer.camera.lookAt(center, new Cesium.HeadingPitchRange(0.0, -Math.PI / 4, cameraHeight));
                }, 300)

            }

        });
    }