Skip to main content

Overview

The Flight interface represents the normalized flight data structure used throughout the Air Tracker application. It contains comprehensive information about an aircraft’s position, velocity, identification, and metadata.

Interface Definition

export interface Flight {
  icao24: string;
  callsign: string | null;
  originCountry: string;
  timePosition?: number | null;
  lastContact?: number;
  latitude: number | null;
  longitude: number | null;
  altitudeBaro: number | null;
  altitudeGeo: number | null;
  heading: number | null;
  velocity: number | null;
  onGround: boolean;
  category: string | null;
  model: string | null;
  operator: string | null;
  operatorIcao: string | null;
  owner: string | null;
  typecode: string | null;
  registration: string | null;
  verticalRate: number | null;
  squawk: string | null;
  spi: boolean;
}

Properties

icao24
string
required
Unique ICAO 24-bit address of the aircraft in hex string representation (e.g., “a1b2c3”)
callsign
string | null
Aircraft callsign (flight number). May be null if not available
originCountry
string
required
Country where the aircraft is registered
timePosition
number | null
Unix timestamp (seconds) of the last position update. Optional field
lastContact
number
Unix timestamp (seconds) of the last data received from the aircraft
latitude
number | null
WGS-84 latitude in decimal degrees. Null if position is not available
longitude
number | null
WGS-84 longitude in decimal degrees. Null if position is not available
altitudeBaro
number | null
Barometric altitude in meters. Null if not available
altitudeGeo
number | null
Geometric altitude in meters. Null if not available
heading
number | null
True track (heading) in decimal degrees (0-360). Null if not available
velocity
number | null
Ground speed in m/s. Null if not available
onGround
boolean
required
Indicates whether the aircraft is on the ground (true) or in the air (false)
category
string | null
Aircraft category (e.g., “A1” for light aircraft)
model
string | null
Aircraft model name (e.g., “Boeing 737-800”)
operator
string | null
Airline or operator name
operatorIcao
string | null
ICAO code of the operator/airline
owner
string | null
Aircraft owner name
typecode
string | null
ICAO aircraft type designator (e.g., “B738” for Boeing 737-800)
registration
string | null
Aircraft registration number (tail number)
verticalRate
number | null
Vertical rate in m/s. Positive values indicate climb, negative indicate descent
squawk
string | null
Transponder squawk code (4-digit code)
spi
boolean
required
Special Position Identification flag. True when the pilot has activated the ident button

Mapping Function

The mapFlightDtoToFlight function converts a FlightDto from the backend response into the Flight model used in the application.
export const mapFlightDtoToFlight = (dto: FlightDto): Flight => ({
  icao24: dto.icao24,
  callsign: dto.callsign,
  originCountry: dto.originCountry,
  timePosition: dto.timePosition,
  lastContact: dto.lastContact,
  latitude: dto.latitude,
  longitude: dto.longitude,
  altitudeBaro: dto.altitudeBaro,
  altitudeGeo: dto.altitudeGeo,
  heading: dto.heading,
  onGround: dto.onGround,
  velocity: dto.velocity,
  category: dto.category,
  model: dto.model,
  operator: dto.operator,
  operatorIcao: dto.operatorIcao,
  owner: dto.owner,
  typecode: dto.typecode,
  registration: dto.registration,
  verticalRate: dto.verticalRate,
  squawk: dto.squawk,
  spi: dto.spi,
});

Usage Examples

Converting API Response to Flight Model

import { mapFlightDtoToFlight } from './models/flight.model';
import type { FlightDto } from './models/flight.dto';

// Received from API
const flightDto: FlightDto = {
  icao24: "a1b2c3",
  callsign: "UAL123",
  originCountry: "United States",
  timePosition: 1678901234,
  lastContact: 1678901235,
  latitude: 37.7749,
  longitude: -122.4194,
  altitudeBaro: 10000,
  altitudeGeo: 10050,
  heading: 270,
  velocity: 250,
  onGround: false,
  category: "A3",
  model: "Boeing 737-900",
  operator: "United Airlines",
  operatorIcao: "UAL",
  owner: "United Airlines Inc",
  typecode: "B739",
  registration: "N12345",
  verticalRate: 5.2,
  squawk: "1200",
  spi: false
};

// Convert to Flight model
const flight = mapFlightDtoToFlight(flightDto);

Working with Flight Data

import type { Flight } from './models/flight.model';

function displayFlightInfo(flight: Flight): void {
  console.log(`Flight ${flight.callsign || 'Unknown'}`);
  console.log(`ICAO24: ${flight.icao24}`);
  console.log(`Status: ${flight.onGround ? 'On Ground' : 'In Flight'}`);
  
  if (flight.latitude && flight.longitude) {
    console.log(`Position: ${flight.latitude}, ${flight.longitude}`);
  }
  
  if (flight.altitudeBaro) {
    console.log(`Altitude: ${flight.altitudeBaro}m`);
  }
  
  if (flight.velocity) {
    console.log(`Speed: ${flight.velocity}m/s`);
  }
}

Filtering Flights

import type { Flight } from './models/flight.model';

function getAirborneFlights(flights: Flight[]): Flight[] {
  return flights.filter(flight => !flight.onGround);
}

function getFlightsByOperator(flights: Flight[], operatorName: string): Flight[] {
  return flights.filter(flight => 
    flight.operator?.toLowerCase().includes(operatorName.toLowerCase())
  );
}

Source Location

~/workspace/source/src/app/features/flights/models/flight.model.ts

Build docs developers (and LLMs) love