Simplify settings down to just Metric / ShowOtherUnit.

Factor out some common code.
This commit is contained in:
Oliver Jowett 2015-02-22 01:22:05 +00:00
parent 082e973990
commit 5c1cf53316
3 changed files with 65 additions and 68 deletions

View file

@ -7,13 +7,13 @@
// -- Output Settings ------------------------------------- // -- Output Settings -------------------------------------
// Show metric values // Show metric values
// This controls the units used in the plane table, // The Metric setting controls whether metric (m, km, km/h) or
// You can choose to enable Metric or Imperial or both. // imperial (ft, NM, knots) units are used in the plane table
// If you enable both, by setting PreferMetric to either true or false, // and in the detailed plane info. If ShowOtherUnits is true,
// you control which unit is displayed first. // then the other unit will also be shown in the detailed plane
PreferMetric = true; // info.
EnableMetric = true; Metric = false;
EnableImperial = false; ShowOtherUnits = true;
// -- Map settings ---------------------------------------- // -- Map settings ----------------------------------------
// These settings are overridden by any position information // These settings are overridden by any position information

View file

@ -1,4 +1,8 @@
// -*- mode: javascript; indent-tabs-mode: t; c-basic-offset: 8 -*-
"use strict";
var TrackDirections = ["North","Northeast","East","Southeast","South","Southwest","West","Northwest"]; var TrackDirections = ["North","Northeast","East","Southeast","South","Southwest","West","Northwest"];
// formatting helpers // formatting helpers
// track in degrees (0..359) // track in degrees (0..359)
@ -25,19 +29,13 @@ function format_track_long(track) {
function format_altitude_brief(alt, vr) { function format_altitude_brief(alt, vr) {
var alt_text; var alt_text;
// 4 cases possible:
// 1: EnableMetric = true | EnableImperial = false | PreferMetric = (Dont Care) -> display metric
// 2: EnableMetric = false | EnableImperial = true | PreferMetric = (Dont Care) -> display imperial
// 3: EnableMetric = true | EnableImperial = true | PreferMetric = true -> display metric
// 4: EnableMetric = true | EnableImperial = true | PreferMetric = false -> display imperial
if (alt === null){ if (alt === null){
return ""; return "";
} else if (alt === "ground"){ } else if (alt === "ground"){
return "ground"; return "ground";
} }
if ((EnableMetric && !EnableImperial) || (PreferMetric && EnableMetric && EnableImperial)){ if (Metric) {
alt_text = Math.round(alt / 3.2828) + NBSP; // Altitude to meters alt_text = Math.round(alt / 3.2828) + NBSP; // Altitude to meters
} else { } else {
alt_text = Math.round(alt) + NBSP; alt_text = Math.round(alt) + NBSP;
@ -54,6 +52,13 @@ function format_altitude_brief(alt, vr) {
} }
// alt in ft // alt in ft
function _alt_to_unit(alt, m) {
if (m)
return Math.round(alt / 3.2828) + NBSP + "m";
else
return Math.round(alt) + NBSP + "ft";
}
function format_altitude_long(alt, vr) { function format_altitude_long(alt, vr) {
var alt_text = ""; var alt_text = "";
@ -63,21 +68,12 @@ function format_altitude_long(alt, vr) {
return "on ground"; return "on ground";
} }
// If we only want to see one of the two types // Primary unit
if((EnableMetric && !EnableImperial) || (!EnableMetric && EnableImperial)){ alt_text = _alt_to_unit(alt, Metric);
if(EnableMetric){
alt_text = Math.round(alt / 3.2828) + " m"; // Secondary unit
} if (ShowOtherUnits) {
else{ alt_text = alt_text + ' | ' + _alt_to_unit(alt, !Metric);
alt_text = Math.round(alt) + " ft";
}
}
else{ // we want to see both, check PreferMetric for what order
if (PreferMetric) {
alt_text = Math.round(alt / 3.2828) + " m | " + Math.round(alt) + " ft";
} else {
alt_text = Math.round(alt) + " ft | " + Math.round(alt / 3.2828) + " m";
}
} }
if (vr > 128) { if (vr > 128) {
@ -95,7 +91,7 @@ function format_speed_brief(speed) {
return ""; return "";
} }
if ((EnableMetric && !EnableImperial) || (PreferMetric && EnableMetric && EnableImperial)){ if (Metric) {
return Math.round(speed * 1.852); // knots to kilometers per hour return Math.round(speed * 1.852); // knots to kilometers per hour
} else { } else {
return Math.round(speed); // knots return Math.round(speed); // knots
@ -103,28 +99,28 @@ function format_speed_brief(speed) {
} }
// speed in kts // speed in kts
function _speed_to_unit(speed, m) {
if (m)
return Math.round(speed * 1.852) + NBSP + "km/h";
else
return Math.round(speed) + NBSP + "kt";
}
function format_speed_long(speed) { function format_speed_long(speed) {
if (speed === null) { if (speed === null) {
return "n/a"; return "n/a";
} }
// If we only want to see one of the two types // Primary unit
if((EnableMetric && !EnableImperial) || (!EnableMetric && EnableImperial)){ var speed_text = _speed_to_unit(speed, Metric);
if(EnableMetric){
return Math.round(speed * 1.852) + " km/h"; // Secondary unit
} if (ShowOtherUnits) {
else{ speed_text = speed_text + ' | ' + _speed_to_unit(speed, !Metric);
return Math.round(speed) + " kt";
}
}
else{ // we want to see both, check PreferMetric for what order
if (PreferMetric) {
return Math.round(speed * 1.852) + " km/h | " + Math.round(speed) + " kt";
} else {
return Math.round(speed) + " kt | " + Math.round(speed * 1.852) + " km/h";
}
} }
return speed_text;
} }
// dist in meters // dist in meters
@ -133,7 +129,7 @@ function format_distance_brief(dist) {
return ""; return "";
} }
if ((EnableMetric && !EnableImperial) || (PreferMetric && EnableMetric && EnableImperial)){ if (Metric) {
return (dist/1000).toFixed(1); // meters to kilometers return (dist/1000).toFixed(1); // meters to kilometers
} else { } else {
return (dist/1852).toFixed(1); // meters to nautocal miles return (dist/1852).toFixed(1); // meters to nautocal miles
@ -141,27 +137,28 @@ function format_distance_brief(dist) {
} }
// dist in metres // dist in metres
function _dist_to_unit(dist, m) {
if (m)
return (dist/1000).toFixed(1) + NBSP + "km";
else
return (dist/1852).toFixed(1) + NBSP + "NM";
}
function format_distance_long(dist) { function format_distance_long(dist) {
if (dist === null) { if (dist === null) {
return "n/a"; return "n/a";
} }
// If we only want to see one of the two types // Primary unit
if((EnableMetric && !EnableImperial) || (!EnableMetric && EnableImperial)){ var dist_text = _dist_to_unit(dist, Metric);
if(EnableMetric){
return (dist/1000).toFixed(1) + " km"; // Secondary unit
} if (ShowOtherUnits) {
else{ dist_text = dist_text + ' | ' + _dist_to_unit(dist, !Metric);
return (dist/1852).toFixed(1) + " NM";
}
}
else{ // we want to see both, check PreferMetric for what order
if (PreferMetric) {
return (dist/1000).toFixed(1) + " km | " + (dist/1852).toFixed(1) + " NM";
} else {
return (dist/1852).toFixed(1) + " NM | " + (dist/1000).toFixed(1) + " km";
}
} }
return dist_text;
} }
// p as a LatLng // p as a LatLng

View file

@ -786,7 +786,7 @@ function drawCircle(marker, distance) {
} }
distance *= 1000.0; distance *= 1000.0;
if (!EnableMetric) { if (!Metric) {
distance *= 1.852; distance *= 1.852;
} }