2015-02-22 02:22:05 +01:00
|
|
|
// -*- mode: javascript; indent-tabs-mode: t; c-basic-offset: 8 -*-
|
|
|
|
"use strict";
|
|
|
|
|
2015-02-22 02:29:02 +01:00
|
|
|
var NBSP='\u00a0';
|
|
|
|
var DEGREES='\u00b0'
|
|
|
|
var UP_TRIANGLE='\u25b2'; // U+25B2 BLACK UP-POINTING TRIANGLE
|
|
|
|
var DOWN_TRIANGLE='\u25bc'; // U+25BC BLACK DOWN-POINTING TRIANGLE
|
|
|
|
|
2015-02-20 00:09:03 +01:00
|
|
|
var TrackDirections = ["North","Northeast","East","Southeast","South","Southwest","West","Northwest"];
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-22 23:48:17 +02:00
|
|
|
var UnitLabels = {
|
|
|
|
'altitude': { metric: "m", imperial: "ft", nautical: "ft"},
|
|
|
|
'speed': { metric: "km/h", imperial: "mph", nautical: "kt" },
|
|
|
|
'distance': { metric: "km", imperial: "mi", nautical: "NM" },
|
|
|
|
'verticalRate': { metric: "m/s", imperial: "ft/min", nautical: "ft/min" }
|
|
|
|
};
|
|
|
|
|
2015-02-20 00:09:03 +01:00
|
|
|
// formatting helpers
|
|
|
|
|
2016-08-22 23:48:17 +02:00
|
|
|
function get_unit_label(quantity, systemOfMeasurement) {
|
|
|
|
var labels = UnitLabels[quantity];
|
|
|
|
if (labels !== undefined && labels[systemOfMeasurement] !== undefined) {
|
|
|
|
return labels[systemOfMeasurement];
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2015-02-20 00:09:03 +01:00
|
|
|
// 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] + ")";
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// alt in feet
|
2016-08-22 23:48:17 +02:00
|
|
|
function format_altitude_brief(alt, vr, displayUnits) {
|
2015-02-20 00:09:03 +01:00
|
|
|
var alt_text;
|
|
|
|
|
|
|
|
if (alt === null){
|
|
|
|
return "";
|
|
|
|
} else if (alt === "ground"){
|
|
|
|
return "ground";
|
|
|
|
}
|
2016-08-23 23:43:32 +02:00
|
|
|
|
|
|
|
alt_text = Math.round(convert_altitude(alt, displayUnits)) + NBSP;
|
|
|
|
|
2015-02-20 00:09:03 +01:00
|
|
|
// Vertical Rate Triangle
|
2016-09-13 00:08:22 +02:00
|
|
|
var verticalRateTriangle = "<span class=\"verticalRateTriangle\">";
|
2015-02-20 00:09:03 +01:00
|
|
|
if (vr > 128){
|
2016-09-13 00:08:22 +02:00
|
|
|
verticalRateTriangle += UP_TRIANGLE;
|
2015-02-20 00:09:03 +01:00
|
|
|
} else if (vr < -128){
|
2016-09-13 00:08:22 +02:00
|
|
|
verticalRateTriangle += DOWN_TRIANGLE;
|
2015-02-20 00:09:03 +01:00
|
|
|
} else {
|
2016-09-13 00:08:22 +02:00
|
|
|
verticalRateTriangle += NBSP;
|
2015-02-20 00:09:03 +01:00
|
|
|
}
|
2016-09-13 00:08:22 +02:00
|
|
|
verticalRateTriangle += "</span>"
|
|
|
|
|
|
|
|
return alt_text + verticalRateTriangle;
|
2015-02-20 00:09:03 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// alt in feet
|
2016-08-22 23:48:17 +02:00
|
|
|
function format_altitude_long(alt, vr, displayUnits) {
|
2015-02-20 00:09:03 +01:00
|
|
|
var alt_text = "";
|
|
|
|
|
|
|
|
if (alt === null) {
|
|
|
|
return "n/a";
|
|
|
|
} else if (alt === "ground") {
|
|
|
|
return "on ground";
|
|
|
|
}
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
alt_text = Math.round(convert_altitude(alt, displayUnits)) + NBSP + get_unit_label("altitude", displayUnits);
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2015-02-20 00:09:03 +01:00
|
|
|
if (vr > 128) {
|
|
|
|
return UP_TRIANGLE + NBSP + alt_text;
|
|
|
|
} else if (vr < -128) {
|
|
|
|
return DOWN_TRIANGLE + NBSP + alt_text;
|
|
|
|
} else {
|
|
|
|
return alt_text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// alt in feet
|
|
|
|
function convert_altitude(alt, displayUnits) {
|
2016-08-22 23:48:17 +02:00
|
|
|
if (displayUnits === "metric") {
|
2016-08-23 23:43:32 +02:00
|
|
|
return alt / 3.2808; // feet to meters
|
2015-02-20 00:09:03 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
return alt;
|
|
|
|
}
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// speed in knots
|
|
|
|
function format_speed_brief(speed, displayUnits) {
|
|
|
|
if (speed === null) {
|
|
|
|
return "";
|
|
|
|
}
|
2016-08-22 23:48:17 +02:00
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
return Math.round(convert_speed(speed, displayUnits));
|
2015-02-22 02:22:05 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// speed in knots
|
2016-08-22 23:48:17 +02:00
|
|
|
function format_speed_long(speed, displayUnits) {
|
2015-02-20 00:09:03 +01:00
|
|
|
if (speed === null) {
|
|
|
|
return "n/a";
|
|
|
|
}
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
var speed_text = Math.round(convert_speed(speed, displayUnits)) + NBSP + get_unit_label("speed", displayUnits);
|
2015-02-22 02:22:05 +01:00
|
|
|
|
|
|
|
return speed_text;
|
2015-02-20 00:09:03 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// speed in knots
|
|
|
|
function convert_speed(speed, displayUnits) {
|
|
|
|
if (displayUnits === "metric") {
|
|
|
|
return speed * 1.852; // knots to kilometers per hour
|
|
|
|
}
|
|
|
|
else if (displayUnits === "imperial") {
|
|
|
|
return speed * 1.151; // knots to miles per hour
|
|
|
|
}
|
|
|
|
|
|
|
|
return speed;
|
|
|
|
}
|
|
|
|
|
2015-02-20 00:09:03 +01:00
|
|
|
// dist in meters
|
2016-08-22 23:48:17 +02:00
|
|
|
function format_distance_brief(dist, displayUnits) {
|
2015-02-20 00:09:03 +01:00
|
|
|
if (dist === null) {
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
return convert_distance(dist, displayUnits).toFixed(1);
|
2015-02-22 02:22:05 +01:00
|
|
|
}
|
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// dist in meters
|
2016-08-22 23:48:17 +02:00
|
|
|
function format_distance_long(dist, displayUnits) {
|
2015-02-20 00:09:03 +01:00
|
|
|
if (dist === null) {
|
|
|
|
return "n/a";
|
|
|
|
}
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
var dist_text = convert_distance(dist, displayUnits).toFixed(1) + NBSP + get_unit_label("distance", displayUnits);
|
2016-08-22 23:48:17 +02:00
|
|
|
|
|
|
|
return dist_text;
|
|
|
|
}
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-23 23:43:32 +02:00
|
|
|
// dist in meters
|
|
|
|
function convert_distance(dist, displayUnits) {
|
|
|
|
if (displayUnits === "metric") {
|
|
|
|
return (dist / 1000); // meters to kilometers
|
|
|
|
}
|
|
|
|
else if (displayUnits === "imperial") {
|
|
|
|
return (dist / 1609); // meters to miles
|
|
|
|
}
|
|
|
|
return (dist / 1852); // meters to nautical miles
|
|
|
|
}
|
|
|
|
|
2016-08-22 23:48:17 +02:00
|
|
|
// rate in ft/min
|
|
|
|
function format_vert_rate_brief(rate, displayUnits) {
|
2016-08-30 23:38:41 +02:00
|
|
|
if (rate === null || rate === undefined) {
|
2016-08-22 23:48:17 +02:00
|
|
|
return "";
|
2015-02-20 00:09:03 +01:00
|
|
|
}
|
2015-02-22 02:22:05 +01:00
|
|
|
|
2016-08-30 23:38:41 +02:00
|
|
|
return convert_vert_rate(rate, displayUnits).toFixed(displayUnits === "metric" ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// rate in ft/min
|
|
|
|
function format_vert_rate_long(rate, displayUnits) {
|
|
|
|
if (rate === null || rate === undefined) {
|
|
|
|
return "n/a";
|
|
|
|
}
|
|
|
|
|
|
|
|
var rate_text = convert_vert_rate(rate, displayUnits).toFixed(displayUnits === "metric" ? 1 : 0) + NBSP + get_unit_label("verticalRate", displayUnits);
|
|
|
|
|
|
|
|
return rate_text;
|
|
|
|
}
|
|
|
|
|
|
|
|
// rate in ft/min
|
|
|
|
function convert_vert_rate(rate, displayUnits) {
|
2016-08-22 23:48:17 +02:00
|
|
|
if (displayUnits === "metric") {
|
2016-08-30 23:38:41 +02:00
|
|
|
return (rate / 196.85); // ft/min to m/s
|
2016-08-22 23:48:17 +02:00
|
|
|
}
|
2016-08-30 23:38:41 +02:00
|
|
|
|
|
|
|
return rate;
|
2015-02-20 00:09:03 +01:00
|
|
|
}
|
|
|
|
|
2016-07-02 15:44:14 +02:00
|
|
|
// p is a [lon, lat] coordinate
|
2015-02-20 00:09:03 +01:00
|
|
|
function format_latlng(p) {
|
2016-07-02 15:44:14 +02:00
|
|
|
return p[1].toFixed(3) + DEGREES + "," + NBSP + p[0].toFixed(3) + DEGREES;
|
2015-02-22 02:22:05 +01:00
|
|
|
}
|
2016-08-20 00:37:43 +02:00
|
|
|
|
|
|
|
function format_data_source(source) {
|
|
|
|
switch (source) {
|
|
|
|
case 'mlat':
|
|
|
|
return "MLAT";
|
|
|
|
case 'adsb':
|
|
|
|
return "ADSB";
|
|
|
|
case 'mode_s':
|
|
|
|
return "Mode S";
|
|
|
|
case 'mode_ac':
|
|
|
|
return "Mode A/C";
|
|
|
|
}
|
|
|
|
|
2016-08-20 01:45:39 +02:00
|
|
|
return "";
|
|
|
|
}
|