Add ability to map aircraft type descriptions to markers

This commit is contained in:
Carlos Salaverria 2016-08-29 17:12:52 -05:00
parent e13b09f1a4
commit d5293cc0ed
2 changed files with 65 additions and 26 deletions

View file

@ -121,6 +121,21 @@ var _balloon = {
markerRadius: 32 markerRadius: 32
}; };
var _helicopter = {
key : "helicopter",
scale : 0.50,
size : [64, 64],
anchor : [22, 32],
path : _rotorcraft_svg
};
var _single_prop = {
key : "single_prop",
scale : 0.30,
size : [64, 64],
anchor : [32, 25],
path : _beechcraft_svg
};
// by Oliver Jowett <oliver@mutability.co.uk> // by Oliver Jowett <oliver@mutability.co.uk>
// licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) // licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/)
@ -140,7 +155,7 @@ var _b738 = {
path: "m 32,61 -1,-1 -9,2 -2,1 0,-2 9,-6 1,-1 -1,-9 0,-11 -7,0 -1,1 0,-1 -3,1 -1,1 0,-1 -3,1 -9,3 -1,1 0,-2 1,-2 17,-9 1,-1 -1,-2 0,-3 1,-1 2,0 1,1 0,3 3,-2 0,-13 1,-5 1,-3 1,-1 1,1 1,3 1,5 0,13 3,2 0,-3 1,-1 2,0 1,1 0,3 -1,2 1,1 17,9 1,2 0,2 -1,-1 -9,-3 -3,-1 0,1 -1,-1 -3,-1 0,1 -1,-1 -7,0 0,11 -1,9 1,1 9,6 0,2 -2,-1 -9,-2 -1,1 z" path: "m 32,61 -1,-1 -9,2 -2,1 0,-2 9,-6 1,-1 -1,-9 0,-11 -7,0 -1,1 0,-1 -3,1 -1,1 0,-1 -3,1 -9,3 -1,1 0,-2 1,-2 17,-9 1,-1 -1,-2 0,-3 1,-1 2,0 1,1 0,3 3,-2 0,-13 1,-5 1,-3 1,-1 1,1 1,3 1,5 0,13 3,2 0,-3 1,-1 2,0 1,1 0,3 -1,2 1,1 17,9 1,2 0,2 -1,-1 -9,-3 -3,-1 0,1 -1,-1 -3,-1 0,1 -1,-1 -7,0 0,11 -1,9 1,1 9,6 0,2 -2,-1 -9,-2 -1,1 z"
}; };
var TypeIcons = { var TypeDesignatorIcons = {
'A318': _a320, // shortened a320 'A318': _a320, // shortened a320
'A319': _a320, // shortened a320 'A319': _a320, // shortened a320
'A320': _a320, 'A320': _a320,
@ -182,14 +197,30 @@ var TypeIcons = {
'C30J': _c130 'C30J': _c130
}; };
// Maps ICAO aircraft type description codes (e.g. "L2J") to aircraft icons. This is used if the ICAO type designator (e.g. "B731")
// cannot be found in the TypeDesignatorIcons mappings. The key can be one of the following:
// - Single character: The basic aircraft type letter code (e.g. "H" for helicopter).
// - Three characters: The ICAO type description code (e.g. "L2J" for landplanes with 2 jet engines).
// - Five characters: The ICAO type description code concatenated with the wake turbulence category code, separated by
// a dash (e.g. "L2J-M").
var TypeDescriptionIcons = {
'H': _helicopter,
'L1J': _g650,
'L1P': _single_prop,
'L1T': _single_prop,
'L2P': _b200,
'L2T': _b200,
'L2J-L': _g650,
'L2J-M': _a320,
'L2J-H': _b777,
};
var CategoryIcons = { var CategoryIcons = {
"A1" : { "A1" : _single_prop,
key : "A1",
scale : 0.30,
size : [64, 64],
anchor : [32, 25],
path : _beechcraft_svg
},
"A2" : { "A2" : {
key : "A2", key : "A2",
@ -215,13 +246,7 @@ var CategoryIcons = {
path : _heavy_svg path : _heavy_svg
}, },
"A7" : { "A7" : _helicopter,
key : "A7",
scale : 0.50,
size : [64, 64],
anchor : [22, 32],
path : _rotorcraft_svg
},
"B2" : _balloon "B2" : _balloon
}; };
@ -234,9 +259,27 @@ var DefaultIcon = {
path : _generic_plane_svg path : _generic_plane_svg
}; };
function getBaseMarker(category, type) { function getBaseMarker(category, typeDesignator, typeDescription, wtc) {
if (type in TypeIcons) { if (typeDesignator in TypeDesignatorIcons) {
return TypeIcons[type]; return TypeDesignatorIcons[typeDesignator];
}
if (typeDescription !== undefined && typeDescription !== null && typeDescription.length === 3) {
if (wtc !== undefined && wtc !== null && wtc.length === 1) {
var typeDescriptionWithWtc = typeDescription + "-" + wtc;
if (typeDescriptionWithWtc in TypeDescriptionIcons) {
return TypeDescriptionIcons[typeDescriptionWithWtc];
}
}
if (typeDescription in TypeDescriptionIcons) {
return TypeDescriptionIcons[typeDescription];
}
var basicType = typeDescription.charAt(0);
if (basicType in TypeDescriptionIcons) {
return TypeDescriptionIcons[basicType];
}
} }
if (category in CategoryIcons) { if (category in CategoryIcons) {

View file

@ -48,9 +48,7 @@ function PlaneObject(icao) {
// request metadata // request metadata
this.registration = null; this.registration = null;
this.icaotype = null; this.icaotype = null;
this.aircraftTypeCode = null; this.typeDescription = null;
this.engineCount = null;
this.engineType = null;
this.wtc = null; this.wtc = null;
getAircraftData(this.icao).done(function(data) { getAircraftData(this.icao).done(function(data) {
if ("r" in data) { if ("r" in data) {
@ -62,9 +60,7 @@ function PlaneObject(icao) {
} }
if ("desc" in data) { if ("desc" in data) {
this.aircraftTypeCode = data.desc.charAt(0); this.typeDescription = data.desc;
this.engineCount = parseInt(data.desc.charAt(1));
this.engineTypeCode = data.desc.charAt(2);
} }
if ("wtc" in data) { if ("wtc" in data) {
@ -303,7 +299,7 @@ PlaneObject.prototype.updateIcon = function() {
var col = this.getMarkerColor(); var col = this.getMarkerColor();
var opacity = (this.position_from_mlat ? 0.75 : 1.0); var opacity = (this.position_from_mlat ? 0.75 : 1.0);
var outline = (this.position_from_mlat ? OutlineMlatColor : OutlineADSBColor); var outline = (this.position_from_mlat ? OutlineMlatColor : OutlineADSBColor);
var baseMarker = getBaseMarker(this.category, this.icaotype); var baseMarker = getBaseMarker(this.category, this.icaotype, this.typeDescription, this.wtc);
var weight = ((this.selected ? 2 : 1) / baseMarker.scale).toFixed(1); var weight = ((this.selected ? 2 : 1) / baseMarker.scale).toFixed(1);
var rotation = (this.track === null ? 0 : this.track); var rotation = (this.track === null ? 0 : this.track);