mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-25 17:25:14 +03:00
MP version 1.7
This commit is contained in:
parent
63b548e3e0
commit
2fb3cacf9a
6 changed files with 270 additions and 31 deletions
|
@ -3232,6 +3232,9 @@
|
|||
"missionDefaultElevationHead": {
|
||||
"message": "Elevation Profile"
|
||||
},
|
||||
"missionHomeHead": {
|
||||
"message": "Take Off Home"
|
||||
},
|
||||
"missionSafehomeHead": {
|
||||
"message": "Safe Home manager"
|
||||
},
|
||||
|
@ -3757,6 +3760,9 @@
|
|||
"SafehomeLat": {
|
||||
"message": "Lat"
|
||||
},
|
||||
"SafehomeAlt": {
|
||||
"message": "Elev"
|
||||
},
|
||||
"WaypointOptionSelected": {
|
||||
"message": "+"
|
||||
},
|
||||
|
|
BIN
images/icons/cf_icon_home.png
Normal file
BIN
images/icons/cf_icon_home.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.5 KiB |
|
@ -147,7 +147,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM
|
|||
else {
|
||||
elevation = "NA";
|
||||
}
|
||||
$('#elevationValueAtWP').text(elevation);
|
||||
//$('#elevationValueAtWP').text(elevation);
|
||||
console.log("getElevation");
|
||||
return elevation;
|
||||
}
|
||||
|
|
|
@ -334,6 +334,9 @@ let WaypointCollection = function () {
|
|||
|
||||
self.getPoint2Measure = function(reverse=false) {
|
||||
let point2measure = [];
|
||||
let altPoint2measure = [];
|
||||
let namePoint2measure = [];
|
||||
let refPoint2measure = [];
|
||||
let jumpDict = {};
|
||||
let nStart = 0;
|
||||
let nLoop = 0;
|
||||
|
@ -352,6 +355,9 @@ let WaypointCollection = function () {
|
|||
else {
|
||||
point2measure.push(ol.proj.fromLonLat([self.getWaypoint(nStart).getLonMap(), self.getWaypoint(nStart).getLatMap()]));
|
||||
}
|
||||
altPoint2measure.push(self.getWaypoint(nStart).getAlt());
|
||||
namePoint2measure.push(self.getWaypoint(nStart).getLayerNumber()+1);
|
||||
refPoint2measure.push(self.getWaypoint(nStart).getP3());
|
||||
nStart++;
|
||||
}
|
||||
else if (self.getWaypoint(nStart).getAction() == MWNP.WPTYPE.JUMP) {
|
||||
|
@ -379,12 +385,12 @@ let WaypointCollection = function () {
|
|||
}
|
||||
}
|
||||
|
||||
return [nLoop, point2measure];
|
||||
return [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure];
|
||||
}
|
||||
|
||||
self.getDistance = function(display) {
|
||||
let lengthLine = [];
|
||||
const [nLoop, point2measure] = self.getPoint2Measure();
|
||||
const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure();
|
||||
if (nLoop == -1 && display) {
|
||||
return [-1];
|
||||
}
|
||||
|
@ -405,16 +411,10 @@ let WaypointCollection = function () {
|
|||
}
|
||||
|
||||
self.getElevation = async function(globalSettings) {
|
||||
const [nLoop, point2measure] = self.getPoint2Measure(true);
|
||||
const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = 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();
|
||||
|
@ -423,9 +423,7 @@ let WaypointCollection = function () {
|
|||
else {
|
||||
elevation = "NA";
|
||||
}
|
||||
console.log("getElevation");
|
||||
console.log(elevation);
|
||||
return elevation;
|
||||
return [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure];
|
||||
}
|
||||
|
||||
return self;
|
||||
|
|
|
@ -87,6 +87,43 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div id="missionPlanerHome" class="gui_box grey" style="display: none">
|
||||
<div class="gui_box_titlebar">
|
||||
<div class="spacer_box_title i18n-replaced" data-i18n="missionHomeHead">Take Off home</div>
|
||||
<div class="btnMenu btnMenuIcon save_btn">
|
||||
<div id="showHideHomeButton">
|
||||
<a class="ic_hide" href="#" title="Hide"></a>
|
||||
</div>
|
||||
<a id="cancelHome" class="ic_cancel" href="#" title="Cancel"></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="spacer" id="HomeContent">
|
||||
<div>
|
||||
<table class="safehomesTable">
|
||||
<thead>
|
||||
<tr>
|
||||
<th style="width: 80px" data-i18n="SafehomeSelected"></th>
|
||||
<th style="width: 120px" data-i18n="SafehomeLon"></th>
|
||||
<th style="width: 120px" data-i18n="SafehomeLat"></th>
|
||||
<th style="width: 120px" data-i18n="SafehomeAlt"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="homeTableBody">
|
||||
<tr>
|
||||
<td><div id="viewHomePoint" class="btnTable btnTableIcon">
|
||||
<a class="ic_center" data-role="home-center" href="#" title="move to center view"></a>
|
||||
</div>
|
||||
</td>
|
||||
<td><input type="number" class="home-lon" /></td>
|
||||
<td><input type="number" class="home-lat" /></td>
|
||||
<td><span id="elevationValueAtHome">NA</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="missionPlanerSafehome" class="gui_box grey" style="display: none">
|
||||
<div class="gui_box_titlebar">
|
||||
<div class="spacer_box_title i18n-replaced" data-i18n="missionSafehomeHead">Safe Home manager</div>
|
||||
|
@ -245,8 +282,7 @@
|
|||
<div class="gui_box_titlebar">
|
||||
<div class="spacer_box_title i18n-replaced" data-i18n="missionDefaultElevationHead">Elevation Profile</div>
|
||||
<div class="btnMenu btnMenuIcon save_btn">
|
||||
<a id="cancelSettings" class="ic_cancel" href="#" title="Cancel"></a>
|
||||
<a id="saveSettings" class="ic_save" href="#" title="Save"></a>
|
||||
<a id="cancelHome" class="ic_cancel" href="#" title="Cancel"></a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="spacer">
|
||||
|
|
|
@ -384,6 +384,12 @@ TABS.mission_control.initialize = function (callback) {
|
|||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var mission = new WaypointCollection();
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// define & init home parameters
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
var HOME = new Waypoint(0,0,0,0);
|
||||
var homeMarkers =[]; // layer for home point
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// define & init Safehome parameters
|
||||
//////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -615,6 +621,103 @@ TABS.mission_control.initialize = function (callback) {
|
|||
let radiusProjected = (radius / ol.proj.METERS_PER_UNIT.m) * resolutionRate;
|
||||
return radiusProjected;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
// Manage Take Off Home
|
||||
//
|
||||
/////////////////////////////////////////////
|
||||
function closeHomePanel() {
|
||||
$('#missionPlanerHome').hide();
|
||||
$('#missionPlanerElevation').hide();
|
||||
cleanHomeLayers();
|
||||
}
|
||||
|
||||
function cleanHomeLayers() {
|
||||
for (var i in homeMarkers) {
|
||||
map.removeLayer(homeMarkers[i]);
|
||||
}
|
||||
homeMarkers = [];
|
||||
}
|
||||
|
||||
function renderHomeTable() {
|
||||
/*
|
||||
* Process home table UI
|
||||
*/
|
||||
|
||||
$(".home-lon").val(HOME.getLonMap()).change(function () {
|
||||
HOME.setLon(Math.round(Number($(this).val()) * 10000000));
|
||||
cleanHomeLayers();
|
||||
renderHomeOnMap();
|
||||
});
|
||||
|
||||
$(".home-lat").val(HOME.getLatMap()).change(function () {
|
||||
HOME.setLat(Math.round(Number($(this).val()) * 10000000));
|
||||
cleanHomeLayers();
|
||||
renderHomeOnMap();
|
||||
});
|
||||
|
||||
(async () => {
|
||||
const elevationAtHome = await HOME.getElevation(globalSettings);
|
||||
$('#elevationValueAtHome').text(elevationAtHome+' m');
|
||||
HOME.setAlt(elevationAtHome);
|
||||
})()
|
||||
|
||||
}
|
||||
|
||||
|
||||
function renderHomeOnMap() {
|
||||
/*
|
||||
* Process home on Map
|
||||
*/
|
||||
map.addLayer(addHomeMarker(HOME));
|
||||
}
|
||||
|
||||
function addHomeMarker(home) {
|
||||
/*
|
||||
* add safehome on Map
|
||||
*/
|
||||
let coord = ol.proj.fromLonLat([home.getLonMap(), home.getLatMap()]);
|
||||
var iconFeature = new ol.Feature({
|
||||
geometry: new ol.geom.Point(coord),
|
||||
name: 'home'
|
||||
});
|
||||
|
||||
//iconFeature.setStyle(getSafehomeIcon(safehome, safehome.isUsed()));
|
||||
|
||||
var vectorLayer = new ol.layer.Vector({
|
||||
source: new ol.source.Vector({
|
||||
features: [iconFeature]
|
||||
}),
|
||||
style : function(iconFeature) {
|
||||
let styles = [getHomeIcon(home)];
|
||||
return styles;
|
||||
}
|
||||
});
|
||||
|
||||
vectorLayer.kind = "home";
|
||||
vectorLayer.number = home.getNumber();
|
||||
vectorLayer.selection = false;
|
||||
|
||||
homeMarkers.push(vectorLayer);
|
||||
|
||||
return vectorLayer;
|
||||
}
|
||||
|
||||
function getHomeIcon(home) {
|
||||
/*
|
||||
* Process Safehome Icon
|
||||
*/
|
||||
return new ol.style.Style({
|
||||
image: new ol.style.Icon(({
|
||||
anchor: [0.5, 1],
|
||||
opacity: 1,
|
||||
scale: 0.5,
|
||||
src: '../images/icons/cf_icon_home.png'
|
||||
})),
|
||||
});
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////
|
||||
//
|
||||
// Manage Waypoint
|
||||
|
@ -1117,6 +1220,10 @@ TABS.mission_control.initialize = function (callback) {
|
|||
button.style = 'background: url(\'../images/icons/cf_icon_elevation_white.svg\') no-repeat 1px -1px;background-color: rgba(0,60,136,.5);';
|
||||
|
||||
var handleShowSettings = function () {
|
||||
$('#missionPlanerHome').fadeIn(300);
|
||||
cleanHomeLayers();
|
||||
renderHomeTable();
|
||||
renderHomeOnMap();
|
||||
$('#missionPlanerElevation').fadeIn(300);
|
||||
plotElevation();
|
||||
};
|
||||
|
@ -1178,7 +1285,7 @@ TABS.mission_control.initialize = function (callback) {
|
|||
|
||||
var geometry = /** @type {ol.geom.SimpleGeometry} */
|
||||
(this.feature_.getGeometry());
|
||||
if (tempMarker.kind == "waypoint" ||tempMarker.kind == "safehome") {
|
||||
if (tempMarker.kind == "waypoint" ||tempMarker.kind == "safehome" || tempMarker.kind == "home") {
|
||||
geometry.translate(deltaX, deltaY);
|
||||
this.coordinate_[0] = evt.coordinate[0];
|
||||
this.coordinate_[1] = evt.coordinate[1];
|
||||
|
@ -1202,6 +1309,12 @@ TABS.mission_control.initialize = function (callback) {
|
|||
$safehomesTableBody.find('tr:nth-child('+String(tempMarker.number+1)+') > td > .safehome-lon').val(Math.round(coord[0] * 10000000) / 10000000);
|
||||
$safehomesTableBody.find('tr:nth-child('+String(tempMarker.number+1)+') > td > .safehome-lat').val(Math.round(coord[1] * 10000000) / 10000000);
|
||||
}
|
||||
else if (tempMarker.kind == "home") {
|
||||
HOME.setLon(Math.round(coord[0] * 10000000));
|
||||
HOME.setLat(Math.round(coord[1] * 10000000));
|
||||
$('.home-lon').val(Math.round(coord[0] * 10000000) / 10000000);
|
||||
$('.home-lat').val(Math.round(coord[1] * 10000000) / 10000000);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
@ -1235,9 +1348,20 @@ TABS.mission_control.initialize = function (callback) {
|
|||
app.Drag.prototype.handleUpEvent = function (evt) {
|
||||
if (tempMarker.kind == "waypoint" ){
|
||||
if (mission.getWaypoint(tempMarker.number).getP3() == 1.0) {
|
||||
mission.getWaypoint(tempMarker.number).getElevation(globalSettings);
|
||||
(async () => {
|
||||
const elevationAtWP = await mission.getWaypoint(tempMarker.number).getElevation(globalSettings);
|
||||
$('#elevationValueAtWP').text(elevationAtWP);
|
||||
})()
|
||||
}
|
||||
}
|
||||
else if (tempMarker.kind == "home" ) {
|
||||
(async () => {
|
||||
const elevationAtHome = await HOME.getElevation(globalSettings);
|
||||
$('#elevationValueAtHome').text(elevationAtHome+' m');
|
||||
HOME.setAlt(elevationAtHome);
|
||||
plotElevation();
|
||||
})()
|
||||
}
|
||||
this.coordinate_ = null;
|
||||
this.feature_ = null;
|
||||
return false;
|
||||
|
@ -1398,6 +1522,13 @@ TABS.mission_control.initialize = function (callback) {
|
|||
$safehomesTableBody.find('tr:nth-child('+String(tempMarker.number+1)+') > td > .safehome-lon').val(Math.round(coord[0] * 10000000) / 10000000);
|
||||
$safehomesTableBody.find('tr:nth-child('+String(tempMarker.number+1)+') > td > .safehome-lat').val(Math.round(coord[1] * 10000000) / 10000000);
|
||||
}
|
||||
else if (selectedFeature && tempMarker.kind == "home" && tempMarker.selection) {
|
||||
selectedMarker = HOME;
|
||||
var geometry = selectedFeature.getGeometry();
|
||||
var coord = ol.proj.toLonLat(geometry.getCoordinates());
|
||||
$('.home-lon').val(Math.round(coord[0] * 10000000) / 10000000);
|
||||
$('.home-lat').val(Math.round(coord[1] * 10000000) / 10000000);
|
||||
}
|
||||
else {
|
||||
let tempWpCoord = ol.proj.toLonLat(evt.coordinate);
|
||||
let tempWp = new Waypoint(mission.get().length, MWNP.WPTYPE.WAYPOINT, Math.round(tempWpCoord[1] * 10000000), Math.round(tempWpCoord[0] * 10000000), alt=Number(settings.alt), p1=Number(settings.speed));
|
||||
|
@ -1483,6 +1614,19 @@ TABS.mission_control.initialize = function (callback) {
|
|||
}
|
||||
});
|
||||
|
||||
$('#showHideHomeButton').on('click', function () {
|
||||
var src = ($(this).children().attr('class') === 'ic_hide')
|
||||
? 'ic_show'
|
||||
: 'ic_hide';
|
||||
$(this).children().attr('class', src);
|
||||
if ($(this).children().attr('class') === 'ic_hide') {
|
||||
$('#HomeContent').fadeIn(300);
|
||||
}
|
||||
else {
|
||||
$('#HomeContent').fadeOut(300);
|
||||
}
|
||||
});
|
||||
|
||||
$('#showHideWPeditButton').on('click', function () {
|
||||
var src = ($(this).children().attr('class') === 'ic_hide')
|
||||
? 'ic_show'
|
||||
|
@ -1658,6 +1802,23 @@ TABS.mission_control.initialize = function (callback) {
|
|||
}, 500);
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Callback for HOME Table
|
||||
/////////////////////////////////////////////
|
||||
$('#homeTableBody').on('click', "[data-role='home-center']", function (event) {
|
||||
let mapCenter = map.getView().getCenter();
|
||||
HOME.setLon(Math.round(ol.proj.toLonLat(mapCenter)[0] * 1e7));
|
||||
HOME.setLat(Math.round(ol.proj.toLonLat(mapCenter)[1] * 1e7));
|
||||
renderHomeTable();
|
||||
cleanHomeLayers();
|
||||
renderHomeOnMap();
|
||||
plotElevation();
|
||||
});
|
||||
|
||||
$('#cancelHome').on('click', function () {
|
||||
closeHomePanel();
|
||||
});
|
||||
|
||||
/////////////////////////////////////////////
|
||||
// Callback for Remove buttons
|
||||
/////////////////////////////////////////////
|
||||
|
@ -2002,22 +2163,60 @@ TABS.mission_control.initialize = function (callback) {
|
|||
}
|
||||
|
||||
function plotElevation() {
|
||||
mission.getElevation(globalSettings);
|
||||
var trace1 = {
|
||||
x: [1, 2, 3, 4],
|
||||
y: [10, 15, 13, 17],
|
||||
type: 'scatter'
|
||||
(async () => {
|
||||
const [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure] = await mission.getElevation(globalSettings);
|
||||
|
||||
var trace_WGS84 = {
|
||||
x: Array.from(Array(samples), (_,i)=> i*totalMissionDistance/samples),
|
||||
y: elevation,
|
||||
type: 'scatter',
|
||||
name: 'WGS84 elevation',
|
||||
fill: 'tozeroy',
|
||||
line: {
|
||||
color: '#ff7f0e',
|
||||
},
|
||||
};
|
||||
|
||||
var trace2 = {
|
||||
x: [1, 2, 3, 4],
|
||||
y: [16, 5, 11, 9],
|
||||
type: 'scatter'
|
||||
var trace_missionHeight = {
|
||||
x: lengthMission,
|
||||
y: altPoint2measure.map(x => x / 100 + HOME.getAlt()) ,
|
||||
type: 'scatter',
|
||||
mode: 'lines+markers+text',
|
||||
name: 'Mission altitude',
|
||||
text: namePoint2measure,
|
||||
textposition: 'top center',
|
||||
textfont: {
|
||||
family: 'Raleway, sans-serif'
|
||||
},
|
||||
line: {
|
||||
color: '#1497f1',
|
||||
},
|
||||
marker: {
|
||||
color: '#1f77b4',
|
||||
},
|
||||
};
|
||||
|
||||
var data = [trace1, trace2];
|
||||
var layout = {showlegend: true,
|
||||
legend: {
|
||||
"orientation": "h",
|
||||
xanchor: "center",
|
||||
y: 1.2,
|
||||
x: 0.5
|
||||
},
|
||||
title: 'Mission Elevation Profile',
|
||||
xaxis: {
|
||||
title: 'Distance (m)'
|
||||
},
|
||||
yaxis: {
|
||||
title: 'Elevation (m)'
|
||||
},
|
||||
height: 300,
|
||||
}
|
||||
|
||||
Plotly.newPlot('elevationDiv', data);
|
||||
var data = [trace_WGS84, trace_missionHeight];
|
||||
|
||||
Plotly.newPlot('elevationDiv', data, layout);
|
||||
})()
|
||||
}
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue