forked from iNavFlight/inav-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaypoint.js
168 lines (128 loc) · 3.63 KB
/
waypoint.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
'use strict';
let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endMission=0, isUsed=true, isAttached=false, attachedId="", multiMissionIdx = 0) {
var self = {};
let layerNumber = "undefined";
let attachedNumber = "undefined";
let poiNumber = "undefined";
self.getNumber = function () {
return number;
};
self.setNumber = function (data) {
number = data;
};
self.getLayerNumber = function () {
return layerNumber;
};
self.setLayerNumber = function (data) {
layerNumber = data;
};
self.getPoiNumber = function () {
return poiNumber;
};
self.setPoiNumber = function (data) {
poiNumber = data;
};
self.isUsed = function () {
return isUsed;
};
self.setUsed = function (data) {
isUsed = data;
};
self.isAttached = function () {
return isAttached;
};
self.setAttached = function (data) {
isAttached = data;
};
self.getLon = function () {
return lon;
};
self.getLonMap = function () {
return lon / 10000000;
};
self.setLon = function (data) {
lon = data;
};
self.getLat = function () {
return lat;
};
self.getLatMap = function () {
return lat / 10000000;
};
self.setLat = function (data) {
lat = data;
};
self.getAction = function () {
return action;
};
self.setAction = function (data) {
action = data;
};
self.getAlt = function () {
return alt;
};
self.setAlt = function (data) {
alt = data;
};
self.getP1 = function () {
return p1;
};
self.setP1 = function (data) {
p1 = data;
};
self.getP2 = function () {
return p2;
};
self.setP2 = function (data) {
p2 = data;
};
self.getP3 = function () {
return p3;
};
self.setP3 = function (data) {
p3 = data;
};
self.getEndMission = function () {
return endMission;
};
self.setEndMission = function (data) {
endMission = data;
};
self.getAttachedId = function () {
return attachedId;
};
self.setAttachedId = function (data) {
attachedId = data;
};
self.getAttachedNumber = function () {
return attachedNumber;
};
self.setAttachedNumber = function (data) {
attachedNumber = data;
};
self.setMultiMissionIdx = function(data) {
multiMissionIdx = data;
}
self.getMultiMissionIdx = function() {
return multiMissionIdx;
}
self.getElevation = async function (globalSettings) {
let elevation = "N/A";
if (globalSettings.mapProviderType == 'bing') {
let elevationEarthModel = $('#elevationEarthModel').prop("checked") ? "ellipsoid" : "sealevel";
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+self.getLatMap()+','+self.getLonMap()+'&heights='+elevationEarthModel+'&key='+globalSettings.mapApiKey);
const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations[0];
}
else {
const response = await fetch('https://api.opentopodata.org/v1/aster30m?locations='+self.getLatMap()+','+self.getLonMap());
const myJson = await response.json();
if (myJson.status == "OK" && myJson.results[0].elevation != null) {
elevation = myJson.results[0].elevation;
}
}
return elevation;
}
return self;
};
module.exports = Waypoint;