liuyg
2021-06-19 66f2854366a59a2194ac51e67e5c6ddc29b20ff3
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
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
///////////////////////////////////////////////////////////////////////////
// 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();
 
                $('.seemodo').click(() => {
                    that.seemodo();
                })
 
                $('.closemodo').click(() => {
                    that.closeModo();
                })
                $('.beginPlay').click(() => {
                    that.beginPlay();
                })
                $('.stopPlay').click(() => {
                    that.stopPlay();
                })
                $('.closesmodelDiagram').click(() => {
                    console.log(3423)
                    $('.jimu-widget-modelDiagram').hide();
                    if (that.openEntity) {
                        that.map.entities.removeAll();
                    }
                })
 
            },
            beginCesium: function (a = 116.058987, b = 28.973468, g = 1000) {
                var viewer = this.map
                    , that = this
                    , url = "./images/gltf/Cesium_Man.glb";
                // var startPosition = new Cesium.Cartesian3(
                //     116.058987,
                //     28.973468,
                //     1000
                // );
                // var endPosition = new Cesium.Cartesian3(
                //     116.158987,
                //     29.073468,
                //     1000
                // );
                // var position = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468);
                //动态 //缺少viewer.timeline时间轴
                //Make sure viewer is at the desired time.
                //Make sure viewer is at the desired time.
                // var start = Cesium.JulianDate.fromDate(new Date(2018, 11, 12, 15));
                // var totalSeconds = 10;
                // var stop = Cesium.JulianDate.addSeconds(
                //     start,
                //     totalSeconds,
                //     new Cesium.JulianDate()
                // );
                // viewer.clock.startTime = start.clone();
                // viewer.clock.stopTime = stop.clone();
                // viewer.clock.currentTime = start.clone();
                // viewer.clock.clockRange = Cesium.ClockRange.LOOP_STOP;
                // // console.log(viewer.timeline,111)
                // viewer.timeline.zoomTo = function (startTime, stopTime) {
                //     //>>includeStart('debug', pragmas.debug);
                //     if (!defined(startTime)) {
                //         throw new DeveloperError("startTime is required.");
                //     }
                //     if (!defined(stopTime)) {
                //         throw new DeveloperError("stopTime is required");
                //     }
                //     if (JulianDate.lessThanOrEquals(stopTime, startTime)) {
                //         throw new DeveloperError("Start time must come before end time.");
                //     }
                //     //>>includeEnd('debug');
 
                //     this._startJulian = startTime;
                //     this._endJulian = stopTime;
                //     this._timeBarSecondsSpan = JulianDate.secondsDifference(stopTime, startTime);
 
                //     // If clock is not unbounded, clamp timeline range to clock.
                //     if (this._clock && this._clock.clockRange !== ClockRange$1.UNBOUNDED) {
                //         var clockStart = this._clock.startTime;
                //         var clockEnd = this._clock.stopTime;
                //         var clockSpan = JulianDate.secondsDifference(clockEnd, clockStart);
                //         var startOffset = JulianDate.secondsDifference(
                //             clockStart,
                //             this._startJulian
                //         );
                //         var endOffset = JulianDate.secondsDifference(clockEnd, this._endJulian);
 
                //         if (this._timeBarSecondsSpan >= clockSpan) {
                //             // if new duration longer than clock range duration, clamp to full range.
                //             this._timeBarSecondsSpan = clockSpan;
                //             this._startJulian = this._clock.startTime;
                //             this._endJulian = this._clock.stopTime;
                //         } else if (startOffset > 0) {
                //             // if timeline start is before clock start, shift right
                //             this._endJulian = JulianDate.addSeconds(
                //                 this._endJulian,
                //                 startOffset,
                //                 new JulianDate()
                //             );
                //             this._startJulian = clockStart;
                //             this._timeBarSecondsSpan = JulianDate.secondsDifference(
                //                 this._endJulian,
                //                 this._startJulian
                //             );
                //         } else if (endOffset < 0) {
                //             // if timeline end is after clock end, shift left
                //             this._startJulian = JulianDate.addSeconds(
                //                 this._startJulian,
                //                 endOffset,
                //                 new JulianDate()
                //             );
                //             this._endJulian = clockEnd;
                //             this._timeBarSecondsSpan = JulianDate.secondsDifference(
                //                 this._endJulian,
                //                 this._startJulian
                //             );
                //         }
                //     }
 
                //     this._makeTics();
 
                //     var evt = document.createEvent("Event");
                //     evt.initEvent("setzoom", true, true);
                //     evt.startJulian = this._startJulian;
                //     evt.endJulian = this._endJulian;
                //     evt.epochJulian = this._epochJulian;
                //     evt.totalSpan = this._timeBarSecondsSpan;
                //     evt.mainTicSpan = this._mainTicSpan;
                //     this._topDiv.dispatchEvent(evt);
                // }
                // viewer.timeline.zoomTo(start, stop);
 
                // // Create a path for our vehicle by lerping between two positions.
                // var position = new Cesium.SampledPositionProperty();
                // var startPosition = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468, 1000);
                // var endPosition = Cesium.Cartesian3.fromDegrees(116.158987, 29.073468, 1000);
                // // var startPosition = new Cesium.Cartesian3(
                // //     -2379556.799372864,
                // //     -4665528.205030263,
                // //     3628013.106599678
                // // );
                // // var endPosition = new Cesium.Cartesian3(
                // //     -2379603.7074103747,
                // //     -4665623.48990283,
                // //     3627860.82704567
                // // );
                // // A velocity vector property will give us the entity's speed and direction at any given time.
                // var velocityVectorProperty = new Cesium.VelocityVectorProperty(
                //     position,
                //     false
                // );
                // var velocityVector = new Cesium.Cartesian3();
                // // Store the wheel's rotation over time in a SampledProperty.
                // var wheelAngleProperty = new Cesium.SampledProperty(Number);
                // var wheelAngle = 0;
 
                // var numberOfSamples = 100;
                // for (var i = 0; i <= numberOfSamples; ++i) {
                //     var factor = i / numberOfSamples;
                //     var time = Cesium.JulianDate.addSeconds(
                //         start,
                //         factor * totalSeconds,
                //         new Cesium.JulianDate()
                //     );
 
                //     // Lerp using a non-linear factor so that the vehicle accelerates.
                //     var locationFactor = Math.pow(factor, 2);
                //     var location = Cesium.Cartesian3.lerp(
                //         startPosition,
                //         endPosition,
                //         locationFactor,
                //         new Cesium.Cartesian3()
                //     );
                //     position.addSample(time, location);
                //     // Rotate the wheels based on how fast the vehicle is moving at each timestep.
                //     velocityVectorProperty.getValue(time, velocityVector);
                //     var metersPerSecond = Cesium.Cartesian3.magnitude(velocityVector);
                //     var wheelRadius = 0.52; //in meters.
                //     var circumference = Math.PI * wheelRadius * 2;
                //     var rotationsPerSecond = metersPerSecond / circumference;
 
                //     wheelAngle +=
                //         ((Math.PI * 2 * totalSeconds) / numberOfSamples) *
                //         rotationsPerSecond;
                //     wheelAngleProperty.addSample(time, wheelAngle);
                // }
 
                // function updateSpeedLabel(time, result) {
                //     velocityVectorProperty.getValue(time, velocityVector);
                //     var metersPerSecond = Cesium.Cartesian3.magnitude(velocityVector);
                //     var kmPerHour = Math.round(metersPerSecond * 3.6);
 
                //     return kmPerHour + " km/hr";
                // }
 
                // var rotationProperty = new Cesium.CallbackProperty(function (
                //     time,
                //     result
                // ) {
                //     return Cesium.Quaternion.fromAxisAngle(
                //         Cesium.Cartesian3.UNIT_X,
                //         wheelAngleProperty.getValue(time),
                //         result
                //     );
                // },
                //     false);
 
                // var wheelTransformation = new Cesium.NodeTransformationProperty({
                //     rotation: rotationProperty,
                // });
 
                // var nodeTransformations = {
                //     Wheels: wheelTransformation,
                //     Wheels_mid: wheelTransformation,
                //     Wheels_rear: wheelTransformation,
                // };
 
                // // Add our vehicle model.
                // var vehicleEntity = viewer.entities.add({
                //     position: position,
                //     orientation: new Cesium.VelocityOrientationProperty(position), // Automatically set the vehicle's orientation to the direction it's facing.
                //     model: {
                //         uri: url,
                //         runAnimations: false,
                //         nodeTransformations: nodeTransformations,
                //     },
                //     label: {
                //         text: new Cesium.CallbackProperty(updateSpeedLabel, false),
                //         font: "20px sans-serif",
                //         showBackground: true,
                //         distanceDisplayCondition: new Cesium.DistanceDisplayCondition(
                //             0.0,
                //             100.0
                //         ),
                //         eyeOffset: new Cesium.Cartesian3(0, 3.5, 0),
                //     },
                // });
 
                // viewer.trackedEntity = vehicleEntity;
                // vehicleEntity.viewFrom = new Cesium.Cartesian3(-10.0, 7.0, 4.0);
 
                //静态
                // var position = Cesium.Cartesian3.fromDegrees(116.058987, 28.973468, 1000);
                var position = Cesium.Cartesian3.fromDegrees(a, b, g);
                viewer.trackedEntity = viewer.entities.add({//viewer.trackedEntity跟随
                    name: url,
                    position: position,
                    model: {
                        uri: url,
                    },
                });
                that.entityPeople = viewer.trackedEntity;
 
                // var viewModel = {// 以下是工具栏
                //     blackAndWhiteShow: false,
                //     blackAndWhiteGradations: 5.0,
                //     brightnessShow: false,
                //     brightnessValue: 0.5,
                //     nightVisionShow: false,
                //     silhouette: false,
                // };
 
                // Cesium.knockout.track(viewModel);
                // var toolbar = document.getElementById("toolbarcesium");
                // Cesium.knockout.applyBindings(viewModel, toolbar);
                // for (var name in viewModel) {
                //     if (viewModel.hasOwnProperty(name)) {
                //         Cesium.knockout
                //             .getObservable(viewModel, name)
                //             .subscribe(updatePostProcess);
                //     }
                // }
 
                // if (
                //     !Cesium.PostProcessStageLibrary.isSilhouetteSupported(viewer.scene)
                // ) {
                //     window.alert(
                //         "This browser does not support the silhouette post process."
                //     );
                // }
 
                // var stages = viewer.scene.postProcessStages;
                // var silhouette = stages.add(
                //     Cesium.PostProcessStageLibrary.createSilhouetteStage()
                // );
                // var blackAndWhite = stages.add(
                //     Cesium.PostProcessStageLibrary.createBlackAndWhiteStage()
                // );
                // var brightness = stages.add(
                //     Cesium.PostProcessStageLibrary.createBrightnessStage()
                // );
                // var nightVision = stages.add(
                //     Cesium.PostProcessStageLibrary.createNightVisionStage()
                // );
 
                // function updatePostProcess() {
                //     silhouette.enabled = Boolean(viewModel.silhouette);
                //     silhouette.uniforms.color = Cesium.Color.YELLOW;
                //     blackAndWhite.enabled = Boolean(viewModel.blackAndWhiteShow);
                //     blackAndWhite.uniforms.gradations = Number(
                //         viewModel.blackAndWhiteGradations
                //     );
                //     brightness.enabled = Boolean(viewModel.brightnessShow);
                //     brightness.uniforms.brightness = Number(viewModel.brightnessValue);
                //     nightVision.enabled = Boolean(viewModel.nightVisionShow);
                // }
                // updatePostProcess();
 
            },
            entityPeople: '',
            seeEntity: true,
            openEntity: false,
            time: '',
            beginPlay: function () {
                var postion = [116.058987, 28.973468, 1000]
                    , a = 116.058987
                    , b = 28.973468
                    , g = 1000;
                this.time = setInterval(() => {
 
                    if (this.openEntity) {
                        // this.map.entities.remove(this.entityPeople)//删除entity
                        // this.map.entities.remove(this.map.trackedEntity)//删除entity
                        this.map.entities.removeAll();
                    } else {
                        a += 0.01;
                        b += 0.01;
                        // g += 0.01;
                        this.beginCesium(a, b);
                    }
                    this.openEntity = !this.openEntity;
                    console.log(this.openEntity)
                }, 1000);
            },
            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
            },
            closeModo: function () {
                if (this.openEntity) {
                    // this.map.entities.remove(this.entityPeople)//删除entity
                    // this.map.entities.remove(this.map.trackedEntity)//删除entity
                    this.map.entities.removeAll();
                } else {
                    var a = $('#modelDiagramjdu').val() == '' ? 116.058987 : +$('#modelDiagramjdu').val();
                    var b = $('#modelDiagramwdu').val() == '' ? 28.973468 : +$('#modelDiagramwdu').val();
                    var g = $('#modelDiagramgdu').val() == '' ? 1000 : +$('#modelDiagramgdu').val();
                    // console.log([a, b, g])
                    this.beginCesium(a, b, g);
                }
                this.openEntity = !this.openEntity;
                console.log(this.openEntity)
                // var that = this;
                // if (that.seeEntity) {
                //     this.map.trackedEntity = that.entityPeople;//目标视野跟踪
                // } else {
                //     this.map.trackedEntity = '';
                // }
                // viewer.entities.remove(that.entityPeople)//删除entity
 
                // viewer.entities.removeById(id)//根据id删除entity
 
                // viewer.entities.removeAll()//清空所有entity
 
                // viewer.entities.getById(id)// 获取enetity
 
                // viewer.entities.contains(entity)// 是否包含
                // viewer.entities.removeById('')
            },
            beginModelDiagram: function () {
                var that = this
                    , viewer = that.map
                    , scene = viewer.scene;
                // scene.globe.show = false;
                viewer.shouldAnimate = true;
                var collect = new Cesium.InstanceLayer(scene._context)
                    , url = "./images/gltf/walk.gltf"
                    , gltf = viewer.entities.add({
                        name: "gltf",
                        position: new Cesium.Cartesian3.fromDegrees(115.783206 - 0.002034006, 28.810602 - 0.005072179, 800),
                        model: {
                            uri: url
                        }
                    });
                viewer.zoomTo(gltf);
                $("#modelDiagramSelOpt").change(function () {
                    var value = $(this).val();
                    if (value === "1") {
                        collect.removeInstance(url, [collect._instances._array[0]._array[0].id]);
                        viewer.entities._show = true;
                    } else {
                        viewer.entities._show = false;
                        collect.add(url,
                            {
                                position: new Cesium.Cartesian3.fromDegrees(115.783206 - 0.002034006, 28.810602 - 0.005072179, 1000)
                            });
 
                    }
                })
            },
            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);
            }
 
        });
    });