liuyg
2021-06-30 1b22efb7fa9d35c531e5f4ff2e6d600c23a6546d
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/_base/html',
    'dojo/topic',
    'jimu/BaseWidget',
],
    function (declare,
        lang,
        array,
        html,
        topic,
        BaseWidget
    ) {
        return declare([BaseWidget], {
            baseClass: 'jimu-widget-BOXInteractive',
            name: 'BOXInteractive',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginBOXInteractive", lang.hitch(this, this.beginBOXInteractive));
                topic.subscribe("closesBOXInteractive", lang.hitch(this, this.closesBOXInteractive));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesBOXInteractive();
                })
 
 
                // that.beginBOXInteractive();
 
            },
            beginBOXInteractive: function () {
                console.log(`${this.name}--kaishi`);
                var that = this;
 
                var viewer = that.map;
                var URL_CONFIG = window.MYURL_CONFIG;
                viewer.imageryLayers.addImageryProvider(new Cesium.BingMapsImageryProvider({
                    url: 'https://dev.virtualearth.net',
                    mapStyle: Cesium.BingMapsStyle.AERIAL,
                    key: URL_CONFIG.BING_MAP_KEY
                }));
 
                var scene = viewer.scene;
                var widget = viewer.cesiumWidget;
                $('#toolbarBOXInteractive').show();
                $('#loadingbarBOXInteractive').remove();
 
                var promise = scene.open(URL_CONFIG.SCENE_BIMBUILDING);
                Cesium.when(promise, function (layers) {
                    // 精准定位
                    scene.camera.setView({
                        destination: new Cesium.Cartesian3(-2180753.065987198, 4379023.266141494, 4092583.575045952),
                        orientation: {
                            heading: 4.0392222751147955,
                            pitch: 0.010279641987852584,
                            roll: 1.240962888005015e-11
                        }
                    });
                    // 设置裁剪线颜色
                    setAllLayersClipColor();
                    var boxEntity = undefined;
                    var $clipMode = $('#clipModeBOXInteractive');
 
                    var tooltip = window.MYcreateTooltip(document.body);
 
                    //交互绘制box
 
                    // Cesium.DrawMode.Box = 4;
                    // console.log(Cesium.DrawMode.Box, 4634343)
                    // var handlerBox = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Box);
                    var handlerBox = new Cesium.DrawHandler(viewer, 4);
                    var editorBox;
 
                    handlerBox.activeEvt.addEventListener(function (isActive) {
                        if (isActive == true) {
                            viewer.enableCursorStyle = false;
                            viewer._element.style.cursor = '';
                            $('body').removeClass('drawCurshizi').addClass('drawCurshizi');
                        }
                        else {
                            viewer.enableCursorStyle = true;
                            $('body').removeClass('drawCurshizi');
                        }
                    });
                    handlerBox.movingEvt.addEventListener(function (windowPosition) {
 
                        if (handlerBox.isDrawing) {
                            tooltip.showAt(windowPosition, '<p>点击鼠标左键结束矩形绘制,移动鼠标绘制box高度。</p><p>右键结束绘制.</p>');
                        } else {
                            tooltip.showAt(windowPosition, '<p>点击鼠标左键,开始绘制矩形作为box底面</p>');
                        }
 
                    });
                    handlerBox.drawEvt.addEventListener(function (e) {
                        console.log(88888888888888888888)
                        tooltip.setVisible(false);
                        // boxEntity = e.object;
                        // var newDim = boxEntity.box.dimensions.getValue();
                        // var position = boxEntity.position.getValue(0);
                        // var boxOption = {
                        //     dimensions: newDim,
                        //     position: position,
                        //     clipMode: $clipMode.val(),
                        //     heading: 0
                        // };
 
                        // //box编辑
                        // editorBox = new Cesium.BoxEditor(viewer, boxEntity);
 
                        // editorBox.editEvt.addEventListener(function (e) {
                        //     boxEntity.box.dimensions = e.dimensions
                        //     boxEntity.position = e.position;
                        //     boxEntity.orientation = e.orientation;
 
                        //     setClipBox();
                        // });
                        // editorBox.distanceDisplayCondition = new Cesium.DistanceDisplayCondition(0, 950);
                        // editorBox.activate();
                        // setAllLayersClipOptions(boxOption);
                        // tooltip.setVisible(false);
                        // handlerBox.clear();
                        // handlerBox.deactivate();
                    });
                    handlerBox.activate();
 
                    $('#clearboxBOXInteractive').click(function () {
                        for (var i = 0, j = layers.length; i < j; i++) {
                            layers[i].clearCustomClipBox();
                        };
                        editorBox.deactivate();
                        viewer.entities.removeAll();
                        handlerBox.clear();
                        handlerBox.deactivate();
                        handlerBox.activate();
 
                    });
 
                    $clipMode.change(function () {
                        setClipBox();
                    });
 
                    function setClipBox() {
                        var clipMode = $clipMode.val();
                        if (typeof (boxEntity) == "undefined") {
                            return;
                        }
                        var newDim = boxEntity.box.dimensions.getValue();
                        var position = boxEntity.position.getValue(0);
 
                        var heading = 0;
                        if (typeof (boxEntity.orientation) != "undefined") {
                            let rotationM3 = Cesium.Matrix3.fromQuaternion(boxEntity.orientation._value, new Cesium.Matrix3());
                            let localFrame = Cesium.Matrix4.fromRotationTranslation(rotationM3, Cesium.Cartesian3.ZERO, new Cesium.Matrix4());
                            let inverse = Cesium.Matrix4.inverse(Cesium.Transforms.eastNorthUpToFixedFrame(position), new Cesium.Matrix4());
                            let hprm = Cesium.Matrix4.multiply(inverse, localFrame, new Cesium.Matrix4());
                            var rotation = Cesium.Matrix4.getMatrix3(hprm, new Cesium.Matrix3());
                            let hpr = Cesium.HeadingPitchRoll.fromQuaternion(Cesium.Quaternion.fromRotationMatrix(rotation));
                            heading = hpr.heading;
                        }
 
 
                        var boxOptions = {
                            dimensions: newDim,
                            position: position,
                            clipMode: clipMode,
                            heading: heading
                        };
                        setAllLayersClipOptions(boxOptions);
                    }
 
                    function setAllLayersClipColor() {
                        for (var i = 0, j = layers.length; i < j; i++) {
                            layers[i].clipLineColor = new Cesium.Color(1, 1, 1, 0);
                            console.log(layers[i].clipLineColor, 4444444444444)
                        }
                    }
 
                    function setAllLayersClipOptions(boxOptions) {
                        console.log(5555555555555)
                        for (var i = 0, j = layers.length; i < j; i++) {
                            layers[i].setCustomClipBox(boxOptions);
                        }
                    }
 
                }, function (e) {
                    if (widget._showRenderLoopErrors) {
                        var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                        widget.showErrorPanel(title, undefined, e);
                    }
                });
 
            },
            closesBOXInteractive: function (froms) {
                console.log(`${this.name}--guanbi`);
                var that = this;
            },
            onOpen: function () {
 
            },
 
            onClose: function () {
                //面板关闭的时候触发 (when this panel is closed trigger)
                console.log('jies')
            },
 
            onMinimize: function () {
                this.resize();
            },
 
            onMaximize: function () {
                this.resize();
            },
 
            resize: function () {
 
            },
 
            destroy: function () {
                //销毁的时候触发
                //todo
                //do something before this func
                this.inherited(arguments);
            }
 
        });
    });