liuyg
2021-07-02 6d4779a48a752c164e2fe7559dac6caed00f416f
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
define([
    'dojo/_base/declare',
    'dojo/_base/lang',
    'dojo/_base/array',
    'dojo/_base/html',
    'dojo/topic',
    'jimu/BaseWidget',
    './fly',
    './FileSaver'
],
    function (declare,
        lang,
        array,
        html,
        topic,
        BaseWidget
    ) {
        return declare([BaseWidget], {
            baseClass: 'jimu-widget-filyL',
            name: 'filyL',
            flightTool: null,
            allRoutes: null,
            flag: false,
            startup: function () {
                var that = this;
                topic.subscribe("beginfilyL", lang.hitch(this, this.beginfilyL));
                topic.subscribe("closesfilyL", lang.hitch(this, this.closesfilyL));
                // topic.publish('getbeginSlope', that.beginSlope);
                $(`.${that.baseClass}`).find('.closeOUR').click(() => {
                    $(`.${that.baseClass}`).hide();
                    that.closesfilyL();
                })
 
 
                // that.beginfilyL();
 
 
 
            },
            beginfilyL: function () {
                console.log(`${this.name}--kaishi`);
                var that = this;
                var viewer = that.map;
                //飞机飞行
                this.flag = true;
                this.init();
 
            },
            init: function init(evt) {
                var self = this;
                var that = this;
                var viewer = that.map
                    , scene = viewer.scene;
                //实例化飞行工具
                self.flightTool = new Fly_NZC(self.map);
 
                //获取全部路线数据
                $.ajax({
                    url: "./widgets/filyL/flyroute.json",
                    // http://sw797.com:82/blade-ycreal/flyroute/detail?id=1
                    // type: "POST",
                    dataType: "json",
                    success: function success(data) {
                        if (data.length == undefined) return;
                        // let datas = data.data;
                        self.allRoutes = data;
 
                        $("#flightRoutefilyL").empty();
                        $('#passPointfilyL').empty();
 
                        // if (data.code == 200) {
                        for (var i = 0; i < data.length; i++) {
                            $("#flightRoutefilyL").append('<option value = ' + data[i].name + ' > ' + data[i].name + ' </option>');
                        }
                        // }
 
 
                        self._loadRoute(self.allRoutes[0].sites);
 
                        $("#flightRoutefilyL").on("change", function (e) {
                            var selectRoute = self.allRoutes.find(function (x) {
                                return x.name == $("#flightRoutefilyL").val();
                            });
                            self._loadRoute(selectRoute.sites);
                        });
 
                        //初始加载默认路线
                        //self._loadRoute(self.allRoutes[0].sites);
                    }
                });
 
                //开始漫游
                $("#ksfilyL").click(function () {
                    self.flightTool.flyManager.play();
                });
                //暂停漫游
                $("#ztfilyL").click(function () {
                    self.flightTool.flyManager.pause();
                });
                //停止漫游
                $("#tzfilyL").click(function () {
                    self.flightTool.flyManager.stop();
                });
                //删除路线
                $("#detelefilyL").click(function () {
                    self.flightTool.RouteCollection.removeAllSites();
 
                    $("#passPointfilyL").empty();
                });
 
                //绘制路线
                // var pointHandler = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Point);//添加鼠标点事件
                var dataArr = [],
                    id = 3;
 
                // pointHandler.drawEvt.addEventListener(function (result) {
 
                // });
                var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
 
                $("#addfilyL").click(function () {
                    var liStr = "<li class='item'>途径点" + ($("#passPointfilyL").children().length + 1) + "</li>";
                    var liDom = $(liStr);
                    var lat = 0;
                    var lng = 0;
                    var height = 0;
                    // 鼠标移动时间回调
                    handler.setInputAction(function (e) {
                        // 若此标记为false,则激活对可视域分析对象的操作
                        // console.log(e,1213486)
                        //     //获取鼠标屏幕坐标,并将其转化成笛卡尔坐标
                        var position = e.endPosition;
                        var last = scene.pickPosition(position);
                        console.log(position, 'position')
                        // 将鼠标当前点坐标转化成经纬度
                        // var cartographic = Cesium.Cartographic.fromCartesian(last);
                        // lat = Cesium.Math.toDegrees(cartographic.longitude);
                        // lng = Cesium.Math.toDegrees(cartographic.latitude);
                        // height = cartographic.height;
                        var ray = viewer.camera.getPickRay(position);
                        var cartesian = viewer.scene.globe.pick(ray, viewer.scene);
                        // console.log(cartesian, 'cartesian')
 
                        lat = cartesian.y;
                        lng = cartesian.x;
                        height = cartesian.z;
 
                    }, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                    // 鼠标左键时间回调
                    handler.setInputAction(function (e) {
                        var data = {};
                        data.ids = id;
                        data.position_x = lng;
                        data.position_y = lat;
                        data.position_z = height + 10;
                        data.heading = 0;
                        data.pitch = -1;
                        data.roll = 0;
                        // data.heading = 6.108652381980;
                        // data.pitch = -0.653625804871;
                        // data.roll = 0;
                        data.time = 10;
                        dataArr.push(data);
                        // console.log(dataArr, 'dataArr');
                        // console.log(id, 'id')
 
                        self.flightTool.RouteCollection.AddSite(data);
                        // console.log(id, 'id2')
                        liDom.on('click', data, function (event) {
                            // console.log(event)
                            var site = self.flightTool.RouteCollection.getSiteByIndex(event.data.id);
                            self.flightTool.flyManager.viewToSite(data);
                        });
 
                        $('#passPointfilyL').append(liDom);
                        self.flightTool.RouteCollection.AddSiteByView(id);
                        id++;
                        handler.removeInputAction(Cesium.ScreenSpaceEventType.MOUSE_MOVE);
                        handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
                    }, Cesium.ScreenSpaceEventType.LEFT_CLICK);
 
 
                    // var liStr = "<li class='item'>途径点" + ($("#passPointfilyL").children().length + 1) + "</li>";
                    // var liDom = $(liStr);
 
                    // var camera = self.map.scene.camera;
 
                    // var cartographic = Cesium.Cartographic.fromCartesian(camera.position);
                    // var lat = Cesium.Math.toDegrees(cartographic.latitude);
                    // var lng = Cesium.Math.toDegrees(cartographic.longitude);
                    // var height = cartographic.height;
 
                    // var data = {};
                    // // data.id = id;
                    // // data.lgtd = lng;
                    // // data.lttd = lat;
                    // // data.height = height;
                    // // data.heading = Cesium.Math.toDegrees(camera.heading);
                    // // data.pitch = Cesium.Math.toDegrees(camera.pitch);
                    // // data.roll = Cesium.Math.toDegrees(camera.roll);
                    // data.id = id;
                    // data.lgtd = lng;
                    // data.lttd = lat;
                    // data.height = height;
                    // data.heading = Cesium.Math.toDegrees(camera.heading);
                    // data.pitch = Cesium.Math.toDegrees(camera.pitch);
                    // data.roll = Cesium.Math.toDegrees(camera.roll);
                    // data.time = null;
                    // dataArr.push(data);
 
                    // liDom.on('click', data, function (event) {
                    // });
 
                    // $('#passPointfilyL').append(liDom);
 
                    // self.flightTool.RouteCollection.AddSiteByView(id);
                    // id++;
                });
                //视角固定
                $("#openViewL").click(function () {
                    self.flightTool.flyManager.openView();
                })
                //导出路线
                $("#exportfilyL").click(function () {
                    for (var i = 0; i < dataArr.length - 1; i++) {
                        var a = Cesium.Cartesian3.fromDegrees(dataArr[i].lgtd, dataArr[i].lttd, dataArr[i].height);
                        var b = Cesium.Cartesian3.fromDegrees(dataArr[i + 1].lgtd, dataArr[i + 1].lttd, dataArr[i + 1].height);
                        var c = self.getSpaceDistance([a, b]);
                        dataArr[i].time = c;
                    }
 
                    var data = {
                        name: $('#routeNamefilyL').val(),
                        sites: dataArr
                    };
                    var content = JSON.stringify(data);
                    var blob = new Blob([content], {
                        type: "text/plain;charset=utf-8"
                    });
                    saveAs(blob, "save.json");
                    dataArr = [];
                });
 
                topic.subscribe("autoRoam", lang.hitch(this, this._executeRoam));
 
                topic.subscribe("stopflay", lang.hitch(this, this._stopFlay));
            },
 
            closesfilyL: function (froms) {
                console.log(`${this.name}--guanbi`);
                // var that = this;
 
                var self = this;
                if (item == this.name && this.flag == true) {
                    this.flag = false;
                    // $('.jimu-widget-filyL').hide();
                    // $('.jimu-widget-visualAngle .v-a-One').addClass('on').siblings().removeClass('on');
                    self.flightTool.flyManager.stop();
                    self.flightTool.RouteCollection.removeAllSites();
                }
            },
            //空间两点距离计算函数
            getSpaceDistance: function getSpaceDistance(positions) {
                var distance = 0;
                for (var i = 0; i < positions.length - 1; i++) {
 
                    var point1cartographic = Cesium.Cartographic.fromCartesian(positions[i]);
                    var point2cartographic = Cesium.Cartographic.fromCartesian(positions[i + 1]);
                    /**根据经纬度计算出距离**/
                    var geodesic = new Cesium.EllipsoidGeodesic();
                    geodesic.setEndPoints(point1cartographic, point2cartographic);
                    var s = geodesic.surfaceDistance;
                    //返回两点之间的距离
                    s = Math.sqrt(Math.pow(s, 2) + Math.pow(point2cartographic.height - point1cartographic.height, 2));
                    distance = distance + s;
                }
                return (distance / 70);
            },
 
            _executeRoam: function _executeRoam(data) {
                this.flightTool.flyManager.stop();
                this.flightTool.RouteCollection.removeAllSites();
                var selectRoute = this.allRoutes.find(function (x) {
                    return x.name == data;
                });
                for (var i = 0; i < selectRoute.sites.length; i++) {
                    var cartesian3 = Cesium.Cartesian3.fromDegrees(selectRoute.sites[i].lgtd, selectRoute.sites[i].lttd, selectRoute.sites[i].height);
                    var site = {
                        "ids": selectRoute.sites[i].id,
                        "position_x": cartesian3.x,
                        "position_y": cartesian3.y,
                        "position_z": cartesian3.z,
                        "pitch": Cesium.Math.toRadians(selectRoute.sites[i].pitch),
                        "heading": Cesium.Math.toRadians(selectRoute.sites[i].heading),
                        "roll": Cesium.Math.toRadians(selectRoute.sites[i].roll),
                        "time": selectRoute.sites[i].time
                    };
                    this.flightTool.allSites[i] = site;
                }
                this.flightTool.flyManager.play();
            },
 
            _stopFlay: function _stopFlay(data) {
                if (data) {
                    this.flightTool.flyManager.stop();
                    this.flightTool.RouteCollection.removeAllSites();
                }
            },
 
            _loadRoute: function _loadRoute(route) {
                console.log(route)
                var self = this;
                $("#passPointfilyL").empty();
                self.flightTool.RouteCollection.AddRoute(route);
                for (var j = 0; j < route.length; j++) {
                    var liStr = "<li class='item'>q途径点" + (j + 1) + "</li>";
                    var liDom = $(liStr);
                    liDom.on('click', route[j], function (event) {
                        var site = self.flightTool.RouteCollection.getSiteByIndex(event.data.id);
                        self.flightTool.flyManager.viewToSite(site);
                    });
                    $('#passPointfilyL').append(liDom);
                }
            },
            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);
            }
 
        });
    });