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
///////////////////////////////////////////////////////////////////////////
// Copyright © 2020 zhongsong. All Rights Reserved.
// 模块描述:飞行路线
///////////////////////////////////////////////////////////////////////////
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-SuperMapFlyRoute',
        name: 'SuperMapFlyRoute',
        flightTool: null,
        allRoutes: null,
        scene:null,
        startup: function startup() {
            var self = this;
 
            var viewer = self.map;
            self.scene = viewer.scene;
 
            self.scene.shadowMap.darkness = 1.275; //设置第二重烘焙纹理的效果(明暗程度)
            self.scene.skyAtmosphere.brightnessShift = 0.4;  //修改大气的亮度
            self.scene.debugShowFramesPerSecond = true;
            self.scene.hdrEnabled = false;
            self.scene.sun.show = false;
            // 01设置环境光的强度-新处理CBD场景
            self.scene.lightSource.ambientLightColor = new Cesium.Color(0.65, 0.65, 0.65, 1);
            // 添加光源
            var position1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 480);
            //光源方向点
 
            var targetPosition1 = new Cesium.Cartesian3.fromDegrees(116.261209157595, 39.3042238956531, 430);
            var dirLightOptions = {
                targetPosition: targetPosition1,
                color: new Cesium.Color(1.0, 1.0, 1.0, 1),
                intensity: 0.55
            };
 
            directionalLight_1 = new Cesium.DirectionalLight(position1, dirLightOptions);
            self.scene.addLightSource(directionalLight_1);
 
            self.scene.globe.depthTestAgainstTerrain = false;
 
            $('#stopListLX').change(function () { //注册路线切换事件
                self.map.entities.removeAll();
                self.flyStart($(this).val());
            });
 
            $(".super-head-th-xx").click(function () {
                self.onClose();
                $(".jimu-widget-SuperMapFlyRoute").hide();
            });
 
        },
 
        getData: function (){
            var self = this;
            //添加fpf飞行文件,fpf由SuperMap iDesktop生成
            $.ajax({
                url: './widgets/SuperMapFlyRoute/datas.json',
                type: "POST",
                dataType: "json",
                success: function success(data) {
                    var menuLX = document.getElementById('stopListLX');
                    menuLX.innerHTML = "";
                    for (var i = 0; i < data.length; i++) {
                        var option = document.createElement('option');
                        option.innerHTML = data[i].name;
                        option.value = data[i].url;
                        menuLX.appendChild(option);
                    }
 
                    self.flyStart(data[0].url);
                }
            });
        },
        flyStart: function (url) {
            var self = this;
            var routes = new Cesium.RouteCollection(viewer.entities);
            routes.fromFile(url);
            //初始化飞行管理
            var flyManager = new Cesium.FlyManager({
                scene: self.scene,
                routes: routes
            });
            //注册站点到达事件
            flyManager.stopArrived.addEventListener(function (routeStop) {
                routeStop.waitTime = 1; // 在每个站点处停留1s
            });
 
            flyManager.readyPromise.then(function () { // 飞行路线就绪
                var currentRoute = flyManager.currentRoute;
                currentRoute.isLineVisible = false;
                currentRoute.isStopVisible = false;
                //生成飞行文件中的所有站点列表
                var allStops = flyManager.getAllRouteStops();
                var menu = document.getElementById('stopList');
                menu.innerHTML = "";
                for (var i = 0, j = allStops.length; i < j; i++) {
                    var option = document.createElement('option');
                    option.innerHTML = "站点 " + (i + 1);
                    option.value = allStops[i].index;
                    menu.appendChild(option);
                }
 
                $('#stopList').change(function () { //注册站点切换事件
                    flyManager && flyManager.stop();
                    var index = parseInt($(this).val()); // 站点的索引
                    var route = flyManager.currentRoute;
                    var stop = route.get(index);
                    flyManager.currentStopIndex = index;
                    flyManager.viewToStop(stop);
                });
 
                $('#play').click(function () {
                    flyManager && flyManager.play();
                });
                $('#pause').click(function () {
                    flyManager && flyManager.pause();
                });
                $('#stop').click(function () {
                    flyManager && flyManager.stop();
                });
 
                $('#show-line').change(function () {
                    currentRoute.isLineVisible = $(this).prop('checked');
                });
 
                $('#show-stop').change(function () {
                    currentRoute.isStopVisible = $(this).prop('checked');
                });
 
                $('#toolbar').show();
                $('#loadingbar').remove();
 
                $(".cesium-performanceDisplay").hide();
            });
        },
 
        onMinimize: function () {
            this.resize();
        },
 
        onMaximize: function () {
            this.resize();
        },
 
        resize: function () {
 
        },
 
        onOpen: function onOpen() {
            //面板打开的时候触发 (when open this panel trigger)
            var self = this;
            self.getData();
        },
 
        onClose: function onClose() {
            //面板关闭的时候触发 (when this panel is closed trigger)
            this.map.entities.removeAll();
        },
 
        destroy: function destroy() {
            //销毁的时候触发
            //todo
            //do something before this func
            this.inherited(arguments);
        }
 
    });
});