const mapScreen = { DoubleScreen: null, rightHandler: null, leftHandler: null, isScreen: null, Init() { this.isScreen = true; this.getLeftCameraView(); setTimeout(() => { this.addLeftCameraChangeHandler(); this.addRightCameraChangeHandler(); this.addMouseMoveHandle(); }, 1000); }, edit() { if (this.leftHandler) { this.leftHandler.removeInputAction( Cesium.ScreenSpaceEventType.MOUSE_MOVE ); //移除事 this.leftHandler = null; } if (this.rightHandler) { this.rightHandler.removeInputAction( Cesium.ScreenSpaceEventType.MOUSE_MOVE ); //移除事 this.rightHandler = null; } this.isScreen = false; }, addMouseMoveHandle() { var that = this; window.Viewer.scene.postRender.addEventListener(() => { if (that.DoubleScreen == "LEFT") { this.getLeftCameraView(); } }); window.Viewer2.scene.postRender.addEventListener(() => { if (that.DoubleScreen == "RIGHT") { this.getRightCameraView(); } }); }, addLeftCameraChangeHandler() { var that = this; this.leftHandler = new Cesium.ScreenSpaceEventHandler(window.Viewer.canvas); this.leftHandler.setInputAction(() => { that.DoubleScreen = "LEFT"; }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); }, addRightCameraChangeHandler() { var that = this; this.rightHandler = new Cesium.ScreenSpaceEventHandler( window.Viewer2.canvas ); this.rightHandler.setInputAction(() => { that.DoubleScreen = "RIGHT"; }, Cesium.ScreenSpaceEventType.MOUSE_MOVE); }, getLeftCameraView() { const destination = Cesium.Cartographic.toCartesian( window.Viewer.camera.positionCartographic ); window.Viewer2.camera.setView({ destination: new SmartEarth.Cesium.Cartesian3( destination.x, destination.y, destination.z ), orientation: { heading: window.Viewer.camera.heading, pitch: window.Viewer.camera.pitch, roll: window.Viewer.camera.roll, }, }); }, getRightCameraView() { const destination = Cesium.Cartographic.toCartesian( window.Viewer2.camera.positionCartographic ); window.Viewer.camera.setView({ destination: new SmartEarth.Cesium.Cartesian3( destination.x, destination.y, destination.z ), orientation: { heading: window.Viewer.camera.heading, pitch: window.Viewer.camera.pitch, roll: window.Viewer.camera.roll, }, }); }, exit() {}, }; export default mapScreen;