liuyg
2021-07-02 25ce610f6ecca7325e7a743dc032c4a76559c63d
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
230
231
232
233
234
235
236
237
238
239
240
241
242
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-clippingPlanes',
            name: 'clippingPlanes',
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginclippingPlanes", lang.hitch(this, this.beginclippingPlanes));
                topic.subscribe("closesclippingPlanes", lang.hitch(this, this.closesclippingPlanes));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesclippingPlanes();
                })
 
 
                // that.beginclippingPlanes();
 
            },
            beginclippingPlanes: function (promise) {
                // console.log(`${this.name}--kaishi`);
                var that = this;
                var viewer = that.map;
                // 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;
                // try{
                //场景添加S3M图层服务
                that.isClearBut = true;
                // that.promise = scene.open(window.MYURL_CONFIG.SCENE_BIMBUILDING);
                // console.log(promise, 444444444444444)
                that.promise = promise.src;
                Cesium.when(that.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
                    //         }
                    //     });
                    // var name = scene.layers._layers._hash;
                    // for (var a in name) {
                    //     name = a;
                    // }
                    // console.log(name)
                    var layer = scene.layers.find(promise.name);
                    // console.log(layer, 55555555555555)
                    if (layer == undefined) {
                        console.log('不支持')
                        window.layer.tips('该图层不支持平面裁剪!', '.SelectLayerTool', {
                        tips: [3, 'red']
                        });
                        if ($(".jimu-widget-clippingPlanes").is(":visible")) {//判断是否隐藏
                            $(".jimu-widget-clippingPlanes").hide();
                            topic.publish('closesclippingPlanes');
                        }
                        return;
                    }
 
                    layer.selectEnabled = false;
                    // //设置被裁剪对象的颜色
                    layer.clipLineColor = new Cesium.Color(1, 1, 1, 0);
                    that.BIMLayer = layer;
                    // if (!scene.pickPositionSupported) {
                    //     alert('不支持深度纹理,无法拾取位置!');
                    // }
                    // }, function (e) {
                    //     if (widget._showRenderLoopErrors) {
                    //         var title = '加载SCP失败,请检查网络连接状态或者url地址是否正确?';
                    //         widget.showErrorPanel(title, undefined, e);
                    //     }
                });
                // }
                // catch(e){
                //     if (widget._showRenderLoopErrors) {
                //         var title = '渲染时发生错误,已停止渲染。';
                //         widget.showErrorPanel(title, undefined, e);
                //     }
                // }
 
 
                var clampMode = Cesium.ClampMode.Space;
                that.tooltip = window.MYcreateTooltip(document.body);
                that.handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, clampMode);
                var i = 0;
                that.handlerPolygon.activeEvt.addEventListener(function (isActive) {
                    if (isActive == true) {
                        viewer.enableCursorStyle = false;
                        viewer._element.style.cursor = '';
                        $('body').removeClass('drawCur').addClass('drawCur');
                        that.isClearBut = false;
                        Usebody();
                        i = 0;
                    }
                    else {
                        viewer.enableCursorStyle = true;
                        $('body').removeClass('drawCur');
                        if (that.isClearBut == false) {
                            if (i < 3) {
                                that.tooltip.setVisible(false);
                                layer.tips('不足三个点请重新绘画!', '#polygonclippingPlanes', {
                                    tips: [3, 'red']
                                });
                            }
                        }
                        Endbody();
                    }
                });
                that.handlerPolygon.movingEvt.addEventListener(function (windowPosition) {
                    // console.log(i)
                    if (that.handlerPolygon.isDrawing) {
                        that.tooltip.showAt(windowPosition, '<p>只需要设置三个点!</p>');
                    }
                    else {
                        that.tooltip.showAt(windowPosition, '<p>点击绘制第一个点</p>');
                    }
                    if (i == 3) {
                        that.tooltip.showAt(windowPosition, '<p>请点击右键!</p>');
                    }
                    if (i > 3) {
                        that.tooltip.showAt(windowPosition, '<p>超过3个的点不生效!</p>');
                    }
                });
                that.handlerPolygon.drawEvt.addEventListener(function (result) {
 
                    var positions = result.object.positions;
                    // console.log(that.handlerPolygon.polygon, 12434)
                    that.tooltip.setVisible(false);
                    that.handlerPolygon.polygon.show = false;
                    // 通过多边形的顶点设置裁剪面,裁剪方向为裁剪面的法线方向
                    that.BIMLayer.setCustomClipPlane(positions[0], positions[1], positions[2]);
 
                });
                var Usebody = () => {
                    i = 0;
                    $('.cesium-widget').click(() => {
                        i++;
                    })
                }
                var Endbody = () => {
                    i = 0;
                    $(".cesium-widget").unbind()
                }
 
                $('#polygonclippingPlanes').click(function () {
                    that.handlerPolygon.activate();
                });
 
                $('#clearclippingPlanes').click(function () {
                    that.isClearBut = true;
                    that.handlerPolygon.clear();
                    that.isClearBut = false;
                    //清除裁剪结果
                    that.BIMLayer.clearCustomClipBox();
                    Endbody();
                    // if ()
 
                });
                $('#toolbarclippingPlanes').show();
                $('#loadingbar').remove();
                if (!scene.pickPositionSupported) {
                    alert('不支持深度拾取,无法进行鼠标交互绘制!');
                }
 
            },
            tooltip: '',
            handlerPolygon: '',
            BIMLayer: '',
            isClearBut: '',
            promise: '',
            closesclippingPlanes: function (froms) {
                // console.log(`${this.name}--guanbi`);
                var that = this;
 
                that.isClearBut = true;
                if (that.handlerPolygon) {
                    that.handlerPolygon.clear();
                }
                that.isClearBut = false;
                //清除裁剪结果
                if (that.BIMLayer != '') {
                    that.BIMLayer.clearCustomClipBox();
                }
                $(".cesium-widget").unbind();
 
                // if (that.promise != '') {
                //     Cesium.when(that.promise, function (layer) {
                //         for (var i = 0; i < layer.length; i++) {
                //             that.map.scene.layers.remove(layer[i].name)
                //         }
                //     })
                // }
            },
            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);
            }
 
        });
    });