58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
import fetch from './fetch.mjs';
|
|
|
|
export async function getOpenskyData() {
|
|
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
|
|
const res = await fetch.get(`https://opensky-network.org/api/states/all`);
|
|
return res.data.states.map(rec => ({
|
|
transponder: `${rec[0]}`.toLowerCase(),
|
|
callsign: `${rec[1]}`.trim(),
|
|
origin_country: rec[2],
|
|
time_position: new Date(rec[3] * 1000),
|
|
last_contact: new Date(rec[4] * 1000),
|
|
location: rec[5] && rec[6] ? `${rec[6]},${rec[5]}` : null,
|
|
lat: rec[6],
|
|
lon: rec[5],
|
|
baro_altitude: rec[7],
|
|
geo_altitude: rec[13],
|
|
on_ground: rec[8],
|
|
velocity: rec[9],
|
|
vertical_rate: rec[11],
|
|
squawk: rec[14],
|
|
spi: rec[15],
|
|
position_source: positionSourceMap[rec[16]],
|
|
}));
|
|
}
|
|
|
|
export async function getAdbsExchangeData({ lat, lon, radius }) {
|
|
const positionSourceMap = ['Unknown', 'Mode-S', 'ADS-B', 'ADS-B', 'ADS-B', 'ADS-B'];
|
|
const formatNumber = str => str && Number(`${str}`.replace(/[^0-9.-]/, ''));
|
|
|
|
const res = await fetch.get(
|
|
`http://public-api.adsbexchange.com/VirtualRadar/AircraftList.json?lat=${lat}&lng=${lon}&fDstL=0&fDstU=${radius}`
|
|
);
|
|
|
|
return res.data.acList.map(rec => ({
|
|
transponder: `${rec.Icao}`.toLowerCase(),
|
|
callsign: `${rec.Call}`.trim(),
|
|
origin_country: rec.Cou,
|
|
time_position: new Date(rec.PosTime),
|
|
last_contact: new Date(rec.PosTime),
|
|
location: rec.Lat && rec.Long ? `${rec.Lat},${rec.Long}` : null,
|
|
lat: rec.Lat,
|
|
lon: rec.Long,
|
|
baro_altitude: formatNumber(rec.Alt),
|
|
geo_altitude: formatNumber(rec.GAlt),
|
|
on_ground: rec.Gnd,
|
|
velocity: formatNumber(rec.Spd),
|
|
vertical_rate: formatNumber(rec.Vsi),
|
|
squawk: rec.Sqk,
|
|
spi: false,
|
|
position_source: positionSourceMap[rec.Trt],
|
|
operator: rec.Op,
|
|
aircraft: rec.Mdl,
|
|
aircraft_manufacturer: rec.Man,
|
|
from: rec.From,
|
|
to: rec.To,
|
|
}));
|
|
}
|