mirror of
https://github.com/iNavFlight/inav-configurator.git
synced 2025-07-17 05:15:20 +03:00
Sealevel Ref
This commit is contained in:
parent
1623dfbb66
commit
0c4f12f499
6 changed files with 74 additions and 14 deletions
|
@ -55,7 +55,7 @@ let GeozoneVertex = function (number, lat, lon) {
|
|||
return self;
|
||||
}
|
||||
|
||||
let Geozone = function (type, shape, minAltitude, maxAltitude, radius, fenceAction, vertices, number = 0) {
|
||||
let Geozone = function (type, shape, minAltitude, maxAltitude, sealevelRef, radius, fenceAction, vertices, number = 0) {
|
||||
var self = {};
|
||||
|
||||
self.setNumber = (data) => {
|
||||
|
@ -98,6 +98,14 @@ let Geozone = function (type, shape, minAltitude, maxAltitude, radius, fenceActi
|
|||
return maxAltitude;
|
||||
}
|
||||
|
||||
self.setSealevelRef = (data) => {
|
||||
sealevelRef = data;
|
||||
}
|
||||
|
||||
self.getSealevelRef = () => {
|
||||
return sealevelRef;
|
||||
}
|
||||
|
||||
self.setRadius = (data) => {
|
||||
radius = data;
|
||||
}
|
||||
|
@ -168,6 +176,27 @@ let Geozone = function (type, shape, minAltitude, maxAltitude, radius, fenceActi
|
|||
vertices = [];
|
||||
}
|
||||
|
||||
self.getElevationFromServer = async function (lon, lat, 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='+lat+','+lon+'&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='+lat+','+lon);
|
||||
const myJson = await response.json();
|
||||
if (myJson.status == "OK" && myJson.results[0].elevation != null) {
|
||||
elevation = myJson.results[0].elevation;
|
||||
}
|
||||
}
|
||||
return elevation;
|
||||
}
|
||||
|
||||
return self;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
|
|
@ -132,6 +132,7 @@ let GeozoneCollection = function() {
|
|||
buffer.push(BitHelper.specificByte(zone.getMaxAltitude(), 1));
|
||||
buffer.push(BitHelper.specificByte(zone.getMaxAltitude(), 2));
|
||||
buffer.push(BitHelper.specificByte(zone.getMaxAltitude(), 3));
|
||||
buffer.push(zone.getSealevelRef());
|
||||
buffer.push(zone.getFenceAction());
|
||||
if (zone.getShape() == GeozoneShapes.CIRCULAR) {
|
||||
buffer.push(2);
|
||||
|
|
|
@ -1608,16 +1608,17 @@ var mspHelper = (function () {
|
|||
|
||||
case MSPCodes.MSP2_INAV_GEOZONE:
|
||||
var geozone = new Geozone(
|
||||
data.getUint8(0),
|
||||
data.getUint8(1),
|
||||
data.getInt32(2, true),
|
||||
data.getInt32(6, true),
|
||||
data.getUint8(2),
|
||||
data.getInt32(3, true),
|
||||
data.getInt32(4, true),
|
||||
data.getUint8(11),
|
||||
0,
|
||||
data.getInt8(10, true),
|
||||
data.getInt8(12, true),
|
||||
null,
|
||||
data.getUint8(12, true),
|
||||
data.getUint8(14, true),
|
||||
);
|
||||
let verticesCount = data.getUint8(11, true);
|
||||
let verticesCount = data.getUint8(13, true);
|
||||
if (verticesCount == 0) {
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -335,12 +335,18 @@
|
|||
<div class="point">
|
||||
<label class="point-label" for="zoneMinAlt" data-i18n="geozoneMinAlt"></label>
|
||||
<input type="number" id="geozoneMinAlt"></input>
|
||||
<span id="geozoneMinAltM"></span>
|
||||
</div>
|
||||
<div class="point">
|
||||
<label class="point-label" for="zoneMaxAlt" data-i18n="geozoneMaxAlt"></label>
|
||||
<input type="number" id="geozoneMaxAlt"></input>
|
||||
<span id="geozoneMaxAltM"></span><br/>
|
||||
<span data-i18n="geozoneInfiniteAlt"></span>
|
||||
</div>
|
||||
<div class="point">
|
||||
<label class="point-label" for="geozoneSeaLevelRef" data-i18n="missionSeaLevelRef"></label>
|
||||
<input id="geozoneSeaLevelRef" type="checkbox" value="0" class="togglemedium" required>
|
||||
</div>
|
||||
<div class="point">
|
||||
<label class="point-label" for="zoneAction" data-i18n="geozoneAction">Action:</label>
|
||||
<select name="zoneAction" id="geozoneAction">
|
||||
|
|
|
@ -31,6 +31,7 @@ const Plotly = require('./../js/libraries/plotly-latest.min');
|
|||
const interval = require('./../js/intervals');
|
||||
const { Geozone, GeozoneVertex, GeozoneType, GeozoneShapes, GeozoneFenceAction } = require('./../js/geozone');
|
||||
const GeozoneCollection = require('./../js/geozoneCollection');
|
||||
const { event } = require('jquery');
|
||||
|
||||
var MAX_NEG_FW_LAND_ALT = -2000; // cm
|
||||
|
||||
|
@ -978,7 +979,7 @@ TABS.mission_control.initialize = function (callback) {
|
|||
let mapCenter = map.getView().getCenter();
|
||||
let midLon = Math.round(ol.proj.toLonLat(mapCenter)[0] * 1e7);
|
||||
let midLat = Math.round(ol.proj.toLonLat(mapCenter)[1] * 1e7);
|
||||
FC.GEOZONES.put(new Geozone(GeozoneType.INCLUSIVE, GeozoneShapes.CIRCULAR, 0, 10000, 20000, GeozoneFenceAction.NONE, [ new GeozoneVertex(0, midLat, midLon) ]));
|
||||
FC.GEOZONES.put(new Geozone(GeozoneType.INCLUSIVE, GeozoneShapes.CIRCULAR, 0, 10000, false, 20000, GeozoneFenceAction.NONE, [ new GeozoneVertex(0, midLat, midLon) ]));
|
||||
|
||||
selectedGeozone = FC.GEOZONES.last();
|
||||
renderGeozoneOptions();
|
||||
|
@ -1689,6 +1690,9 @@ TABS.mission_control.initialize = function (callback) {
|
|||
$('#geozoneType').val(selectedGeozone.getType());
|
||||
$('#geozoneMinAlt').val(selectedGeozone.getMinAltitude());
|
||||
$('#geozoneMaxAlt').val(selectedGeozone.getMaxAltitude());
|
||||
$('#geozoneMinAltM').text(selectedGeozone.getMinAltitude() / 100 + " m");
|
||||
$('#geozoneMaxAltM').text(selectedGeozone.getMaxAltitude() / 100 + " m");
|
||||
changeSwitchery($('#geozoneSeaLevelRef'), selectedGeozone.getSealevelRef());
|
||||
$('#geozoneAction').val(selectedGeozone.getFenceAction());
|
||||
$('#geozoneRadius').val(selectedGeozone.getRadius);
|
||||
if (selectedGeozone.getShape() == GeozoneShapes.CIRCULAR) {
|
||||
|
@ -3414,20 +3418,39 @@ TABS.mission_control.initialize = function (callback) {
|
|||
$('#geozoneMinAlt').on('change', event => {
|
||||
if (selectedGeozone) {
|
||||
selectedGeozone.setMinAltitude($(event.currentTarget).val());
|
||||
renderGeozonesOnMap();
|
||||
renderGeozoneOptions();
|
||||
}
|
||||
});
|
||||
$('#geozoneMaxAlt').on('change', event => {
|
||||
if (selectedGeozone) {
|
||||
selectedGeozone.setMaxAltitude($(event.currentTarget).val());
|
||||
renderGeozonesOnMap();
|
||||
renderGeozoneOptions();
|
||||
}
|
||||
});
|
||||
|
||||
$('#geozoneSeaLevelRef').on('change', event => {
|
||||
if (selectedGeozone) {
|
||||
const isChecked = $(event.currentTarget).prop('checked') ? 1 : 0;
|
||||
selectedGeozone.setSealevelRef(isChecked);
|
||||
(async () => {
|
||||
const vertex = selectedGeozone.getVertex(0);
|
||||
const elevation = await selectedGeozone.getElevationFromServer(vertex.getLonMap(), vertex.getLatMap(), globalSettings);
|
||||
|
||||
if (isChecked) {
|
||||
selectedGeozone.setMinAltitude(Number(selectedGeozone.getMinAltitude()) + elevation * 100);
|
||||
selectedGeozone.setMaxAltitude(Number(selectedGeozone.getMaxAltitude()) + elevation * 100);
|
||||
} else {
|
||||
selectedGeozone.setMinAltitude(Number(selectedGeozone.getMinAltitude()) - elevation * 100);
|
||||
selectedGeozone.setMaxAltitude(Number(selectedGeozone.getMaxAltitude()) - elevation * 100);
|
||||
}
|
||||
renderGeozoneOptions();
|
||||
})();
|
||||
}
|
||||
});
|
||||
|
||||
$('#geozoneAction').on('change', event => {
|
||||
if (selectedGeozone) {
|
||||
selectedGeozone.setFenceAction($(event.currentTarget).val());
|
||||
renderGeozonesOnMap();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -1760,7 +1760,7 @@ OSD.constants = {
|
|||
}
|
||||
},{
|
||||
name: 'COURSE_NEXT_GEOZONE',
|
||||
id: 159,
|
||||
id: 163,
|
||||
min_version: '8.0.0',
|
||||
enabled: function() {
|
||||
return FC.isFeatureEnabled('GEOZONE');
|
||||
|
@ -1768,7 +1768,7 @@ OSD.constants = {
|
|||
preview: FONT.symbol(SYM.DIR_TO_HOME)
|
||||
}, {
|
||||
name: 'HOR_DIST_TO_NEXT_GEOZONE',
|
||||
id: 160,
|
||||
id: 164,
|
||||
min_version: '8.0.0',
|
||||
enabled: function() {
|
||||
return FC.isFeatureEnabled('GEOZONE');
|
||||
|
@ -1787,7 +1787,7 @@ OSD.constants = {
|
|||
},
|
||||
{
|
||||
name: 'VERT_DIST_TO_NEXT_GEOZONE',
|
||||
id: 161,
|
||||
id: 165,
|
||||
min_version: '8.0.0',
|
||||
enabled: function() {
|
||||
return FC.isFeatureEnabled('GEOZONE');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue