基于亦庄一张图系统为模板创建的Demo系统
surprise
2024-04-16 f51e0da4c397110b2916a9dc371b6d745042029d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
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;