Skip to content

Commit

Permalink
Sealevel Ref
Browse files Browse the repository at this point in the history
  • Loading branch information
Scavanger committed Nov 10, 2024
1 parent 1623dfb commit 0c4f12f
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 14 deletions.
31 changes: 30 additions & 1 deletion js/geozone.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Expand Down
1 change: 1 addition & 0 deletions js/geozoneCollection.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions js/msp/MSPHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions tabs/mission_control.html
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down
31 changes: 27 additions & 4 deletions tabs/mission_control.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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();
}
});

Expand Down
6 changes: 3 additions & 3 deletions tabs/osd.js
Original file line number Diff line number Diff line change
Expand Up @@ -1760,15 +1760,15 @@ OSD.constants = {
}
},{
name: 'COURSE_NEXT_GEOZONE',
id: 159,
id: 163,
min_version: '8.0.0',
enabled: function() {
return FC.isFeatureEnabled('GEOZONE');
},
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');
Expand All @@ -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');
Expand Down

0 comments on commit 0c4f12f

Please sign in to comment.