diff --git a/public_html/config.js b/public_html/config.js index 81909e4..ceddc70 100644 --- a/public_html/config.js +++ b/public_html/config.js @@ -7,10 +7,13 @@ // -- Output Settings ------------------------------------- // Show metric values -// This controls the units used in the plane table, -// and whether metric or imperial units are shown first -// in the detailed plane info. -Metric = false; // true or false +// The Metric setting controls whether metric (m, km, km/h) or +// imperial (ft, NM, knots) units are used in the plane table +// and in the detailed plane info. If ShowOtherUnits is true, +// then the other unit will also be shown in the detailed plane +// info. +Metric = false; +ShowOtherUnits = true; // -- Map settings ---------------------------------------- // These settings are overridden by any position information diff --git a/public_html/formatter.js b/public_html/formatter.js new file mode 100644 index 0000000..19c54e1 --- /dev/null +++ b/public_html/formatter.js @@ -0,0 +1,167 @@ +// -*- mode: javascript; indent-tabs-mode: t; c-basic-offset: 8 -*- +"use strict"; + +var TrackDirections = ["North","Northeast","East","Southeast","South","Southwest","West","Northwest"]; + +// formatting helpers + +// track in degrees (0..359) +function format_track_brief(track) { + if (track === null){ + return ""; + } + + return Math.round(track); +} + +// track in degrees (0..359) +function format_track_long(track) { + if (track === null){ + return "n/a"; + } + + var trackDir = Math.floor((360 + track % 360 + 22.5) / 45) % 8; + return Math.round(track) + DEGREES + NBSP + "(" + TrackDirections[trackDir] + ")"; +} + +// altitude (input: alt in feet) +// brief will always show either Metric or Imperial +function format_altitude_brief(alt, vr) { + var alt_text; + + if (alt === null){ + return ""; + } else if (alt === "ground"){ + return "ground"; + } + + if (Metric) { + alt_text = Math.round(alt / 3.2828) + NBSP; // Altitude to meters + } else { + alt_text = Math.round(alt) + NBSP; + } + + // Vertical Rate Triangle + if (vr > 128){ + return alt_text + UP_TRIANGLE; + } else if (vr < -128){ + return alt_text + DOWN_TRIANGLE; + } else { + return alt_text + NBSP; + } +} + +// 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) { + var alt_text = ""; + + if (alt === null) { + return "n/a"; + } else if (alt === "ground") { + return "on ground"; + } + + // Primary unit + alt_text = _alt_to_unit(alt, Metric); + + // Secondary unit + if (ShowOtherUnits) { + alt_text = alt_text + ' | ' + _alt_to_unit(alt, !Metric); + } + + if (vr > 128) { + return UP_TRIANGLE + NBSP + alt_text; + } else if (vr < -128) { + return DOWN_TRIANGLE + NBSP + alt_text; + } else { + return alt_text; + } +} + +//input: speed in kts +function format_speed_brief(speed) { + if (speed === null) { + return ""; + } + + if (Metric) { + return Math.round(speed * 1.852); // knots to kilometers per hour + } else { + return Math.round(speed); // knots + } +} + +// 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) { + if (speed === null) { + return "n/a"; + } + + // Primary unit + var speed_text = _speed_to_unit(speed, Metric); + + // Secondary unit + if (ShowOtherUnits) { + speed_text = speed_text + ' | ' + _speed_to_unit(speed, !Metric); + } + + return speed_text; +} + +// dist in meters +function format_distance_brief(dist) { + if (dist === null) { + return ""; + } + + if (Metric) { + return (dist/1000).toFixed(1); // meters to kilometers + } else { + return (dist/1852).toFixed(1); // meters to nautocal miles + } +} + +// 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) { + if (dist === null) { + return "n/a"; + } + + // Primary unit + var dist_text = _dist_to_unit(dist, Metric); + + // Secondary unit + if (ShowOtherUnits) { + dist_text = dist_text + ' | ' + _dist_to_unit(dist, !Metric); + } + + return dist_text; +} + +// p as a LatLng +function format_latlng(p) { + return p.lat().toFixed(3) + DEGREES + "," + NBSP + p.lng().toFixed(3) + DEGREES; +} diff --git a/public_html/gmap.html b/public_html/gmap.html index a2f0ff2..e3ec31f 100644 --- a/public_html/gmap.html +++ b/public_html/gmap.html @@ -8,6 +8,7 @@ + diff --git a/public_html/script.js b/public_html/script.js index 7d6e160..8f787de 100644 --- a/public_html/script.js +++ b/public_html/script.js @@ -486,118 +486,6 @@ function reaper() { PlanesOrdered = newPlanes; refreshTableInfo(); refreshSelected(); -} - -// -// formatting helpers -// - -var TrackDirections = ["North","Northeast","East","Southeast","South","Southwest","West","Northwest"]; - -// track in degrees (0..359) -function format_track_brief(track) { - if (track === null) return ""; - return Math.round(track); -} - -// track in degrees (0..359) -function format_track_long(track) { - if (track === null) return "n/a"; - var trackDir = Math.floor((360 + track % 360 + 22.5) / 45) % 8; - return Math.round(track) + DEGREES + NBSP + "(" + TrackDirections[trackDir] + ")"; -} - -// alt in ft -function format_altitude_brief(alt, vr) { - var alt_text; - - if (alt === null) - return ""; - if (alt === "ground") - return "ground"; - - if (Metric) - alt_text = Math.round(alt / 3.2828) + NBSP; - else - alt_text = Math.round(alt) + NBSP; - - if (vr > 128) - return alt_text + UP_TRIANGLE; - else if (vr < -128) - return alt_text + DOWN_TRIANGLE; - else - return alt_text + NBSP; -} - -// alt in ft -function format_altitude_long(alt, vr) { - var alt_text; - - if (alt === null) - return "n/a"; - if (alt === "ground") - return "on ground"; - - if (Metric) - alt_text = Math.round(alt / 3.2828) + NBSP + "m / " + Math.round(alt) + NBSP + "ft"; - else - alt_text = Math.round(alt) + NBSP + "ft / " + Math.round(alt / 3.2828) + NBSP + "m"; - - if (vr > 128) - return UP_TRIANGLE + NBSP + alt_text; - else if (vr < -128) - return DOWN_TRIANGLE + NBSP + alt_text; - else - return alt_text; -} - -// speed in kts -function format_speed_brief(speed) { - if (speed === null) - return ""; - - if (Metric) - return Math.round(speed * 1.852); - else - return Math.round(speed); -} - -// speed in kts -function format_speed_long(speed) { - if (speed === null) - return "n/a"; - - if (Metric) - return Math.round(speed * 1.852) + NBSP + "km/h / " + Math.round(speed) + NBSP + "kt"; - else - return Math.round(speed) + NBSP + "kt / " + Math.round(speed * 1.852) + NBSP + "km/h"; -} - -// dist in metres -function format_distance_brief(dist) { - if (dist === null) - return ""; - - if (Metric) - return (dist/1000).toFixed(1); - else - return (dist/1852).toFixed(1); -} - -// dist in metres -function format_distance_long(dist) { - if (dist === null) - return "n/a"; - - if (Metric) - return (dist/1000).toFixed(1) + " km / " + (dist/1852).toFixed(1) + " NM"; - else - return (dist/1852).toFixed(1) + " NM / " + (dist/1000).toFixed(1) + " km"; -} - -// p as a LatLng -function format_latlng(p) { - return p.lat().toFixed(3) + DEGREES + "," + NBSP + p.lng().toFixed(3) + DEGREES; } // Refresh the detail window about the plane