Skip to content

Commit

Permalink
Correct display units
Browse files Browse the repository at this point in the history
When hovering the mouse on an aircraft, the pop-up box (and when zoomed in, the label) was always in NM  regardless of the DisplayUnits option in config.js. Corrected
  • Loading branch information
alkissack committed Sep 17, 2023
1 parent 9b9e086 commit cf9f6a6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 22 deletions.
1 change: 1 addition & 0 deletions public_html/formatter.js
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ function convert_distance(dist, displayUnits) {
return (dist / 1852); // meters to nautical miles
}


// rate in ft/min
function format_vert_rate_brief(rate, displayUnits) {
if (rate === null || rate === undefined) {
Expand Down
24 changes: 16 additions & 8 deletions public_html/planeObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -871,19 +871,27 @@ PlaneObject.prototype.updateMarker = function (moved) {
tmpText = this.icaotype ? this.icaotype : "Unknown Type";
}
labelText = labelText + "\n" + tmpText;
} else {
labelText = labelText + "\n[" + (this.fl ? this.fl : "?") + v + "]";
}
}

//LINE THREE
labelText =
labelText +
"\n" +
this.icao.toUpperCase() +
" [" +
(this.fl ? this.fl : "?") +
v +
"]";
this.icao.toUpperCase();

var hgt = parseInt(this.fl ? (this.fl) : 0);
hgt = convert_altitude(hgt*100, DisplayUnits);
//console.log("Height.. " + hgt);
labelText =
labelText +
"[" + parseInt(hgt) + (DisplayUnits === "metric" ? "m" : " ft") + "]";

//labelText =
// labelText +
// " [" +
// (this.fl ? this.fl : "?") +
// v +
// "]";
}

var hexColour = this.labelColour; // New section for semi transparency
Expand Down
45 changes: 31 additions & 14 deletions public_html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ function end_load_history() {
fetchData();
}

// Make a LineString with 'points'-number points
// Make a LineString with 'points'- number points
// that is a closed circle on the sphere such that the
// great circle distance from 'center' to each point is
// 'radius' meters
Expand Down Expand Up @@ -1578,13 +1578,14 @@ function initialize_map() {
popname = popname + " [" + Planes[feature.hex].registration + "]";

//LINE THREE
var hgt = parseInt(Planes[feature.hex].altitude ? (Planes[feature.hex].altitude) : 0);
hgt = convert_altitude(hgt, DisplayUnits);
//console.log("Height.. " + hgt);
popname =
popname +
"\n" +
(Planes[feature.hex].altitude
? parseInt(Planes[feature.hex].altitude)
: "?");
popname = popname + " ft and " + vsi;
"\n" + parseInt(hgt) + (DisplayUnits === "metric" ? "m & " : " ft & ") + vsi;


//LINE FOUR
popname =
popname +
Expand All @@ -1598,18 +1599,21 @@ function initialize_map() {
(Planes[feature.hex].operator
? Planes[feature.hex].operator
: "");

var dst = parseInt(Planes[feature.hex].siteNm ? (Planes[feature.hex].siteNm) : 0);
dst = convert_nm_distance(dst, DisplayUnits);
//console.log("Distance.. " + dst);
popname =
popname +
" " +
(Planes[feature.hex].siteNm
? Planes[feature.hex].siteNm + "nm"
: "");
" " + dst.toFixed(2) + (DisplayUnits === "metric" ? " km " : DisplayUnits === "imperial" ? " mile " : " nm ");

popname =
popname +
" " +
(Planes[feature.hex].siteBearing
? Planes[feature.hex].siteBearing + "\u00B0"
: "");

} else {
popname = "ICAO: " + Planes[feature.hex].icao;
popname =
Expand All @@ -1628,12 +1632,14 @@ function initialize_map() {
(Planes[feature.hex].registration
? Planes[feature.hex].registration
: "?");

var hgt = parseInt(Planes[feature.hex].altitude ? (Planes[feature.hex].altitude) : 0);
hgt = convert_altitude(hgt, DisplayUnits);
//console.log("Height.. " + hgt);
popname =
popname +
"\nFt: " +
(Planes[feature.hex].altitude
? parseInt(Planes[feature.hex].altitude)
: "?");
"\nAlt: " + parseInt(hgt) + (DisplayUnits === "metric" ? "m " : " ft ");

}
overlay.getElement().innerHTML = popname ? popname : "";
return feature;
Expand Down Expand Up @@ -3117,3 +3123,14 @@ function getTerrainColorByAlti(alti) {
"%)"
);
}

// dist in nm
function convert_nm_distance(dist, displayUnits) {
if (displayUnits === "metric") {
return (dist * 1.852); // nm to kilometers
}
else if (displayUnits === "imperial") {
return (dist * 1.15078); // meters to miles
}
return (dist); // nautical miles
}

0 comments on commit cf9f6a6

Please sign in to comment.