1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-25 17:25:14 +03:00

MP version 1.6

This commit is contained in:
ArnoTlse 2021-05-28 23:02:58 +02:00
parent 59b5cbe5b2
commit 63b548e3e0
3 changed files with 45 additions and 8 deletions

View file

@ -138,6 +138,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM
self.getElevation = async function (globalSettings) { self.getElevation = async function (globalSettings) {
let elevation; let elevation;
console.log('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+self.getLatMap()+','+self.getLonMap()+'&heights=ellipsoid&key='+globalSettings.mapApiKey);
if (globalSettings.mapProviderType == 'bing') { if (globalSettings.mapProviderType == 'bing') {
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+self.getLatMap()+','+self.getLonMap()+'&heights=ellipsoid&key='+globalSettings.mapApiKey); const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+self.getLatMap()+','+self.getLonMap()+'&heights=ellipsoid&key='+globalSettings.mapApiKey);
const myJson = await response.json(); const myJson = await response.json();

View file

@ -332,22 +332,26 @@ let WaypointCollection = function () {
return poiList; return poiList;
} }
self.getDistance = function() { self.getPoint2Measure = function(reverse=false) {
let point2measure = [] let point2measure = [];
let lengthLine = []
let jumpDict = {}; let jumpDict = {};
let nStart = 0; let nStart = 0;
let nLoop = 0; let nLoop = 0;
let n = 0 ; let n = 0 ;
let startCount = true; let startCount = true;
while (startCount && (nLoop!=-1)) { while (startCount) {
if (nStart > data[data.length -1].getNumber() ) { if (nStart > data[data.length -1].getNumber() ) {
startCount = false; startCount = false;
break; break;
} }
if ([MWNP.WPTYPE.WAYPOINT,MWNP.WPTYPE.POSHOLD_TIME,MWNP.WPTYPE.LAND].includes(self.getWaypoint(nStart).getAction())) { if ([MWNP.WPTYPE.WAYPOINT,MWNP.WPTYPE.POSHOLD_TIME,MWNP.WPTYPE.LAND].includes(self.getWaypoint(nStart).getAction())) {
point2measure.push(ol.proj.fromLonLat([self.getWaypoint(nStart).getLonMap(), self.getWaypoint(nStart).getLatMap()])); if (reverse) {
point2measure.push([self.getWaypoint(nStart).getLatMap(), self.getWaypoint(nStart).getLonMap()]);
}
else {
point2measure.push(ol.proj.fromLonLat([self.getWaypoint(nStart).getLonMap(), self.getWaypoint(nStart).getLatMap()]));
}
nStart++; nStart++;
} }
else if (self.getWaypoint(nStart).getAction() == MWNP.WPTYPE.JUMP) { else if (self.getWaypoint(nStart).getAction() == MWNP.WPTYPE.JUMP) {
@ -356,6 +360,7 @@ let WaypointCollection = function () {
} }
if (Object.keys(jumpDict).includes(String(self.getWaypoint(nStart).getNumber())) ) { if (Object.keys(jumpDict).includes(String(self.getWaypoint(nStart).getNumber())) ) {
if (jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] == -1) { if (jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] == -1) {
jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] = 1;
nLoop = -1; nLoop = -1;
} }
if ( (jumpDict[self.getWaypoint(nStart).getNumber()]["n"]>=jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] || jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] ==0) ) { if ( (jumpDict[self.getWaypoint(nStart).getNumber()]["n"]>=jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] || jumpDict[self.getWaypoint(nStart).getNumber()]["nLoop"] ==0) ) {
@ -368,13 +373,19 @@ let WaypointCollection = function () {
nStart = nStartTemp; nStart = nStartTemp;
} }
} }
} }
else { else {
nStart++; nStart++;
} }
} }
if (nLoop == -1) {
return [nLoop, point2measure];
}
self.getDistance = function(display) {
let lengthLine = [];
const [nLoop, point2measure] = self.getPoint2Measure();
if (nLoop == -1 && display) {
return [-1]; return [-1];
} }
else { else {
@ -392,6 +403,30 @@ let WaypointCollection = function () {
return lengthLine.map(cumulativeSum); return lengthLine.map(cumulativeSum);
} }
} }
self.getElevation = async function(globalSettings) {
const [nLoop, point2measure] = self.getPoint2Measure(true);
let lengthMission = self.getDistance(true);
let totalMissionDistance = lengthMission[lengthMission.length -1].toFixed(1);
//let point2measureMap = point2measure.map(function(x) { return x.map(function(y) {return y / 10000000})});
console.log(totalMissionDistance/30);
let samples = (Math.trunc(totalMissionDistance/30) <= 1024 ? Math.trunc(totalMissionDistance/30) : 1024);
console.log(samples);
console.log(point2measure.toString());
console.log('http://dev.virtualearth.net/REST/v1/Elevation/Polyline?points='+point2measure+'&heights=ellipsoid&samples='+String(samples)+'&key='+globalSettings.mapApiKey);
if (globalSettings.mapProviderType == 'bing') {
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/Polyline?points='+point2measure+'&heights=ellipsoid&samples='+String(samples)+'&key='+globalSettings.mapApiKey);
const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations;
}
else {
elevation = "NA";
}
console.log("getElevation");
console.log(elevation);
return elevation;
}
return self; return self;
}; };

View file

@ -751,7 +751,7 @@ TABS.mission_control.initialize = function (callback) {
if (textGeom) { if (textGeom) {
textGeom.setCoordinates(map.getCoordinateFromPixel([0,0])); textGeom.setCoordinates(map.getCoordinateFromPixel([0,0]));
} }
let lengthMission = mission.getDistance(); let lengthMission = mission.getDistance(true);
$('#missionDistance').text(lengthMission[lengthMission.length -1] != -1 ? lengthMission[lengthMission.length -1].toFixed(1) : 'infinite'); $('#missionDistance').text(lengthMission[lengthMission.length -1] != -1 ? lengthMission[lengthMission.length -1].toFixed(1) : 'infinite');
} }
@ -2002,6 +2002,7 @@ TABS.mission_control.initialize = function (callback) {
} }
function plotElevation() { function plotElevation() {
mission.getElevation(globalSettings);
var trace1 = { var trace1 = {
x: [1, 2, 3, 4], x: [1, 2, 3, 4],
y: [10, 15, 13, 17], y: [10, 15, 13, 17],