1
0
Fork 0
mirror of https://github.com/iNavFlight/inav-configurator.git synced 2025-07-26 01:35:23 +03:00

MP version 1.9

This commit is contained in:
ArnoTlse 2021-06-15 23:10:58 +02:00
parent 0087e53f57
commit 258b92cd54
4 changed files with 147 additions and 74 deletions

View file

@ -414,15 +414,33 @@ let WaypointCollection = function () {
const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure(true); const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure(true);
let lengthMission = self.getDistance(true); let lengthMission = self.getDistance(true);
let totalMissionDistance = lengthMission[lengthMission.length -1].toFixed(1); let totalMissionDistance = lengthMission[lengthMission.length -1].toFixed(1);
let samples = (Math.trunc(totalMissionDistance/30) <= 1024 ? Math.trunc(totalMissionDistance/30) : 1024); let samples;
if (point2measure.length <= 2){
samples = 1;
}
else if (Math.trunc(totalMissionDistance/30) <= 1024 && point2measure.length > 2){
samples = Math.trunc(totalMissionDistance/30);
}
else {
samples = 1024;
}
console.log(samples);
if (globalSettings.mapProviderType == 'bing') { 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); if (point2measure.length >1) {
const myJson = await response.json(); const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/Polyline?points='+point2measure+'&heights=ellipsoid&samples='+String(samples+1)+'&key='+globalSettings.mapApiKey);
elevation = myJson.resourceSets[0].resources[0].elevations; const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations;
}
else {
const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+point2measure+'&heights=ellipsoid&key='+globalSettings.mapApiKey);
const myJson = await response.json();
elevation = myJson.resourceSets[0].resources[0].elevations;
}
} }
else { else {
elevation = "NA"; elevation = "NA";
} }
//console.log("elevation ", elevation);
return [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure]; return [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure];
} }

View file

@ -191,11 +191,11 @@
height: 100%; height: 100%;
} }
/* #missionMap { #missionMap {
height: 60%; height: 100%;
} }
#missionPlanerElevation { /* #missionPlanerElevation {
height: 40%; height: 40%;
} */ } */

View file

@ -102,7 +102,7 @@
<table class="safehomesTable"> <table class="safehomesTable">
<thead> <thead>
<tr> <tr>
<th style="width: 80px" data-i18n="SafehomeSelected"></th> <th style="width: 50px" data-i18n="SafehomeSelected"></th>
<th style="width: 120px" data-i18n="SafehomeLon"></th> <th style="width: 120px" data-i18n="SafehomeLon"></th>
<th style="width: 120px" data-i18n="SafehomeLat"></th> <th style="width: 120px" data-i18n="SafehomeLat"></th>
<th style="width: 120px" data-i18n="SafehomeAlt"></th> <th style="width: 120px" data-i18n="SafehomeAlt"></th>
@ -276,13 +276,13 @@
</div> </div>
</div> </div>
</div> </div>
<div class="cf_column threefourth_left"> <div class="cf_column threefourth_left" style="height: 100%;">
<div id="missionMap"></div> <div id="missionMap"></div>
<div id="missionPlanerElevation" class="gui_box grey" style="display: none"> <div id="missionPlanerElevation" class="gui_box grey" style="display: none">
<div class="gui_box_titlebar"> <div class="gui_box_titlebar">
<div class="spacer_box_title i18n-replaced" data-i18n="missionDefaultElevationHead">Elevation Profile</div> <div class="spacer_box_title i18n-replaced" data-i18n="missionDefaultElevationHead">Elevation Profile</div>
<div class="btnMenu btnMenuIcon save_btn"> <div class="btnMenu btnMenuIcon save_btn">
<a id="cancelHome" class="ic_cancel" href="#" title="Cancel"></a> <a id="cancelPlot" class="ic_cancel" href="#" title="Cancel"></a>
</div> </div>
</div> </div>
<div class="spacer"> <div class="spacer">

View file

