liuyg
2021-06-28 932dc50fd51bb07e8ebb7d5ef0c711c2e062845a
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
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
///////////////////////////////////////////////////////////////////////////
// Copyright © 2019 zhongsong. All Rights Reserved.
// 模块描述:显示坐标
///////////////////////////////////////////////////////////////////////////
define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/_base/html',
    'dojo/topic',
    'jimu/BaseWidget',
    'jimu/utils',
    'jimu/css!libs/zTree_v3/css/zTreeStyle/zTreeStyle.css',
    'libs/zTree_v3/js/jquery.ztree.all'
],
    function (declare,
        lang,
        array,
        html,
        topic,
        BaseWidget,
        aspect,
        string,
        utils
    ) {
        return declare([BaseWidget], {
            baseClass: 'jimu-widget-modelDiagram',
            name: 'modelDiagram',
            layers: {},
            startup: function () {
                var that = this;
                // 暴露在外的接口
                // that.beginModelDiagram();
                // that.beginCesium();
 
                // 三个按钮事件
                $('.jimu-widget-modelDiagram').find('.once').click(() => {
                    that.once();
                })
                $('.jimu-widget-modelDiagram').find('.always').click(() => {
                    that.always();
                })
                $('.jimu-widget-modelDiagram').find('.stopPlay').click(() => {
                    that.stopPlay();
                })
 
                $('.jimu-widget-modelDiagram').find('.always').unbind("mousedown").bind("mousedown", function (event) {
                    if (event.which == 3) {
                        // console.log('you');
                        if ($("#modelDiagramCHONGFU").is(":hidden")) { //判断是否隐藏
                            $('#modelDiagramCHONGFU').show();
                            $('#modelDYes').click(() => {
                                that.getInput();
                                var W = $('#modelDiagramW').val(),
                                    H = $('#modelDiagramH').val(),
                                    JW = $('#modelDiagramJW').val(),
                                    JH = $('#modelDiagramJH').val(),
                                    as = that.a - (0.00001 * ((+H + 1) / 2)) * JH,
                                    bs = that.b - (0.00001 * ((+W + 1) / 2)) * JW;
                                for (var i = 1; i <= H; i++) {
                                    var aa = as * 100000;
                                    aa += i * JH;
                                    aa = aa / 100000;
                                    for (var n = 1; n <= W; n++) {
                                        var bb = bs * 100000;
                                        bb += n * JW;
                                        bb = bb / 100000;
                                        // console.log(aa,bb)
                                        that.always(aa, bb);
                                    }
                                }
                            })
                            $('#modelDNo').click(() => {
                                $('#modelDiagramCHONGFU').hide();
                            })
                        }
                    } else if (event.which == 1) {
                        // console.log('zuo');
                    }
                });
 
                $('.jimu-widget-modelDiagram').find('.closesmodelDiagram').click(() => {
                    $('.jimu-widget-modelDiagram').hide();
                    that.stopPlay();
                })
                //初演示
                layui.use(['dropdown', 'util', 'layer', 'table'], function () {
                    var dropdown = layui.dropdown,
                        layer = layui.layer;
                    dropdown.render({
                        elem: '.models',
                        data: [{
                            title: '人偶',
                            value: './images/gltf/Cesium_Man.glb',
                            id: 100,
                            num: [3, 3, 1, 1]
                        }, {
                            title: '飞机',
                            value: './images/gltf/Cesium_Air.glb',
                            id: 101,
                            num: [3, 3, 30, 30]
                        }, {
                            title: '飞机2',
                            value: './images/gltf/CesiumDrone.glb',
                            id: 102,
                            num: [3, 3, 7, 7]
                        }, {
                            title: '装甲车',
                            value: './images/gltf/GroundVehicle.glb',
                            id: 103,
                            num: [3, 3, 4, 9]
                        }, {
                            title: '热气球',
                            value: './images/gltf/CesiumBalloon.glb',
                            id: 104,
                            num: [3, 3, 15, 17]
                        }, {
                            title: '牛奶车',
                            value: './images/gltf/CesiumMilkTruck.glb',
                            id: 105,
                            num: [3, 3, 3, 5]
                        }, {
                            title: '牛奶车gltf',
                            value: './images/gltf/CesiumMilkTruck.gltf',
                            id: 106,
                            num: [3, 3, 3, 5]
                        }, {
                            title: '人gltf',
                            value: './images/gltf/walk.gltf',
                            id: 107,
                            num: [3, 3, 1, 1]
                        }],
                        click: function (obj) {
                            layer.tips('选择了:' + obj.title, this.elem, {
                                tips: [1, '#5FB878']
                            });
                            that.urls = obj.value;
                            var dom = $('.models');
                            dom.empty();
                            var str = `${obj.title} <i class="layui-icon layui-icon-down layui-font-12"></i>`
                            dom.append(str);
                            a = obj.num[2];
                            b = obj.num[3];
                            that.getInput();
                            var neWnum = [obj.num[0], obj.num[1], obj.num[2] * that.scale, obj.num[3] * that.scale]
                            that.setNum(neWnum);
                        }
                    });
                });
                var a = 1;
                var b = 1;
                $("#modelDiagrambeishu").on("input", function () {
                    // $('#modelDiagramW').val();
                    var it = $(this).val();
                    $('#modelDiagramJW').val(a * it);
                    // $('#modelDiagramH').val();
                    $('#modelDiagramJH').val(b * it);
                    // console.log(a, b, it)
                });
 
            },
            urls: './images/gltf/Cesium_Man.glb',
            setNum: function (num) {
                $('#modelDiagramW').val(num[0])
                $('#modelDiagramH').val(num[1])
                $('#modelDiagramJW').val(num[2])
                $('#modelDiagramJH').val(num[3])
            },
            beginCesium: function (a, b, g, once, scale) {
                var viewer = this.map,
                    that = this,
                    url = that.urls;
 
                //静态
                // var position = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468, 1000);
 
                // console.log(a, b, g, scale)
 
                var position = Cesium.Cartesian3.fromDegrees(a, b, g);
                that.entityPeople = viewer.entities.add({ //viewer.trackedEntity跟随
                    name: url,
                    position: position,
                    model: {
                        uri: url,
                        scale: scale
                    },
                });
 
 
 
                if (once == 'once') {
                    // viewer.trackedEntity = that.entityPeople;
                    var gg = g + scale * 6;
                    that.map.camera.flyTo({
                        destination: Cesium.Cartesian3.fromDegrees(a, b, gg),
                        duration: 3
                    });
                }
 
 
            },
            stopPlay: function () {
                this.map.entities.removeAll();
                // clearInterval(this.time);
            },
            seemodo: function () {
                var that = this;
                if (that.seeEntity) {
                    this.map.trackedEntity = that.entityPeople; //目标视野跟踪
                } else {
                    this.map.trackedEntity = '';
                }
                that.seeEntity = !that.seeEntity;
                console.log(that.seeEntity)
                // console.log('seedom')
                // this.map.entities.remove(this.entityPeople)//删除entity
            },
            getInput: function () {
                this.a = $('#modelDiagramjdu').val() == '' ? 116.058987 : +$('#modelDiagramjdu').val();
                this.b = $('#modelDiagramwdu').val() == '' ? 28.973468 : +$('#modelDiagramwdu').val();
                this.g = $('#modelDiagramgdu').val() == '' ? 1000 : +$('#modelDiagramgdu').val();
                this.scale = $('#modelDiagrambeishu').val() == '' ? 1000 : +$('#modelDiagrambeishu').val();
            },
            a: '',
            b: '',
            g: '',
            scale: '',
            //重复添加
            always: function (aa = 'a', bb = 'b') {
                this.getInput();
                // console.log([a, b, g])
                if (aa != 'a' && bb != 'b') {
                    this.beginCesium(aa, bb, this.g, '', this.scale);
                } else {
                    this.beginCesium(this.a, this.b, this.g, '', this.scale);
                }
            },
            //单次添加
            once: function () {
                this.stopPlay();
                this.getInput();
                // console.log([a, b, g])
                this.beginCesium(this.a, this.b, this.g, 'once', this.scale);
            },
 
            onClose: function () {
                //面板关闭的时候触发 (when this panel is closed trigger)
            },
 
            onMinimize: function () {
                this.resize();
            },
 
            onMaximize: function () {
                this.resize();
            },
 
            resize: function () {
 
            },
 
 
            destroy: function () {
                //销毁的时候触发
                //todo
                //do something before this func
                this.inherited(arguments);
            }
 
        });
    });