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
243
244
245
246
247
248
249
250
251
252
///////////////////////////////////////////////////////////////////////////
// Copyright © 2020 zhongsong. All Rights Reserved.
// 模块描述:飞行路线
///////////////////////////////////////////////////////////////////////////
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-FlyRoute',
        name: 'FlyRoute',
        flightTool: null,
        allRoutes: null,
        flag: false,
        startup: function startup() {
            topic.subscribe("openFlyRoute", lang.hitch(this, this.openFlyRoute));
            topic.subscribe("closeFlyRoute", lang.hitch(this, this.closeFlyRoute));
            var self = this;
            // this.inherited(arguments);
 
 
            $('.close-flyrouter').click(function () {
                self.closeFlyRoute('FlyRoute');
                $('.jimu-widget-visualAngle').find('.v-a-Two').removeClass('on');//清楚样式
                topic.publish('closeFly', 'closeFly');
            });
        },
 
        init: function init(evt) {
            var self = this;
            //实例化飞行工具
            self.flightTool = new Fly_NZC(self.map);
 
            //获取全部路线数据
            $.ajax({
                url: "./widgets/FlyRoute/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;
 
                    $("#flightRoute").empty();
                    $('#passPoint').empty();
 
                    // if (data.code == 200) {
                    for (var i = 0; i < data.length; i++) {
                        $("#flightRoute").append('<option value = ' + data[i].name + ' > ' + data[i].name + ' </option>');
                    }
                    // }
 
 
                    self._loadRoute(self.allRoutes[0].sites);
 
                    $("#flightRoute").on("change", function (e) {
                        var selectRoute = self.allRoutes.find(function (x) {
                            return x.name == $("#flightRoute").val();
                        });
                        self._loadRoute(selectRoute.sites);
                    });
 
                    //初始加载默认路线
                    //self._loadRoute(self.allRoutes[0].sites);
                }
            });
 
            //开始漫游
            $("#ks").click(function () {
                self.flightTool.flyManager.play();
            });
            //暂停漫游
            $("#zt").click(function () {
                self.flightTool.flyManager.pause();
            });
            //停止漫游
            $("#tz").click(function () {
                self.flightTool.flyManager.stop();
            });
            //删除路线
            $("#detele").click(function () {
                self.flightTool.RouteCollection.removeAllSites();
                $("#passPoint").empty();
            });
 
            //绘制路线
            var dataArr = [],
                id = 0;
            $("#add").click(function () {
                var liStr = "<li class='item'>途径点" + ($("#passPoint").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.time = null;
                dataArr.push(data);
 
                liDom.on('click', data, function (event) {
                });
 
                $('#passPoint').append(liDom);
 
                self.flightTool.RouteCollection.AddSiteByView(id);
                id++;
            });
 
            //导出路线
            $("#export").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: $('#routeName').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));
        },
 
        openFlyRoute: function (item) {
            if (item == this.name) {
                this.flag = true;
                this.init();
                $('.jimu-widget-FlyRoute').show();
            }
        },
 
        closeFlyRoute: function (item) {
            var self = this;
            if (item == this.name && this.flag == true) {
                this.flag = false;
                $('.jimu-widget-FlyRoute').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) {
            var self = this;
            $("#passPoint").empty();
            self.flightTool.RouteCollection.AddRoute(route);
            for (var j = 0; j < route.length; j++) {
                var liStr = "<li class='item'>途径点" + (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);
                });
                $('#passPoint').append(liDom);
            }
        },
 
        onOpen: function onOpen() {
            //面板打开的时候触发 (when open this panel trigger)
        },
 
        onClose: function onClose() {
            //面板关闭的时候触发 (when this panel is closed trigger)
        },
 
        onMinimize: function onMinimize() {
            this.resize();
        },
 
        onMaximize: function onMaximize() {
            this.resize();
        },
 
        resize: function resize() { },
 
        destroy: function destroy() {
            //销毁的时候触发
            //todo
            //do something before this func
            this.inherited(arguments);
        }
 
    });
});