@ -717,7 +717,14 @@ TABS.mission_control.initialize = function (callback) {
})), })),
}); });
} }
function updateHome() {
renderHomeTable();
cleanHomeLayers();
renderHomeOnMap();
plotElevation();
}
///////////////////////////////////////////// /////////////////////////////////////////////
// //
// Manage Waypoint // Manage Waypoint
@ -1347,12 +1354,13 @@ TABS.mission_control.initialize = function (callback) {
*/ */
app.Drag.prototype.handleUpEvent = function (evt) { app.Drag.prototype.handleUpEvent = function (evt) {
if (tempMarker.kind == "waypoint" ){ if (tempMarker.kind == "waypoint" ){
if (mission.getWaypoint(tempMarker.number).getP3() == 1.0) {
(async () => { (async () => {
const elevationAtWP = await mission.getWaypoint(tempMarker.number).getElevation(globalSettings); if (mission.getWaypoint(tempMarker.number).getP3() == 1.0) {
$('#elevationValueAtWP').text(elevationAtWP); const elevationAtWP = await mission.getWaypoint(tempMarker.number).getElevation(globalSettings);
$('#elevationValueAtWP').text(elevationAtWP);
}
plotElevation();
})() })()
}
} }
else if (tempMarker.kind == "home" ) { else if (tempMarker.kind == "home" ) {
(async () => { (async () => {
@ -1536,6 +1544,7 @@ TABS.mission_control.initialize = function (callback) {
mission.update(); mission.update();
cleanLayers(); cleanLayers();
redrawLayers(); redrawLayers();
plotElevation();
} }
//mission.missionDisplayDebug(); //mission.missionDisplayDebug();
}); });
@ -1673,6 +1682,7 @@ TABS.mission_control.initialize = function (callback) {
redrawLayers(); redrawLayers();
selectedFeature = markers[selectedMarker.getLayerNumber()].getSource().getFeatures()[0]; selectedFeature = markers[selectedMarker.getLayerNumber()].getSource().getFeatures()[0];
selectedFeature.setStyle(getWaypointIcon(selectedMarker, true)); selectedFeature.setStyle(getWaypointIcon(selectedMarker, true));
plotElevation();
} }
}); });
@ -1685,6 +1695,7 @@ TABS.mission_control.initialize = function (callback) {
redrawLayers(); redrawLayers();
selectedFeature = markers[selectedMarker.getLayerNumber()].getSource().getFeatures()[0]; selectedFeature = markers[selectedMarker.getLayerNumber()].getSource().getFeatures()[0];
selectedFeature.setStyle(getWaypointIcon(selectedMarker, true)); selectedFeature.setStyle(getWaypointIcon(selectedMarker, true));
plotElevation();
} }
}); });
@ -1694,6 +1705,7 @@ TABS.mission_control.initialize = function (callback) {
mission.updateWaypoint(selectedMarker); mission.updateWaypoint(selectedMarker);
mission.update(); mission.update();
redrawLayer(); redrawLayer();
plotElevation();
} }
}); });
@ -1733,6 +1745,7 @@ TABS.mission_control.initialize = function (callback) {
mission.updateWaypoint(selectedMarker); mission.updateWaypoint(selectedMarker);
mission.update(); mission.update();
redrawLayer(); redrawLayer();
plotElevation();
} }
}); });
@ -1813,22 +1826,24 @@ TABS.mission_control.initialize = function (callback) {
let mapCenter = map.getView().getCenter(); let mapCenter = map.getView().getCenter();
HOME.setLon(Math.round(ol.proj.toLonLat(mapCenter)[0] * 1e7)); HOME.setLon(Math.round(ol.proj.toLonLat(mapCenter)[0] * 1e7));
HOME.setLat(Math.round(ol.proj.toLonLat(mapCenter)[1] * 1e7)); HOME.setLat(Math.round(ol.proj.toLonLat(mapCenter)[1] * 1e7));
renderHomeTable(); updateHome();
cleanHomeLayers();
renderHomeOnMap();
plotElevation();
}); });
$('#cancelHome').on('click', function () { $('#cancelHome').on('click', function () {
closeHomePanel(); closeHomePanel();
}); });
$('#cancelPlot').on('click', function () {
closeHomePanel();
});
///////////////////////////////////////////// /////////////////////////////////////////////
// Callback for Remove buttons // Callback for Remove buttons
///////////////////////////////////////////// /////////////////////////////////////////////
$('#removeAllPoints').on('click', function () { $('#removeAllPoints').on('click', function () {
if (markers.length && confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) { if (markers.length && confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) {
removeAllWaypoints(); removeAllWaypoints();
plotElevation();
} }
}); });
@ -1849,6 +1864,7 @@ TABS.mission_control.initialize = function (callback) {
clearEditForm(); clearEditForm();
cleanLayers(); cleanLayers();
redrawLayers(); redrawLayers();
plotElevation();
} }
} }
else { else {
@ -1858,6 +1874,7 @@ TABS.mission_control.initialize = function (callback) {
clearEditForm(); clearEditForm();
cleanLayers(); cleanLayers();
redrawLayers(); redrawLayers();
plotElevation();
} }
} }
}); });
@ -1992,6 +2009,10 @@ TABS.mission_control.initialize = function (callback) {
mission.setCenterLon(parseFloat(node.$[attr]) * 10000000); mission.setCenterLon(parseFloat(node.$[attr]) * 10000000);
} else if (attr.match(/cy/i)) { } else if (attr.match(/cy/i)) {
mission.setCenterLat(parseFloat(node.$[attr]) * 10000000); mission.setCenterLat(parseFloat(node.$[attr]) * 10000000);
} else if (attr.match(/home\-x/i)) {
HOME.setLon(Math.round(parseFloat(node.$[attr]) * 10000000));
} else if (attr.match(/home\-y/i)) {
HOME.setLat(Math.round(parseFloat(node.$[attr]) * 10000000));
} }
} }
} else if (node['#name'].match(/missionitem/i) && node.$) { } else if (node['#name'].match(/missionitem/i) && node.$) {
@ -2059,6 +2080,7 @@ TABS.mission_control.initialize = function (callback) {
} }
redrawLayers(); redrawLayers();
updateHome();
updateTotalInfo(); updateTotalInfo();
let sFilename = String(filename.split('\\').pop().split('/').pop()); let sFilename = String(filename.split('\\').pop().split('/').pop());
GUI.log(sFilename+' has been loaded successfully !'); GUI.log(sFilename+' has been loaded successfully !');
@ -2076,7 +2098,11 @@ TABS.mission_control.initialize = function (callback) {
var data = { var data = {
'version': { $: { 'value': '2.3-pre8' } }, 'version': { $: { 'value': '2.3-pre8' } },
'mwp': { $: { 'cx': (Math.round(center[0] * 10000000) / 10000000), 'cy': (Math.round(center[1] * 10000000) / 10000000), 'zoom': zoom } }, 'mwp': { $: { 'cx': (Math.round(center[0] * 10000000) / 10000000),
'cy': (Math.round(center[1] * 10000000) / 10000000),
'home-x' : HOME.getLonMap(),
'home-y' : HOME.getLatMap(),
'zoom': zoom } },
'missionitem': [] 'missionitem': []
}; };
@ -2167,62 +2193,91 @@ TABS.mission_control.initialize = function (callback) {
} }
function plotElevation() { function plotElevation() {
(async () => { if ($('#missionPlanerElevation').is(":visible")) {
const [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure] = await mission.getElevation(globalSettings); if (mission.get().length == 0) {
console.log(elevation); var data = [[0], [0]];
console.log(totalMissionDistance); var layout = {showlegend: true,
console.log(Array.from(Array(samples), (_,i)=> i*totalMissionDistance/samples)); legend: {
var trace_WGS84 = { "orientation": "h",
x: Array.from(Array(samples), (_,i)=> i*totalMissionDistance/samples), xanchor: "center",
y: elevation, y: 1.3,
type: 'scatter', x: 0.5
name: 'WGS84 elevation', },
fill: 'tozeroy', title: 'Mission Elevation Profile',
line: { xaxis: {
color: '#ff7f0e', title: 'Distance (m)'
}, },
}; yaxis: {
console.log(altPoint2measure.map((x,i) => x / 100 + HOME.getAlt()*refPoint2measure[i])); title: 'Elevation (m)',
var trace_missionHeight = { },
x: lengthMission, height: 300,
y: altPoint2measure.map((x,i) => x / 100 + HOME.getAlt()*(1-refPoint2measure[i])) , }
type: 'scatter', Plotly.newPlot('elevationDiv', data, layout);
mode: 'lines+markers+text', }
name: 'Mission altitude', else {
text: namePoint2measure, (async () => {
textposition: 'top center', const [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure] = await mission.getElevation(globalSettings);
textfont: { let x_elevation = Array.from(Array(samples+1), (_,i)=> i*totalMissionDistance/samples);
family: 'Raleway, sans-serif' var trace_WGS84 = {
}, x: x_elevation,
line: { y: elevation,
color: '#1497f1', type: 'scatter',
}, name: 'WGS84 elevation',
marker: { hovertemplate: '<b>Elevation</b>: %{y} m',
color: '#1f77b4', fill: 'tozeroy',
}, line: {
}; color: '#ff7f0e',
},
var layout = {showlegend: true, };
legend: { let y_missionElevation = altPoint2measure.map((x,i) => x / 100 + HOME.getAlt()*(1-refPoint2measure[i]));
"orientation": "h", let y_elevationReference = refPoint2measure.map((x,i) => (x == 1 ? "WGS84" : "Take-off Home"));
xanchor: "center", console.log(y_elevationReference);
y: 1.2, var trace_missionHeight = {
x: 0.5 x: lengthMission,
}, y: y_missionElevation ,
title: 'Mission Elevation Profile', type: 'scatter',
xaxis: { mode: 'lines+markers+text',
title: 'Distance (m)' name: 'Mission altitude',
}, text: namePoint2measure,
yaxis: { textposition: 'top center',
title: 'Elevation (m)' textfont: {
}, family: 'Raleway, sans-serif'
height: 300, },
} customdata: y_elevationReference,
hovertemplate: '<b>WP</b>: %{text}' +
'<br><b>Elevation</b>: %{y} m<br>' +
'<b>Reference</b>: %{customdata}',
line: {
color: '#1497f1',
},
marker: {
color: '#1f77b4',
},
};
var layout = {showlegend: true,
legend: {
"orientation": "h",
xanchor: "center",
y: 1.3,
x: 0.5
},
title: 'Mission Elevation Profile',
xaxis: {
title: 'Distance (m)'
},
yaxis: {
title: 'Elevation (m)',
range: [-10 + Math.min(Math.min(...y_missionElevation), Math.min(...elevation)), 10 + Math.max(Math.max(...y_missionElevation), Math.max(...elevation))],
},
height: 300,
}
var data = [trace_WGS84, trace_missionHeight]; var data = [trace_WGS84, trace_missionHeight];
Plotly.newPlot('elevationDiv', data, layout); Plotly.newPlot('elevationDiv', data, layout);
})() })()
}
}
} }
}; };