feat: add ads-b exchange source

This commit is contained in:
2018-11-02 14:49:40 -07:00
parent aca5c03388
commit 9f0da54ccf
3 changed files with 38 additions and 3 deletions

View File

@@ -26,6 +26,9 @@ export async function createIndex(client, index) {
mappings: {
[doctype]: {
properties: {
operator: { type: 'keyword' },
aircraft: { type: 'text' },
aircraft_manufacturer: { type: 'keyword' },
transponder: { type: 'keyword' },
callsign: { type: 'keyword' },
origin_country: { type: 'keyword' },
@@ -42,6 +45,8 @@ export async function createIndex(client, index) {
squawk: { type: 'keyword' },
spi: { type: 'boolean' },
position_source: { type: 'keyword' },
from: { type: 'text' },
to: { type: 'text' },
},
},
},

View File

@@ -1,7 +1,7 @@
import axios from 'axios';
export default axios.create({
timeout: 3000,
timeout: 5000,
responseType: 'json',
headers: {
'Content-Type': 'application/json; charset=utf-8',

View File

@@ -1,8 +1,7 @@
import fetch from './fetch.mjs';
const positionSourceMap = ['ADS-B', 'ASTERIX', 'MLAT'];
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(),
@@ -23,3 +22,34 @@ export async function getOpenskyData() {
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 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: rec.Alt,
geo_altitude: rec.Galt,
on_ground: rec.Gnd,
velocity: rec.Spd,
vertical_rate: 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,
}));
}