diff --git a/_locales/en/messages.json b/_locales/en/messages.json index e44b7738..296e0edf 100755 --- a/_locales/en/messages.json +++ b/_locales/en/messages.json @@ -3351,7 +3351,7 @@ }, "osdSettingPLUS_CODE_DIGITS_HELP": { "message": "Precision at the equator: 10=13.9x13.9m; 11=2.8x3.5m; 12=56x87cm; 13=11x22cm." - }, + }, "osdSettingPLUS_CODE_SHORT_HELP": { "message": "Removing 2, 4 and 6 leading digits requires a reference location within, respectively, ~800km, ~40km and ~2km to recover the original coordinates." }, @@ -3971,7 +3971,7 @@ "message": "I2C Speed" }, "configurationI2cSpeedHelp": { - "message": "I2C speed should be kept at the highest level that allows for all connected devices to work. Default 400kHz is a save value and it is suggested to switch to 800kHz in case of Multirotors." + "message": "I2C speed should be kept at the highest level that allows for all connected devices to work. Default 400kHz is a safe value and it is suggested to switch to 800kHz in case of Multirotors." }, "i2cSpeedSuggested800khz": { "message": "Please switch to 800kHz if connected hardware allows for it" @@ -4003,6 +4003,9 @@ "MissionPlannerJumpTargetRemoval": { "message": "You can't remove a Waypoint which is defined as a JUMP target! \nYou first need to remove the target on the waypoint triggering the JUMP." }, + "MissionPlannerAltitudeChangeReset": { + "message": "Altitude below ground level. Change ignored" + }, "SafehomeSelected": { "message": "" }, diff --git a/js/fc.js b/js/fc.js index b8faf75d..50e18b75 100644 --- a/js/fc.js +++ b/js/fc.js @@ -861,7 +861,7 @@ var FC = { return []; }, getAccelerometerNames: function () { - return [ "NONE", "AUTO", "ADXL345", "MPU6050", "MMA845x", "BMA280", "LSM303DLHC", "MPU6000", "MPU6500", "MPU9250", "BMI160", "ICM20689", "FAKE"]; + return [ "NONE", "AUTO", "MPU6050", "LSM303DLHC", "MPU6000", "MPU6500", "MPU9250", "BMI160", "ICM20689", "FAKE"]; }, getBarometerNames: function () { if (semver.gte(CONFIG.flightControllerVersion, "2.6.0")) { diff --git a/js/waypoint.js b/js/waypoint.js index d117c40c..348cf270 100644 --- a/js/waypoint.js +++ b/js/waypoint.js @@ -15,7 +15,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setNumber = function (data) { number = data; }; - + self.getLayerNumber = function () { return layerNumber; }; @@ -23,7 +23,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setLayerNumber = function (data) { layerNumber = data; }; - + self.getPoiNumber = function () { return poiNumber; }; @@ -31,7 +31,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setPoiNumber = function (data) { poiNumber = data; }; - + self.isUsed = function () { return isUsed; }; @@ -39,7 +39,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setUsed = function (data) { isUsed = data; }; - + self.isAttached = function () { return isAttached; }; @@ -51,7 +51,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.getLon = function () { return lon; }; - + self.getLonMap = function () { return lon / 10000000; }; @@ -63,7 +63,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.getLat = function () { return lat; }; - + self.getLatMap = function () { return lat / 10000000; }; @@ -71,55 +71,55 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setLat = function (data) { lat = data; }; - + self.getAction = function () { return action; }; - + self.setAction = function (data) { action = data; }; - + self.getAlt = function () { return alt; }; - + self.setAlt = function (data) { alt = data; }; - + self.getP1 = function () { return p1; }; - + self.setP1 = function (data) { p1 = data; }; - + self.getP2 = function () { return p2; }; - + self.setP2 = function (data) { p2 = data; }; - + self.getP3 = function () { return p3; }; - + self.setP3 = function (data) { p3 = data; }; - + self.getEndMission = function () { return endMission; }; - + self.setEndMission = function (data) { endMission = data; }; - + self.getAttachedId = function () { return attachedId; }; @@ -127,7 +127,7 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setAttachedId = function (data) { attachedId = data; }; - + self.getAttachedNumber = function () { return attachedNumber; }; @@ -135,16 +135,18 @@ let Waypoint = function (number, action, lat, lon, alt=0, p1=0, p2=0, p3=0, endM self.setAttachedNumber = function (data) { attachedNumber = data; }; - + self.getElevation = async function (globalSettings) { let elevation; 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 myJson = await response.json(); + let elevationEarthModel = $('#elevationEarthModel').prop("checked") ? "sealevel" : "ellipsoid"; + + const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+self.getLatMap()+','+self.getLonMap()+'&heights='+elevationEarthModel+'&key='+globalSettings.mapApiKey); + const myJson = await response.json(); elevation = myJson.resourceSets[0].resources[0].elevations[0]; } else { - elevation = "NA"; + elevation = "N/A"; } return elevation; } diff --git a/js/waypointCollection.js b/js/waypointCollection.js index e1f9bf66..925a1e76 100644 --- a/js/waypointCollection.js +++ b/js/waypointCollection.js @@ -10,7 +10,7 @@ let WaypointCollection = function () { countBusyPoints = 0, version = 0, center = {} - + self.getMaxWaypoints = function () { return maxWaypoints; }; @@ -18,15 +18,15 @@ let WaypointCollection = function () { self.setMaxWaypoints = function (data) { maxWaypoints = data; }; - + self.getValidMission = function () { return isValidMission; }; - + self.setValidMission = function (data) { isValidMission = data; }; - + self.getCountBusyPoints = function () { return countBusyPoints; }; @@ -34,7 +34,7 @@ let WaypointCollection = function () { self.setCountBusyPoints = function (data) { countBusyPoints = data; }; - + self.getVersion = function () { return version; }; @@ -42,11 +42,11 @@ let WaypointCollection = function () { self.setVersion = function (data) { version = data; }; - + self.getCenter = function () { return center; }; - + self.setCenter = function (data) { center = data; }; @@ -54,11 +54,11 @@ let WaypointCollection = function () { self.setCenterZoom = function (data) { center.zoom = data; }; - + self.setCenterLon = function (data) { center.lon = data; }; - + self.setCenterLat = function (data) { center.lat = data; }; @@ -70,7 +70,7 @@ let WaypointCollection = function () { self.get = function () { return data; }; - + self.isEmpty = function () { return data == []; }; @@ -78,7 +78,7 @@ let WaypointCollection = function () { self.flush = function () { data = []; }; - + self.reinit = function () { data = []; maxWaypoints = 60; @@ -99,13 +99,13 @@ let WaypointCollection = function () { } } }; - + self.updateWaypoint = function(newWaypoint) { if (newWaypoint.isUsed()) { data[newWaypoint.getNumber()] = newWaypoint; } }; - + self.dropWaypoint = function(newWaypoint) { self.getWaypoint(newWaypoint.getNumber()).setUsed(false); let indexId = newWaypoint.getNumber() @@ -120,7 +120,7 @@ let WaypointCollection = function () { data.splice(indexId, 1); }; - + self.insertWaypoint = function (newWaypoint, indexId) { data.forEach(function (wp) { if (wp.getNumber() >= indexId) { @@ -133,7 +133,7 @@ let WaypointCollection = function () { data.splice(indexId, 0, newWaypoint); }; - + self.drop = function (waypointId) { self.getWaypoint(waypointId).setUsed(false); var tmpData = []; @@ -148,7 +148,7 @@ let WaypointCollection = function () { data = tmpData; }; - + self.update = function (bMWPfile=false, bReverse=false) { let oldWPNumber = 0; let optionIdx = 0; @@ -167,7 +167,7 @@ let WaypointCollection = function () { element.setP1(element.getP1()+1); } } - + if ([MWNP.WPTYPE.JUMP,MWNP.WPTYPE.SET_HEAD,MWNP.WPTYPE.RTH].includes(element.getAction())) { element.setAttachedId(oldWPNumber); element.setAttachedNumber(optionIdx); @@ -189,7 +189,7 @@ let WaypointCollection = function () { } }); }; - + self.getNonAttachedList = function () { let tmpData = []; data.forEach(function (element) { @@ -199,8 +199,8 @@ let WaypointCollection = function () { }); return tmpData; - } - + } + self.getAttachedList = function () { let tmpData = []; data.forEach(function (element) { @@ -210,8 +210,8 @@ let WaypointCollection = function () { }); return tmpData; - } - + } + self.getAttachedFromWaypoint = function (waypoint) { let tmpData = []; data.forEach(function (element) { @@ -221,8 +221,8 @@ let WaypointCollection = function () { }); return tmpData; - } - + } + self.addAttachedFromWaypoint = function (waypoint) { let tmpNumber = 0; let tmpData = self.getAttachedFromWaypoint(waypoint); @@ -234,8 +234,8 @@ let WaypointCollection = function () { tempWp.setAttachedId(waypoint.getNumber()); self.insertWaypoint(tempWp, waypoint.getNumber()+tmpNumber+1); self.update(); - } - + } + self.dropAttachedFromWaypoint = function (waypoint, waypointAttachedNumber) { data.forEach(function (element) { if (element.isAttached() && element.getAttachedId() == waypoint.getNumber() && element.getAttachedNumber() == waypointAttachedNumber) { @@ -243,9 +243,9 @@ let WaypointCollection = function () { self.update(); } }); - - } - + + } + self.extractBuffer = function(waypointId) { let buffer = []; let waypoint = self.getWaypoint(waypointId); @@ -270,10 +270,10 @@ let WaypointCollection = function () { buffer.push(lowByte(waypoint.getP3())); //sbufReadU16(src); // P3 buffer.push(highByte(waypoint.getP3())); buffer.push(waypoint.getEndMission()); //sbufReadU8(src); // future: to set nav flag - + return buffer; } - + self.missionDisplayDebug = function() { if (data && data.length != 0) { data.forEach(function (element) { @@ -289,7 +289,7 @@ let WaypointCollection = function () { }); } } - + self.copy = function(mission){ mission.get().forEach(function (element) { self.put(element); @@ -300,7 +300,7 @@ let WaypointCollection = function () { self.setVersion(mission.getVersion()); self.setCenter(mission.getCenter()); } - + self.convertJumpNumberToWaypoint = function(jumpId) { let outputNumber = 0; self.getNonAttachedList().forEach(function (element) { @@ -310,7 +310,7 @@ let WaypointCollection = function () { }); return outputNumber; } - + self.isJumpTargetAttached = function(waypoint) { let lJumptTargetAttached = []; data.forEach(function (element) { @@ -320,7 +320,7 @@ let WaypointCollection = function () { }); return (lJumptTargetAttached.length != 0 && lJumptTargetAttached != 'undefined') } - + self.getPoiList = function() { let poiList = []; data.forEach(function (element) { @@ -330,7 +330,7 @@ let WaypointCollection = function () { }); return poiList; } - + self.getPoint2Measure = function(reverse=false) { let point2measure = []; let altPoint2measure = []; @@ -383,10 +383,10 @@ let WaypointCollection = function () { nStart++; } } - + return [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure]; } - + self.getDistance = function(display) { let lengthLine = []; const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure(); @@ -394,9 +394,9 @@ let WaypointCollection = function () { return [-1]; } else { - + const cumulativeSum = (sum => value => sum += value)(0); - + let oldCoord = []; point2measure.forEach(function (coord) { if (oldCoord != 'undefined' && oldCoord != []) { @@ -408,7 +408,7 @@ let WaypointCollection = function () { return lengthLine.map(cumulativeSum); } } - + self.getElevation = async function(globalSettings) { const [nLoop, point2measure, altPoint2measure, namePoint2measure, refPoint2measure] = self.getPoint2Measure(true); let lengthMission = self.getDistance(true); @@ -424,19 +424,21 @@ let WaypointCollection = function () { samples = 1024; } if (globalSettings.mapProviderType == 'bing') { + let elevationEarthModel = $('#elevationEarthModel').prop("checked") ? "sealevel" : "ellipsoid"; + if (point2measure.length >1) { - const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/Polyline?points='+point2measure+'&heights=ellipsoid&samples='+String(samples+1)+'&key='+globalSettings.mapApiKey); - const myJson = await response.json(); + const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/Polyline?points='+point2measure+'&heights='+elevationEarthModel+'&samples='+String(samples+1)+'&key='+globalSettings.mapApiKey); + 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(); + const response = await fetch('http://dev.virtualearth.net/REST/v1/Elevation/List?points='+point2measure+'&heights='+elevationEarthModel+'&key='+globalSettings.mapApiKey); + const myJson = await response.json(); elevation = myJson.resourceSets[0].resources[0].elevations; } } else { - elevation = "NA"; + elevation = "N/A"; } //console.log("elevation ", elevation); return [lengthMission, totalMissionDistance, samples, elevation, altPoint2measure, namePoint2measure, refPoint2measure]; diff --git a/resources/motor_order/flying_wing.svg b/resources/motor_order/flying_wing.svg index cc8f2ba1..587aaa5a 100644 --- a/resources/motor_order/flying_wing.svg +++ b/resources/motor_order/flying_wing.svg @@ -27,12 +27,12 @@ viewBox="0 0 850 850" - + - + diff --git a/src/css/tabs/auxiliary.css b/src/css/tabs/auxiliary.css index 9c0be25f..f6c823a8 100644 --- a/src/css/tabs/auxiliary.css +++ b/src/css/tabs/auxiliary.css @@ -22,6 +22,14 @@ background: #37a8db; } +.tab-auxiliary .mode.inRange .info { + background: #104156; + color: white; +} +.tab-auxiliary .mode.inRange:nth-child(odd) .info { + background: #104156; +} + .tab-auxiliary .mode.off .info { background: #828885; color: white; @@ -198,6 +206,33 @@ padding: 10px 5px; } +.tab-auxiliary .acroEnabled { + margin-top: 0; + margin-bottom: 0; + background-color: #828885; + color: white; + font-family: 'open_sansbold', Arial, serif; + font-size: 12px; + display: block; + cursor: pointer; + transition: all ease 0.2s; + line-height: 28px; + position: fixed; + bottom:10px; + left:20px; + width:10%; + text-align: center; + z-index: 25000; +} + +.tab-auxiliary .acroEnabled.on { + background-color: #37a8db; +} + +.tab-auxiliary .acroEnabled.off { + background-color: #828885; +} + @media only screen and (max-width: 1055px) , only screen and (max-device-width: 1055px) { .tab-auxiliary .fixed_band { width: calc(100% - -30px); diff --git a/src/css/tabs/mission_planer.css b/src/css/tabs/mission_planer.css index ef51efe8..1bdcef81 100644 --- a/src/css/tabs/mission_planer.css +++ b/src/css/tabs/mission_planer.css @@ -302,7 +302,7 @@ .tab-mission-control .safehomesTable { width: 100%; text-align: center; - font-size: 8px; + font-size: 12px; } .tab-mission-control .safehomesTable input[type="text"] { @@ -311,7 +311,7 @@ } .tab-mission-control .safehomesTable input[type="number"] { - font-size: 8px; + font-size: 10px; width: 100%; -moz-appearance: textfield; } @@ -498,8 +498,8 @@ width:20px; } -.tab-mission-control .textLegend{ - margin:2px; +.tab-mission-control .textLegend{ + margin:2px; } .tab-mission-control .valueLegend{ float:right; diff --git a/tabs/auxiliary.html b/tabs/auxiliary.html index 86723342..cec9c2af 100644 --- a/tabs/auxiliary.html +++ b/tabs/auxiliary.html @@ -22,6 +22,9 @@ +
+ ACRO +
diff --git a/tabs/auxiliary.js b/tabs/auxiliary.js index e97cce79..f5085911 100644 --- a/tabs/auxiliary.js +++ b/tabs/auxiliary.js @@ -111,6 +111,7 @@ TABS.auxiliary.initialize = function (callback) { $(newMode).data('index', modeIndex); $(newMode).data('id', modeId); $(newMode).data('origId', ORIG_AUX_CONFIG_IDS[modeIndex]); + $(newMode).data('modeName', AUX_CONFIG[modeIndex]); $(newMode).find('.name').data('modeElement', newMode); $(newMode).find('a.addRange').data('modeElement', newMode); @@ -180,6 +181,7 @@ TABS.auxiliary.initialize = function (callback) { $(rangeElement).find('a.deleteRange').click(function () { var rangeElement = $(this).data('rangeElement'); + modeElement.removeClass('inRange'); rangeElement.remove(); }); @@ -344,8 +346,19 @@ TABS.auxiliary.initialize = function (callback) { function update_ui() { let hasUsedMode = false; + let acroEnabled = true; + let acroFail = ["ANGLE", "HORIZON", "MANUAL", "NAV RTH", "NAV POSHOLD", "NAV CRUISE", "NAV COURSE HOLD", "NAV WP", "GCS NAV"]; + + var auxChannelCount = RC.active_channels - 4; + + for (var i = 0; i < (auxChannelCount); i++) { + update_marker(i, RC.channels[i + 4]); + } + for (var i = 0; i < AUX_CONFIG.length; i++) { var modeElement = $('#mode-' + i); + let inRange = false; + if (modeElement.find(' .range').length == 0) { // if the mode is unused, skip it modeElement.removeClass('off').removeClass('on'); @@ -353,12 +366,48 @@ TABS.auxiliary.initialize = function (callback) { } if (FC.isModeBitSet(modeElement.data('origId'))) { - $('.mode .name').eq(modeElement.data('index')).data('modeElement').addClass('on').removeClass('off'); + // The flight controller can activate the mode + $('.mode .name').eq(modeElement.data('index')).data('modeElement').addClass('on').removeClass('inRange').removeClass('off'); + + if (jQuery.inArray(modeElement.data('modeName'), acroFail) !== -1) { + acroEnabled = false; + } } else { - $('.mode .name').eq(modeElement.data('index')).data('modeElement').removeClass('on').addClass('off'); + // Check to see if the mode is in range + var modeRanges = modeElement.find(' .range'); + for (r = 0; r < modeRanges.length; r++) { + var rangeLow = $(modeRanges[r]).find('.lowerLimitValue').html(); + var rangeHigh = $(modeRanges[r]).find('.upperLimitValue').html(); + var markerPosition = $(modeRanges[r]).find('.marker')[0].style.left; + markerPosition = markerPosition.substring(0, markerPosition.length-1); + + rangeLow = (rangeLow - 900) / (2100-900) * 100; + rangeHigh = (rangeHigh - 900) / (2100-900) * 100; + + if ((markerPosition >= rangeLow) && (markerPosition <= rangeHigh)) { + inRange = true; + } + } + + if (inRange) { + $('.mode .name').eq(modeElement.data('index')).data('modeElement').removeClass('on').addClass('inRange').removeClass('off'); + + if (jQuery.inArray(modeElement.data('modeName'), acroFail) !== -1) { + acroEnabled = false; + } + } else { + // If not, it is shown as disabled. + $('.mode .name').eq(modeElement.data('index')).data('modeElement').removeClass('on').removeClass('inRange').addClass('off'); + } } hasUsedMode = true; } + + if (acroEnabled) { + $('.acroEnabled').addClass('on').removeClass('off'); + } else { + $('.acroEnabled').removeClass('on').addClass('off'); + } let hideUnused = hideUnusedModes && hasUsedMode; for (let i = 0; i < AUX_CONFIG.length; i++) { @@ -367,11 +416,6 @@ TABS.auxiliary.initialize = function (callback) { modeElement.toggle(!hideUnused); } } - var auxChannelCount = RC.active_channels - 4; - - for (var i = 0; i < (auxChannelCount); i++) { - update_marker(i, RC.channels[i + 4]); - } } let hideUnusedModes = false; @@ -391,6 +435,8 @@ TABS.auxiliary.initialize = function (callback) { // enable data pulling helper.mspBalancedInterval.add('aux_data_pull', 50, 1, get_rc_data); + $(".tab-auxiliary .acroEnabled").width($("#mode-0 .info").width()); + GUI.content_ready(callback); } }; @@ -398,3 +444,7 @@ TABS.auxiliary.initialize = function (callback) { TABS.auxiliary.cleanup = function (callback) { if (callback) callback(); }; + +$(window).on('resize', function(){ + $(".tab-auxiliary .acroEnabled").width($("#mode-0 .info").width()); +}); \ No newline at end of file diff --git a/tabs/mission_control.html b/tabs/mission_control.html index 31e49eff..b84aae35 100644 --- a/tabs/mission_control.html +++ b/tabs/mission_control.html @@ -13,7 +13,7 @@
- +
@@ -86,7 +86,7 @@
- +
- - - - + + + + - + - +
- +
+
-
NAN/A
+ - + diff --git a/tabs/mission_control.js b/tabs/mission_control.js index a0960575..aff3497a 100644 --- a/tabs/mission_control.js +++ b/tabs/mission_control.js @@ -108,7 +108,7 @@ TABS.mission_control.initialize = function (callback) { $('#saveEepromMissionButton').hide(); isOffline = true; } - + $safehomesTable = $('.safehomesTable'); $safehomesTableBody = $('#safehomesTableBody'); $waypointOptionsTable = $('.waypointOptionsTable'); @@ -140,7 +140,7 @@ TABS.mission_control.initialize = function (callback) { function get_attitude_data() { MSP.send_message(MSPCodes.MSP_ATTITUDE, false, false, update_gpsTrack); } - + function update_gpsTrack() { let lat = GPS_DATA.lat / 10000000; @@ -338,29 +338,29 @@ TABS.mission_control.initialize = function (callback) { /////////////////////////////////////////////// // - // define & init parameters + // define & init parameters // /////////////////////////////////////////////// - + ////////////////////////////////////////////////////////////////////////////////////////////// // define & init parameters for Map Layer ////////////////////////////////////////////////////////////////////////////////////////////// var markers = []; // Layer for Waypoints var lines = []; // Layer for lines between waypoints var safehomeMarkers =[]; // layer for Safehome points - + var map; - + ////////////////////////////////////////////////////////////////////////////////////////////// // define & init parameters for Selected Marker ////////////////////////////////////////////////////////////////////////////////////////////// var selectedMarker = null; var selectedFeature = null; var tempMarker = null; - + ////////////////////////////////////////////////////////////////////////////////////////////// // define & init parameters for default Settings - ////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////// var vMaxDistSH = 0; var settings = {}; if (CONFIGURATOR.connectionValid) { @@ -381,23 +381,23 @@ TABS.mission_control.initialize = function (callback) { } ////////////////////////////////////////////////////////////////////////////////////////////// // define & init Waypoints parameters - ////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////// 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 - ////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////// //var SAFEHOMES = new SafehomeCollection(); // TO COMMENT FOR RELEASE : DECOMMENT FOR DEBUG //SAFEHOMES.inflate(); // TO COMMENT FOR RELEASE : DECOMMENT FOR DEBUG //var safehomeRangeRadius = 200; //meters //var safehomeSafeRadius = 50; //meters - + ///////////////////////////////////////////// // // Reinit Jquery Form @@ -413,11 +413,11 @@ TABS.mission_control.initialize = function (callback) { $('#missionDistance').text(0); $('#MPeditPoint').fadeOut(300); } - + function clearFilename() { $('#missionFilename').text(''); } - + ///////////////////////////////////////////// // // Manage Settings @@ -441,21 +441,21 @@ TABS.mission_control.initialize = function (callback) { $('#MPdefaultPointSpeed').val(String(settings.speed)); $('#MPdefaultSafeRangeSH').val(String(settings.safeRadiusSH)); } - + function closeSettingsPanel() { $('#missionPlanerSettings').hide(); - } - + } + ///////////////////////////////////////////// // // Manage Safehome // - ///////////////////////////////////////////// + ///////////////////////////////////////////// function closeSafehomePanel() { $('#missionPlanerSafehome').hide(); cleanSafehomeLayers(); - } - + } + function renderSafehomesTable() { /* * Process safehome table UI @@ -474,16 +474,16 @@ TABS.mission_control.initialize = function (callback) { \ \ \ - \ \ + \ \ '); const $row = $safehomesTableBody.find('tr:last'); - - + + $row.find(".safehome-number").text(safehome.getNumber()+1); - + $row.find(".safehome-enabled-value").prop('checked',safehome.isUsed()).change(function () { safehome.setEnabled((($(this).prop('checked')) ? 1 : 0)); SAFEHOMES.updateSafehome(safehome); @@ -497,7 +497,7 @@ TABS.mission_control.initialize = function (callback) { cleanSafehomeLayers(); renderSafehomesOnMap(); }); - + $row.find(".safehome-lat").val(safehome.getLatMap()).change(function () { safehome.setLat(Math.round(Number($(this).val()) * 10000000)); SAFEHOMES.updateSafehome(safehome); @@ -511,8 +511,8 @@ TABS.mission_control.initialize = function (callback) { GUI.switchery(); localize(); } - - + + function renderSafehomesOnMap() { /* * Process safehome on Map @@ -521,14 +521,14 @@ TABS.mission_control.initialize = function (callback) { map.addLayer(addSafeHomeMarker(safehome)); }); } - - function cleanSafehomeLayers() { + + function cleanSafehomeLayers() { for (var i in safehomeMarkers) { map.removeLayer(safehomeMarkers[i]); } safehomeMarkers = []; } - + function getSafehomeIcon(safehome) { /* * Process Safehome Icon @@ -554,7 +554,7 @@ TABS.mission_control.initialize = function (callback) { })) }); } - + function addSafeHomeMarker(safehome) { /* * add safehome on Map @@ -566,7 +566,7 @@ TABS.mission_control.initialize = function (callback) { }); //iconFeature.setStyle(getSafehomeIcon(safehome, safehome.isUsed())); - + let circleStyle = new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(144, 12, 63, 0.5)', @@ -577,7 +577,7 @@ TABS.mission_control.initialize = function (callback) { // color: 'rgba(251, 225, 155, 0.1)' // }) }); - + let circleSafeStyle = new ol.style.Style({ stroke: new ol.style.Stroke({ color: 'rgba(136, 204, 62, 1)', @@ -588,7 +588,7 @@ TABS.mission_control.initialize = function (callback) { color: 'rgba(136, 204, 62, 0.1)' }) */ }); - + var vectorLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: [iconFeature] @@ -608,9 +608,9 @@ TABS.mission_control.initialize = function (callback) { vectorLayer.kind = "safehome"; vectorLayer.number = safehome.getNumber(); vectorLayer.selection = false; - + safehomeMarkers.push(vectorLayer); - + return vectorLayer; } @@ -621,7 +621,7 @@ TABS.mission_control.initialize = function (callback) { let radiusProjected = (radius / ol.proj.METERS_PER_UNIT.m) * resolutionRate; return radiusProjected; } - + ///////////////////////////////////////////// // // Manage Take Off Home @@ -632,47 +632,56 @@ TABS.mission_control.initialize = function (callback) { $('#missionPlanerElevation').hide(); cleanHomeLayers(); } - - function cleanHomeLayers() { + + function cleanHomeLayers() { for (var i in homeMarkers) { map.removeLayer(homeMarkers[i]); } homeMarkers = []; } - + function renderHomeTable() { /* * Process home table UI - */ + */ + + $(".home-lat").val(HOME.getLatMap()).change(function () { + HOME.setLat(Math.round(Number($(this).val()) * 10000000)); + cleanHomeLayers(); + renderHomeOnMap(); + }); $(".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); - })() - + + if (HOME.getLatMap() == 0 && HOME.getLonMap() == 0) { + HOME.setAlt("N/A"); + } else { + (async () => { + const elevationAtHome = await HOME.getElevation(globalSettings); + $('#elevationValueAtHome').text(elevationAtHome+' m'); + HOME.setAlt(elevationAtHome); + })() + } + + if (globalSettings.mapProviderType == 'bing') { + $('#elevationEarthModelclass').fadeIn(300); + } else { + $('#elevationEarthModelclass').fadeOut(300); + } } - - + + function renderHomeOnMap() { /* * Process home on Map */ map.addLayer(addHomeMarker(HOME)); } - + function addHomeMarker(home) { /* * add safehome on Map @@ -684,7 +693,7 @@ TABS.mission_control.initialize = function (callback) { }); //iconFeature.setStyle(getSafehomeIcon(safehome, safehome.isUsed())); - + var vectorLayer = new ol.layer.Vector({ source: new ol.source.Vector({ features: [iconFeature] @@ -698,12 +707,12 @@ TABS.mission_control.initialize = function (callback) { vectorLayer.kind = "home"; vectorLayer.number = home.getNumber(); vectorLayer.selection = false; - + homeMarkers.push(vectorLayer); - + return vectorLayer; } - + function getHomeIcon(home) { /* * Process Safehome Icon @@ -722,23 +731,23 @@ TABS.mission_control.initialize = function (callback) { function updateHome() { renderHomeTable(); cleanHomeLayers(); - renderHomeOnMap(); - plotElevation(); + renderHomeOnMap(); + plotElevation(); } ///////////////////////////////////////////// // // Manage Waypoint // ///////////////////////////////////////////// - + function removeAllWaypoints() { - mission.reinit(); + mission.reinit(); cleanLayers(); clearEditForm(); updateTotalInfo(); clearFilename(); } - + function addWaypointMarker(waypoint, isEdit=false) { let coord = ol.proj.fromLonLat([waypoint.getLonMap(), waypoint.getLatMap()]); @@ -756,7 +765,7 @@ TABS.mission_control.initialize = function (callback) { var vectorLayer = new ol.layer.Vector({ source: vectorSource }); - + vectorLayer.kind = "waypoint"; vectorLayer.number = waypoint.getNumber(); vectorLayer.layerNumber = waypoint.getLayerNumber(); @@ -774,7 +783,7 @@ TABS.mission_control.initialize = function (callback) { 5: 'POI', 8: 'LDG' }; - + return new ol.style.Style({ image: new ol.style.Icon(({ anchor: [0.5, 1], @@ -796,8 +805,8 @@ TABS.mission_control.initialize = function (callback) { })) }); } - - + + function repaintLine4Waypoints(mission) { let oldPos, oldAction, @@ -809,7 +818,7 @@ TABS.mission_control.initialize = function (callback) { cleanLines(); mission.get().forEach(function (element) { if (!element.isAttached()) { - let coord = ol.proj.fromLonLat([element.getLonMap(), element.getLatMap()]); + let coord = ol.proj.fromLonLat([element.getLonMap(), element.getLatMap()]); if (element.getAction() == 5) { // If action is Set_POI, increment counter of POI poiList.push(element.getNumber()); @@ -817,7 +826,7 @@ TABS.mission_control.initialize = function (callback) { activateHead = false; } else { - // If classic WPs, draw standard line in-between + // If classic WPs, draw standard line in-between if (typeof oldPos !== 'undefined' && activatePoi != true && activateHead != true){ paintLine(oldPos, coord, element.getNumber()); } @@ -839,7 +848,7 @@ TABS.mission_control.initialize = function (callback) { } else if (element.isAttached()) { if (element.getAction() == MWNP.WPTYPE.JUMP) { - let coord = ol.proj.fromLonLat([mission.getWaypoint(element.getP1()).getLonMap(), mission.getWaypoint(element.getP1()).getLatMap()]); + let coord = ol.proj.fromLonLat([mission.getWaypoint(element.getP1()).getLonMap(), mission.getWaypoint(element.getP1()).getLatMap()]); paintLine(oldPos, coord, element.getNumber(), color='#e935d6', lineDash=5, lineText="Repeat x"+(element.getP2() == -1 ? " infinite" : String(element.getP2())), selection=false, arrow=true); } // If classic WPs is defined with a heading = -1, change Boolean for POI to false. If it is defined with a value different from -1, activate Heading boolean @@ -864,14 +873,14 @@ TABS.mission_control.initialize = function (callback) { let lengthMission = mission.getDistance(true); $('#missionDistance').text(lengthMission[lengthMission.length -1] != -1 ? lengthMission[lengthMission.length -1].toFixed(1) : 'infinite'); } - + function paintLine(pos1, pos2, pos2ID, color='#1497f1', lineDash=0, lineText="", selection=true, arrow=false) { var line = new ol.geom.LineString([pos1, pos2]); var feature = new ol.Feature({ geometry: line }); - + feature.setStyle( new ol.style.Style({ stroke: new ol.style.Stroke({ @@ -890,7 +899,7 @@ TABS.mission_control.initialize = function (callback) { }), }), ); - + if (arrow) { let dx = pos2[0] - pos1[0]; let dy = pos2[1] - pos1[1]; @@ -910,7 +919,7 @@ TABS.mission_control.initialize = function (callback) { }) ); } - + if (arrow) { var vectorSource = new ol.source.Vector({ @@ -931,7 +940,7 @@ TABS.mission_control.initialize = function (callback) { vectorLayer.kind = "line"; vectorLayer.selection = selection; vectorLayer.number = pos2ID; - + lines.push(vectorLayer); /* var length = ol.Sphere.getLength(line) + parseFloat($('#missionDistance').text()); @@ -939,26 +948,26 @@ TABS.mission_control.initialize = function (callback) { map.addLayer(vectorLayer); } - - function cleanLayers() { + + function cleanLayers() { for (var i in lines) { map.removeLayer(lines[i]); } lines = []; - + for (var i in markers) { map.removeLayer(markers[i]); } markers = []; } - - function cleanLines() { + + function cleanLines() { for (var i in lines) { map.removeLayer(lines[i]); } lines = []; } - + function redrawLayers() { if (!mission.isEmpty()) { mission.get().forEach(function (element) { @@ -969,15 +978,15 @@ TABS.mission_control.initialize = function (callback) { } repaintLine4Waypoints(mission); } - + function redrawLayer() { if (selectedFeature && selectedMarker) { selectedFeature.setStyle(getWaypointIcon(selectedMarker, true)); } repaintLine4Waypoints(mission); } - - + + function renderWaypointOptionsTable(waypoint) { /* * Process Waypoint Options table UI @@ -998,7 +1007,7 @@ TABS.mission_control.initialize = function (callback) { '); const $row = $waypointOptionsTableBody.find('tr:last'); - + for (var i = 1; i <= 3; i++) { if (dictOfLabelParameterPoint[element.getAction()]['parameter'+String(i)] != '') { $row.find(".waypointOptions-p"+String(i)).prop("disabled", false); @@ -1007,9 +1016,9 @@ TABS.mission_control.initialize = function (callback) { $row.find(".waypointOptions-p"+String(i)).prop("disabled", true); } } - + GUI.fillSelect($row.find(".waypointOptions-action"), waypointOptions, waypointOptions.indexOf(MWNP.WPTYPE.REV[element.getAction()])); - + $row.find(".waypointOptions-action").val(waypointOptions.indexOf(MWNP.WPTYPE.REV[element.getAction()])).change(function () { element.setAction(MWNP.WPTYPE[waypointOptions[$(this).val()]]); for (var i = 1; i <= 3; i++) { @@ -1024,7 +1033,7 @@ TABS.mission_control.initialize = function (callback) { cleanLines(); redrawLayer(); }); - + $row.find(".waypointOptions-number").text(element.getAttachedNumber()+1); @@ -1061,7 +1070,7 @@ TABS.mission_control.initialize = function (callback) { cleanLines(); redrawLayer(); }); - + $row.find(".waypointOptions-p2").val(element.getP2()).change(function () { if (MWNP.WPTYPE.REV[element.getAction()] == "JUMP") { if ($(this).val() > 10 || ($(this).val() < 0 && $(this).val() != -1)) @@ -1077,13 +1086,13 @@ TABS.mission_control.initialize = function (callback) { }); $row.find("[data-role='waypointOptions-delete']").attr("data-index", element.getAttachedNumber()+1); - + }); GUI.switchery(); localize(); return waypoint; } - + ///////////////////////////////////////////// // // Manage Map construction @@ -1091,10 +1100,10 @@ TABS.mission_control.initialize = function (callback) { ///////////////////////////////////////////// function initMap() { var app = {}; - + ////////////////////////////////////////////////////////////////////////////////////////////// // Drag behavior definition - ////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////// /** * @constructor @@ -1171,8 +1180,8 @@ TABS.mission_control.initialize = function (callback) { }; ol.inherits(app.PlannerSettingsControl, ol.control.Control); - - + + /** * @constructor * @extends {ol.control.Control} @@ -1211,7 +1220,7 @@ TABS.mission_control.initialize = function (callback) { }; ol.inherits(app.PlannerSafehomeControl, ol.control.Control); - + /** * @constructor * @extends {ol.control.Control} @@ -1248,7 +1257,7 @@ TABS.mission_control.initialize = function (callback) { }; ol.inherits(app.PlannerElevationControl, ol.control.Control); - + /** * @param {ol.MapBrowserEvent} evt Map browser event. * @return {boolean} `true` to start the drag sequence. @@ -1293,7 +1302,7 @@ TABS.mission_control.initialize = function (callback) { 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]; + this.coordinate_[1] = evt.coordinate[1]; } let coord = ol.proj.toLonLat(geometry.getCoordinates()); @@ -1301,12 +1310,14 @@ TABS.mission_control.initialize = function (callback) { let tempWp = mission.getWaypoint(tempMarker.number); tempWp.setLon(Math.round(coord[0] * 10000000)); tempWp.setLat(Math.round(coord[1] * 10000000)); - $('#pointLon').val(Math.round(coord[0] * 10000000) / 10000000); - $('#pointLat').val(Math.round(coord[1] * 10000000) / 10000000); + if (selectedMarker != null && tempMarker.number == selectedMarker.getLayerNumber()) { + $('#pointLon').val(Math.round(coord[0] * 10000000) / 10000000); + $('#pointLat').val(Math.round(coord[1] * 10000000) / 10000000); + } mission.updateWaypoint(tempWp); repaintLine4Waypoints(mission); } - else if (tempMarker.kind == "safehome") { + else if (tempMarker.kind == "safehome") { let tempSH = SAFEHOMES.getSafehome(tempMarker.number); tempSH.setLon(Math.round(coord[0] * 10000000)); tempSH.setLat(Math.round(coord[1] * 10000000)); @@ -1314,13 +1325,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 (tempMarker.kind == "home") { + 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); } - + }; /** @@ -1351,14 +1362,16 @@ TABS.mission_control.initialize = function (callback) { * @return {boolean} `false` to stop the drag sequence. */ app.Drag.prototype.handleUpEvent = function (evt) { - if (tempMarker.kind == "waypoint" ){ + if ( tempMarker.kind == "waypoint" ) { + if (selectedMarker != null && tempMarker.number == selectedMarker.getLayerNumber()) { (async () => { - if (mission.getWaypoint(tempMarker.number).getP3() == 1.0) { - const elevationAtWP = await mission.getWaypoint(tempMarker.number).getElevation(globalSettings); - $('#elevationValueAtWP').text(elevationAtWP); - } + const elevationAtWP = await mission.getWaypoint(tempMarker.number).getElevation(globalSettings); + $('#elevationValueAtWP').text(elevationAtWP); + const returnAltitude = checkAltElevSanity(false, mission.getWaypoint(tempMarker.number).getAlt(), elevationAtWP, mission.getWaypoint(tempMarker.number).getP3()); + mission.getWaypoint(tempMarker.number).setAlt(returnAltitude); plotElevation(); })() + } } else if (tempMarker.kind == "home" ) { (async () => { @@ -1392,7 +1405,7 @@ TABS.mission_control.initialize = function (callback) { } else { mapLayer = new ol.source.OSM(); } - + if (CONFIGURATOR.connectionValid) { control_list = [ new app.PlannerSettingsControl(), @@ -1410,7 +1423,7 @@ TABS.mission_control.initialize = function (callback) { ////////////////////////////////////////////////////////////////////////////////////////////// // Map object definition - ////////////////////////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////////////////////////// map = new ol.Map({ controls: ol.control.defaults({ attributionOptions: { @@ -1456,10 +1469,12 @@ TABS.mission_control.initialize = function (callback) { } }); ////////////////////////////////////////////////////////////////////////// - // Map on-click behavior definition + // Map on-click behavior definition ////////////////////////////////////////////////////////////////////////// map.on('click', function (evt) { + var tempSelectedMarkerIndex = null; if (selectedMarker != null && selectedFeature != null) { + tempSelectedMarkerIndex = selectedMarker.getLayerNumber(); try { selectedFeature.setStyle(getWaypointIcon(selectedMarker, false)); selectedMarker = null; @@ -1488,6 +1503,23 @@ TABS.mission_control.initialize = function (callback) { var altitudeMeters = app.ConvertCentimetersToMeters(selectedMarker.getAlt()); + if (globalSettings.mapProviderType == 'bing') { + $('#elevationAtWP').fadeIn(); + $('#groundClearanceAtWP').fadeIn(); + if (tempSelectedMarkerIndex == null || tempSelectedMarkerIndex != selectedMarker.getLayerNumber()) { + (async () => { + const elevationAtWP = await selectedMarker.getElevation(globalSettings); + $('#elevationValueAtWP').text(elevationAtWP); + const returnAltitude = checkAltElevSanity(false, selectedMarker.getAlt(), elevationAtWP, selectedMarker.getP3()); + selectedMarker.setAlt(returnAltitude); + plotElevation(); + })() + } + } else { + $('#elevationAtWP').fadeOut(); + $('#groundClearanceAtWP').fadeOut(); + } + $('#altitudeInMeters').text(` ${altitudeMeters}m`); $('#pointLon').val(Math.round(coord[0] * 10000000) / 10000000); $('#pointLat').val(Math.round(coord[1] * 10000000) / 10000000); @@ -1497,8 +1529,8 @@ TABS.mission_control.initialize = function (callback) { $('#pointP1').val(selectedMarker.getP1()); $('#pointP2').val(selectedMarker.getP2()); changeSwitchery($('#pointP3'), selectedMarker.getP3() == 1); - - + + // Selection box update depending on choice of type of waypoint for (var j in dictOfLabelParameterPoint[selectedMarker.getAction()]) { if (dictOfLabelParameterPoint[selectedMarker.getAction()][j] != '') { @@ -1515,10 +1547,24 @@ TABS.mission_control.initialize = function (callback) { else if (selectedFeature && tempMarker.kind == "line" && tempMarker.selection) { let tempWpCoord = ol.proj.toLonLat(evt.coordinate); let tempWp = new Waypoint(tempMarker.number, MWNP.WPTYPE.WAYPOINT, Math.round(tempWpCoord[1] * 10000000), Math.round(tempWpCoord[0] * 10000000), alt=Number(settings.alt), p1=Number(settings.speed)); - mission.insertWaypoint(tempWp, tempMarker.number); - mission.update(); - cleanLayers(); - redrawLayers(); + if (homeMarkers.length && HOME.getAlt() != "N/A") { + (async () => { + const elevationAtWP = await tempWp.getElevation(globalSettings); + tempWp.setAlt(checkAltElevSanity(false, settings.alt, elevationAtWP, 0)); + + mission.insertWaypoint(tempWp, tempMarker.number); + mission.update(); + cleanLayers(); + redrawLayers(); + plotElevation(); + })() + } else { + mission.insertWaypoint(tempWp, tempMarker.number); + mission.update(); + cleanLayers(); + redrawLayers(); + plotElevation(); + } } else if (selectedFeature && tempMarker.kind == "safehome" && tempMarker.selection) { selectedMarker = SAFEHOMES.getSafehome(tempMarker.number); @@ -1538,11 +1584,24 @@ TABS.mission_control.initialize = function (callback) { 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)); - mission.put(tempWp); - mission.update(); - cleanLayers(); - redrawLayers(); - plotElevation(); + if (homeMarkers.length && HOME.getAlt() != "N/A") { + (async () => { + const elevationAtWP = await tempWp.getElevation(globalSettings); + tempWp.setAlt(checkAltElevSanity(false, settings.alt, elevationAtWP, 0)); + + mission.put(tempWp); + mission.update(); + cleanLayers(); + redrawLayers(); + plotElevation(); + })() + } else { + mission.put(tempWp); + mission.update(); + cleanLayers(); + redrawLayers(); + plotElevation(); + } } //mission.missionDisplayDebug(); }); @@ -1578,7 +1637,7 @@ TABS.mission_control.initialize = function (callback) { let altitudeMeters = app.ConvertCentimetersToMeters($(this).val()); $('#altitudeInMeters').text(` ${altitudeMeters}m`); }); - + ///////////////////////////////////////////// // Callback to show/hide menu boxes ///////////////////////////////////////////// @@ -1594,7 +1653,7 @@ TABS.mission_control.initialize = function (callback) { $('#ActionContent').fadeOut(300); } }); - + $('#showHideInfoButton').on('click', function () { var src = ($(this).children().attr('class') === 'ic_hide') ? 'ic_show' @@ -1607,7 +1666,7 @@ TABS.mission_control.initialize = function (callback) { $('#InfoContent').fadeOut(300); } }); - + $('#showHideSafehomeButton').on('click', function () { var src = ($(this).children().attr('class') === 'ic_hide') ? 'ic_show' @@ -1620,7 +1679,7 @@ TABS.mission_control.initialize = function (callback) { $('#SafehomeContent').fadeOut(300); } }); - + $('#showHideHomeButton').on('click', function () { var src = ($(this).children().attr('class') === 'ic_hide') ? 'ic_show' @@ -1633,7 +1692,7 @@ TABS.mission_control.initialize = function (callback) { $('#HomeContent').fadeOut(300); } }); - + $('#showHideWPeditButton').on('click', function () { var src = ($(this).children().attr('class') === 'ic_hide') ? 'ic_show' @@ -1646,7 +1705,7 @@ TABS.mission_control.initialize = function (callback) { $('#WPeditContent').fadeOut(300); } }); - + ///////////////////////////////////////////// // Callback for Waypoint edition ///////////////////////////////////////////// @@ -1656,7 +1715,6 @@ TABS.mission_control.initialize = function (callback) { if ([MWNP.WPTYPE.SET_POI,MWNP.WPTYPE.POSHOLD_TIME,MWNP.WPTYPE.LAND].includes(selectedMarker.getAction())) { selectedMarker.setP1(0.0); selectedMarker.setP2(0.0); - selectedMarker.setP3(0.0); } for (var j in dictOfLabelParameterPoint[selectedMarker.getAction()]) { if (dictOfLabelParameterPoint[selectedMarker.getAction()][j] != '') { @@ -1670,7 +1728,7 @@ TABS.mission_control.initialize = function (callback) { redrawLayer(); } }); - + $('#pointLat').on('change', function (event) { if (selectedMarker) { selectedMarker.setLat(Math.round(Number($('#pointLat').val()) * 10000000)); @@ -1683,7 +1741,7 @@ TABS.mission_control.initialize = function (callback) { plotElevation(); } }); - + $('#pointLon').on('change', function (event) { if (selectedMarker) { selectedMarker.setLon(Math.round(Number($('#pointLon').val()) * 10000000)); @@ -1696,17 +1754,19 @@ TABS.mission_control.initialize = function (callback) { plotElevation(); } }); - + $('#pointAlt').on('change', function (event) { if (selectedMarker) { - selectedMarker.setAlt(Number($('#pointAlt').val())); + const elevationAtWP = Number($('#elevationValueAtWP').text()); + const returnAltitude = checkAltElevSanity(true, Number($('#pointAlt').val()), elevationAtWP, selectedMarker.getP3()); + selectedMarker.setAlt(returnAltitude); mission.updateWaypoint(selectedMarker); mission.update(); redrawLayer(); plotElevation(); } }); - + $('#pointP1').on('change', function (event) { if (selectedMarker) { selectedMarker.setP1(Number($('#pointP1').val())); @@ -1715,7 +1775,7 @@ TABS.mission_control.initialize = function (callback) { redrawLayer(); } }); - + $('#pointP2').on('change', function (event) { if (selectedMarker) { selectedMarker.setP2(Number($('#pointP2').val())); @@ -1724,28 +1784,41 @@ TABS.mission_control.initialize = function (callback) { redrawLayer(); } }); - + $('#pointP3').on('change', function (event) { if (selectedMarker) { + const P3Value = selectedMarker.getP3(); selectedMarker.setP3( $('#pointP3').prop("checked") ? 1.0 : 0.0); - if ($('#pointP3').prop("checked")) { + if (globalSettings.mapProviderType == 'bing') { (async () => { const elevationAtWP = await selectedMarker.getElevation(globalSettings); $('#elevationValueAtWP').text(elevationAtWP); - $('#elevationAtWP').fadeIn(300); + var altitude = Number($('#pointAlt').val()); + if (P3Value != selectedMarker.getP3()) { + if ($('#pointP3').prop("checked")) { + if (altitude < 0) { + altitude = settings.alt; + } + selectedMarker.setAlt(altitude + elevationAtWP * 100); + } else { + selectedMarker.setAlt(altitude - Number(elevationAtWP) * 100); + } + } + const returnAltitude = checkAltElevSanity(false, selectedMarker.getAlt(), elevationAtWP, selectedMarker.getP3()); + selectedMarker.setAlt(returnAltitude); + $('#pointAlt').val(selectedMarker.getAlt()); + altitudeMeters = app.ConvertCentimetersToMeters(selectedMarker.getAlt()); + $('#altitudeInMeters').text(` ${altitudeMeters}m`); + + mission.updateWaypoint(selectedMarker); + mission.update(); + redrawLayer(); + plotElevation(); })() - } - else { - $('#elevationAtWP').fadeOut(300); - } - mission.updateWaypoint(selectedMarker); - mission.update(); - redrawLayer(); - plotElevation(); } }); - + ///////////////////////////////////////////// // Callback for Waypoint Options Table ///////////////////////////////////////////// @@ -1760,7 +1833,7 @@ TABS.mission_control.initialize = function (callback) { selectedFeature.setStyle(getWaypointIcon(selectedMarker, true)); } }); - + $("[data-role='waypointOptions-add']").click(function () { if (selectedMarker) { mission.addAttachedFromWaypoint(selectedMarker); @@ -1772,7 +1845,7 @@ TABS.mission_control.initialize = function (callback) { selectedFeature.setStyle(getWaypointIcon(selectedMarker, true)); } }); - + ///////////////////////////////////////////// // Callback for SAFEHOMES Table ///////////////////////////////////////////// @@ -1784,13 +1857,13 @@ TABS.mission_control.initialize = function (callback) { SAFEHOMES.updateSafehome(tmpSH); renderSafehomesTable(); cleanSafehomeLayers(); - renderSafehomesOnMap(); + renderSafehomesOnMap(); }); - + $('#cancelSafehome').on('click', function () { closeSafehomePanel(); }); - + $('#loadEepromSafehomeButton').on('click', function () { $(this).addClass('disabled'); GUI.log('Start of getting Safehome points'); @@ -1802,9 +1875,9 @@ TABS.mission_control.initialize = function (callback) { GUI.log('End of getting Safehome points'); $('#loadEepromSafehomeButton').removeClass('disabled'); }, 500); - + }); - + $('#saveEepromSafehomeButton').on('click', function () { $(this).addClass('disabled'); GUI.log('Start of sending Safehome points'); @@ -1815,7 +1888,7 @@ TABS.mission_control.initialize = function (callback) { $('#saveEepromSafehomeButton').removeClass('disabled'); }, 500); }); - + ///////////////////////////////////////////// // Callback for HOME Table ///////////////////////////////////////////// @@ -1825,15 +1898,37 @@ TABS.mission_control.initialize = function (callback) { HOME.setLat(Math.round(ol.proj.toLonLat(mapCenter)[1] * 1e7)); updateHome(); }); - + $('#cancelHome').on('click', function () { closeHomePanel(); }); - + $('#cancelPlot').on('click', function () { closeHomePanel(); }); - + + $('#elevationEarthModel').on('change', function (event) { + if (globalSettings.mapProviderType == 'bing') { + (async () => { + const elevationAtHome = await HOME.getElevation(globalSettings); + $('#elevationValueAtHome').text(elevationAtHome+' m'); + HOME.setAlt(elevationAtHome); + + if (selectedMarker) { + const elevationAtWP = await selectedMarker.getElevation(globalSettings); + $('#elevationValueAtWP').text(elevationAtWP); + const returnAltitude = checkAltElevSanity(false, selectedMarker.getAlt(), elevationAtWP, selectedMarker.getP3()); + selectedMarker.setAlt(returnAltitude); + mission.updateWaypoint(selectedMarker); + } + + mission.update(); + redrawLayer(); + plotElevation(); + })() + } + }); + ///////////////////////////////////////////// // Callback for Remove buttons ///////////////////////////////////////////// @@ -1875,11 +1970,11 @@ TABS.mission_control.initialize = function (callback) { } } }); - - + + ///////////////////////////////////////////// // Callback for Save/load buttons - ///////////////////////////////////////////// + ///////////////////////////////////////////// $('#loadFileMissionButton').on('click', function () { if (markers.length && !confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) return; removeAllWaypoints(); @@ -1912,26 +2007,19 @@ TABS.mission_control.initialize = function (callback) { sendWaypointsToFC(); GUI.log('End send point'); $('#saveMissionButton').removeClass('disabled'); - + }); $('#loadEepromMissionButton').on('click', function () { if (markers.length && !confirm(chrome.i18n.getMessage('confirm_delete_all_points'))) return; removeAllWaypoints(); - GUI.log(chrome.i18n.getMessage('eeprom_load_ok')); MSP.send_message(MSPCodes.MSP_WP_MISSION_LOAD, [0], getWaypointsFromFC); }); - + $('#saveEepromMissionButton').on('click', function () { $(this).addClass('disabled'); GUI.log('Start send point'); sendWaypointsToFC(); - GUI.log('End send point'); - $('#saveEepromMissionButton').removeClass('disabled'); - GUI.log(chrome.i18n.getMessage('eeprom_saved_ok')); - setTimeout(function(){ - MSP.send_message(MSPCodes.MSP_WP_MISSION_SAVE, [0], false); - },2000); }); ///////////////////////////////////////////// @@ -1943,7 +2031,7 @@ TABS.mission_control.initialize = function (callback) { saveSettings(); if (settings.safeRadiusSH != oldSafeRadiusSH && $('#showHideSafehomeButton').is(":visible")) { cleanSafehomeLayers(); - renderSafehomesOnMap(); + renderSafehomesOnMap(); $('#SafeHomeSafeDistance').text(settings.safeRadiusSH); } closeSettingsPanel(); @@ -1953,7 +2041,7 @@ TABS.mission_control.initialize = function (callback) { loadSettings(); closeSettingsPanel(); }); - + updateTotalInfo(); @@ -2075,9 +2163,11 @@ TABS.mission_control.initialize = function (callback) { map.getView().setCenter(coord); map.getView().setZoom(16); } - + redrawLayers(); - updateHome(); + if (!(HOME.getLatMap() == 0 && HOME.getLonMap() == 0)) { + updateHome(); + } updateTotalInfo(); let sFilename = String(filename.split('\\').pop().split('/').pop()); GUI.log(sFilename+' has been loaded successfully !'); @@ -2095,14 +2185,14 @@ TABS.mission_control.initialize = function (callback) { var data = { 'version': { $: { 'value': '2.3-pre8' } }, - 'mwp': { $: { 'cx': (Math.round(center[0] * 10000000) / 10000000), - 'cy': (Math.round(center[1] * 10000000) / 10000000), + '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': [] }; - + mission.get().forEach(function (waypoint) { var point = { $: { 'no': waypoint.getNumber()+1, @@ -2116,7 +2206,7 @@ TABS.mission_control.initialize = function (callback) { } }; data.missionitem.push(point); }); - + var builder = new window.xml2js.Builder({ 'rootName': 'mission', 'renderOpts': { 'pretty': true, 'indent': '\t', 'newline': '\n' } }); var xml = builder.buildObject(data); fs.writeFile(filename, xml, (err) => { @@ -2136,8 +2226,8 @@ TABS.mission_control.initialize = function (callback) { // ///////////////////////////////////////////// function getWaypointsFromFC() { - mspHelper.loadWaypoints(); - setTimeout(function(){ + mspHelper.loadWaypoints(function() { + GUI.log(chrome.i18n.getMessage('eeprom_load_ok')); mission.reinit(); mission.copy(MISSION_PLANER); mission.update(true); @@ -2146,15 +2236,19 @@ TABS.mission_control.initialize = function (callback) { map.getView().setZoom(16); redrawLayers(); updateTotalInfo(); - }, 2000); + }); } - + function sendWaypointsToFC() { MISSION_PLANER.reinit(); MISSION_PLANER.copy(mission); MISSION_PLANER.update(true, true); - mspHelper.saveWaypoints(); - setTimeout(function(){ + mspHelper.saveWaypoints(function() { + GUI.log('End send point'); + $('#saveEepromMissionButton').removeClass('disabled'); + GUI.log(chrome.i18n.getMessage('eeprom_saved_ok')); + MSP.send_message(MSPCodes.MSP_WP_MISSION_SAVE, [0], false); + mission.setMaxWaypoints(MISSION_PLANER.getMaxWaypoints()); mission.setValidMission(MISSION_PLANER.getValidMission()); mission.setCountBusyPoints(MISSION_PLANER.getCountBusyPoints()); @@ -2165,30 +2259,70 @@ TABS.mission_control.initialize = function (callback) { cleanLayers(); redrawLayers(); $('#MPeditPoint').fadeOut(300); - }, 2000); + }); } - + function updateTotalInfo() { if (CONFIGURATOR.connectionValid) { $('#availablePoints').text(mission.getCountBusyPoints() + '/' + mission.getMaxWaypoints()); $('#missionValid').html(mission.getValidMission() ? chrome.i18n.getMessage('armingCheckPass') : chrome.i18n.getMessage('armingCheckFail')); } - } - + } + function updateFilename(filename) { $('#missionFilename').text(filename); $('#infoMissionFilename').show(); } - + function changeSwitchery(element, checked) { if ( ( element.is(':checked') && checked == false ) || ( !element.is(':checked') && checked == true ) ) { element.parent().find('.switcherymid').trigger('click'); } } - + + /* resetAltitude = true : For selected WPs only. Changes WP Altitude value back to previous value if setting below ground level. + ^ resetAltitude = false : changes WP Altitude to value required to give ground clearance = default Altitude setting */ + function checkAltElevSanity(resetAltitude, checkAltitude, elevation, P3Datum) { + if (globalSettings.mapProviderType != 'bing') { + return checkAltitude; + } + + let groundClearance = "NO HOME"; + let altitude = checkAltitude; + if (P3Datum) { + if (checkAltitude < 100 * elevation) { + if (resetAltitude) { + alert(chrome.i18n.getMessage('MissionPlannerAltitudeChangeReset')); + altitude = selectedMarker.getAlt(); + } else { + altitude = settings.alt + 100 * elevation; + } + } + groundClearance = altitude / 100 - elevation; + } else if (homeMarkers.length && HOME.getAlt() != "N/A") { + let elevationAtHome = HOME.getAlt(); + if ((checkAltitude / 100 + elevationAtHome) < elevation) { + if (resetAltitude) { + alert(chrome.i18n.getMessage('MissionPlannerAltitudeChangeReset')); + altitude = selectedMarker.getAlt(); + } else { + altitude = settings.alt + 100 * (elevation - elevationAtHome); + } + } + groundClearance = altitude / 100 + (elevationAtHome - elevation); + } + $('#pointAlt').val(altitude); + let altitudeMeters = parseInt(altitude) / 100; + $('#altitudeInMeters').text(` ${altitudeMeters}m`); + document.getElementById('groundClearanceAtWP').style.color = groundClearance < (settings.alt / 100) ? "#FF0000" : "#303030"; + $('#groundClearanceValueAtWP').text(` ${groundClearance}`); + + return altitude; + } + function plotElevation() { if ($('#missionPlanerElevation').is(":visible")) { if (mission.get().length == 0) { diff --git a/tabs/osd.js b/tabs/osd.js index 77843b51..750eb91b 100644 --- a/tabs/osd.js +++ b/tabs/osd.js @@ -2724,11 +2724,18 @@ OSD.GUI.updatePreviews = function() { // consume drag/drop events. $img.find('img').css('pointer-events', 'none'); if (item && item.positionable !== false) { + var nameKey = 'osdElement_' + item.name; + var nameMessage = chrome.i18n.getMessage(nameKey); + + if (!nameMessage) { + nameMessage = inflection.titleize(item.name); + } + $img.addClass('field-' + item.id) .data('item', item) .prop('draggable', true) .on('dragstart', OSD.GUI.preview.onDragStart) - .prop('title', inflection.titleize(item.name)); + .prop('title', nameMessage); } $row.append($img);