ansel0926
2022-05-15 ebc4c778854c8d2666b1bbaf3dcba2ba00f08453
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"use strict";
 
window.Cesium3dTilesetLocationEditor = (function () {
    function _(cesiumViewer, tileset) {
        this._cesiumViewer = cesiumViewer;
        this._scene = cesiumViewer.scene;
        this._tileset = tileset;
        this._screenSpaceHandler = null;        
 
        this._leftDown= false;
        this._leftDownCartesian = null;
        this._tilesetModelMatrixWhenLeftDown = null;       
        this._initEventHandlers();        
        this._center = tileset.boundingSphere.center.clone();
        this._x = tileset._offsetx;
        this._y = tileset._offsety;
        this._z = tileset._offsetz;        
        this._visible = true;
    }
 
    _.prototype._disableDefaultCameraController = function () {
        var scene = this._cesiumViewer.scene;
 
        // disable the default event handlers
 
        scene.screenSpaceCameraController.enableRotate = false;
        scene.screenSpaceCameraController.enableTranslate = false;
        scene.screenSpaceCameraController.enableZoom = false;
        scene.screenSpaceCameraController.enableTilt = false;
        scene.screenSpaceCameraController.enableLook = false;
    };
 
    _.prototype._enableDefaultCameraController = function () {
        var scene = this._cesiumViewer.scene;
 
        // disable the default event handlers
 
        scene.screenSpaceCameraController.enableRotate = true;
        scene.screenSpaceCameraController.enableTranslate = true;
        scene.screenSpaceCameraController.enableZoom = true;
        scene.screenSpaceCameraController.enableTilt = true;
        scene.screenSpaceCameraController.enableLook = true;
    };
 
    _.prototype._initEventHandlers = function() {
        this._screenSpaceHandler = new Cesium.ScreenSpaceEventHandler(this._scene.canvas);
 
        var self = this;
 
        this._screenSpaceHandler.setInputAction(function(movement) {
            if(!self._visible)
                return;
 
            self._onScreeSpaceLeftDown(movement);
        }, Cesium.ScreenSpaceEventType.LEFT_DOWN);
 
        this._screenSpaceHandler.setInputAction(function(movement) {
            if(!self._visible)
                return;
 
            self._onScreeSpaceMove(movement);
        }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
 
        this._screenSpaceHandler.setInputAction(function(movement) {
            if(!self._visible)
                return;
 
            self._onScreeSpaceLeftUp(movement);
        }, Cesium.ScreenSpaceEventType.LEFT_UP);
 
    };
 
    _.prototype._onScreeSpaceLeftDown = function(movement) {
        
 
        var pick = viewer.scene.pick(movement.position);
 
        if (!Cesium.defined(pick))
            return;
        this._leftDown = true;
        this._disableDefaultCameraController();
        console.log("down");  
    };
 
    _.prototype._onScreeSpaceLeftUp = function(movement) {
        this._leftDown = false;
        console.log("up");    
        this._enableDefaultCameraController();
    };
 
    _.prototype._onScreeSpaceMove = function(movement) {
        if(!this._leftDown)
            return;
        console.log("move");
        var a  = this._cesiumViewer.scene.pickPosition(movement.endPosition);
        var cartographic = Cesium.Cartographic.fromCartesian(a);
        const cartographic2 = Cesium.Cartographic.fromCartesian(
            this._center
        );
        const surface = Cesium.Cartesian3.fromRadians(
            cartographic2.longitude,
            cartographic2.latitude,
            0.0
        );
        var height = $("#modelZ").val();
        const offset = Cesium.Cartesian3.fromRadians(
            cartographic.longitude,
            cartographic.latitude,
            height
        );
        const translation = Cesium.Cartesian3.subtract(
            offset,
            surface,
            new Cesium.Cartesian3()
        );
        this._tileset.modelMatrix = Cesium.Matrix4.fromTranslation(translation);  
        $("#modelX").val(a.x - this._center.x + this._x);
        $("#modelY").val(a.y - this._center.y + this._y);
        // $("#modelZ").val(a.z - this._center.z + this._z);
        // $("#modelX").val(a.x - this._center.x);
        // $("#modelY").val(a.y - this._center.y);
        // $("#modelZ").val(a.z - this._center.z);              
    };
    
    _.prototype.setVisible = function(visible)
    {
        this._visible = visible;       
    };
 
    return _;
}());