forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgroundstation.js
204 lines (155 loc) · 6.51 KB
/
groundstation.js
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
'use strict';
const path = require('path');
const ol = require('openlayers');
const { GUI } = require('./gui');
const ltmDecoder = require('./ltmDecoder');
const interval = require('./intervals');
const { globalSettings } = require('./globalSettings');
const i18n = require('./localization');
const groundstation = (function () {
let publicScope = {},
privateScope = {};
privateScope.activated = false;
privateScope.$viewport = null;
privateScope.$gsViewport = null;
privateScope.mapHandler = null;
privateScope.mapLayer = null;
privateScope.mapView = null;
privateScope.cursorStyle = null;
privateScope.cursorPosition = null;
privateScope.cursorFeature = null;
privateScope.cursorVector = null;
privateScope.cursorLayer = null;
privateScope.textGeometry = null;
privateScope.textFeature = null;
privateScope.textVector = null;
privateScope.textSource = null;
privateScope.mapInitiated = false;
publicScope.isActivated = function () {
return privateScope.activated;
};
publicScope.activate = function ($viewport) {
if (privateScope.activated) {
return;
}
interval.add('gsUpdateGui', privateScope.updateGui, 200);
privateScope.$viewport = $viewport;
privateScope.$viewport.find(".tab_container").hide();
privateScope.$viewport.find('#content').hide();
privateScope.$viewport.find('#status-bar').hide();
privateScope.$viewport.find('#connectbutton a.connect_state').text(i18n.getMessage('disconnect'));
privateScope.$viewport.find('#connectbutton a.connect').addClass('active');
privateScope.$gsViewport = $viewport.find('#view-groundstation');
privateScope.$gsViewport.show();
privateScope.mapInitiated = false;
setTimeout(privateScope.initMap, 100);
privateScope.activated = true;
GUI.log(i18n.getMessage('gsActivated'));
}
privateScope.initMap = function () {
//initialte layers
if (globalSettings.mapProviderType == 'bing') {
privateScope.mapLayer = new ol.source.BingMaps({
key: globalSettings.mapApiKey,
imagerySet: 'AerialWithLabels',
maxZoom: 19
});
} else if (globalSettings.mapProviderType == 'mapproxy') {
privateScope.mapLayer = new ol.source.TileWMS({
url: globalSettings.proxyURL,
params: { 'LAYERS': globalSettings.proxyLayer }
})
} else {
privateScope.mapLayer = new ol.source.OSM();
}
//initiate view
privateScope.mapView = new ol.View({
center: ol.proj.fromLonLat([0, 0]),
zoom: 3
});
//initiate map handler
privateScope.mapHandler = new ol.Map({
target: document.getElementById('groundstation-map'),
layers: [
new ol.layer.Tile({
source: privateScope.mapLayer
})
],
view: privateScope.mapView
});
};
publicScope.deactivate = function () {
if (!privateScope.activated) {
return;
}
interval.remove('gsUpdateGui');
if (privateScope.$viewport !== null) {
privateScope.$viewport.find(".tab_container").show();
privateScope.$viewport.find('#content').show();
privateScope.$viewport.find('#status-bar').show();
}
if (privateScope.$gsViewport !== null) {
privateScope.$gsViewport.hide();
}
privateScope.activated = false;
GUI.log(i18n.getMessage('gsDeactivated'));
}
privateScope.updateGui = function () {
let telemetry = ltmDecoder.get();
if (telemetry.gpsFix && telemetry.gpsFix > 1) {
let lat = telemetry.latitude / 10000000;
let lon = telemetry.longitude / 10000000;
//On first initiation, set zoom to 15
if (!privateScope.mapInitiated) {
//Place UAV on the map
privateScope.cursorStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 0.5],
opacity: 1,
scale: 0.6,
src: path.join(__dirname, './../images/icons/icon_mission_airplane.png')
}))
});
privateScope.cursorPosition = new ol.geom.Point(ol.proj.fromLonLat([lon, lat]));
privateScope.cursorFeature = new ol.Feature({
geometry: privateScope.cursorPosition
});
privateScope.cursorFeature.setStyle(privateScope.cursorStyle);
privateScope.cursorVector = new ol.source.Vector({
features: [privateScope.cursorFeature]
});
privateScope.cursorLayer = new ol.layer.Vector({
source: privateScope.cursorVector
});
privateScope.mapHandler.addLayer(privateScope.cursorLayer);
privateScope.mapView.setZoom(17);
privateScope.mapInitiated = true;
}
//Update map center
let position = ol.proj.fromLonLat([lon, lat]);
privateScope.mapView.setCenter(position);
//Update position of cursor
privateScope.cursorPosition.setCoordinates(position);
//Update orientation of cursor
privateScope.cursorStyle.getImage().setRotation((telemetry.heading / 360.0) * 6.28318);
//Update text
privateScope.$viewport.find("#gs-telemetry-latitude").html(lat);
privateScope.$viewport.find("#gs-telemetry-longitude").html(lon);
}
privateScope.$viewport.find("#gs-telemetry-altitude").html((telemetry.altitude / 100.0).toFixed(2) + 'm');
privateScope.$viewport.find("#gs-telemetry-voltage").html((telemetry.voltage / 1000.0).toFixed(2) + 'V');
privateScope.$viewport.find("#gs-telemetry-sats").html(telemetry.gpsSats);
privateScope.$viewport.find("#gs-telemetry-speed").html(telemetry.groundSpeed.toFixed(0) + 'm/s');
let fixText = '';
if (telemetry.gpsFix == 3) {
fixText = '3D';
} else if (telemetry.gpsFix == 2) {
fixText = '2D';
} else {
fixText = 'No fix';
}
privateScope.$viewport.find("#gs-telemetry-fix").html(fixText);
};
return publicScope;
})();
module.exports = groundstation;