Tle.js
🛰️ Satellite TLE tools in JavaScript: get lat/lon of satellites, get look angles, plot orbit lines, extract individual TLE elements, etc
Install / Use
/learn @davidcalhoun/Tle.jsREADME
tle.js
Satellite TLE tools in JavaScript
Installation
npm add tle.js or yarn add tle.js
Introduction
tle.js is designed to simplify satellite TLEs and SGP4 with a friendly interface, with satellite.js doing the heavy lifting behind the scenes.
The origin of TLEs goes back to the punchcard days! A TLE, or two-line element set, is used by SGP4 propagators to determine spacecraft positioning information, taking into account gravity perturbations (the moon, etc).
Most users will probably want to simply get the latitude/longitude of a satellite (see getLatLngObj) or get the look angles from a ground position, which can be used to track where in the sky a satellite is visible (see getSatelliteInfo). Users may also want to plot orbit lines (see getGroundTracks).
Users may also be interested in grabbing specific values from a TLE. In this case, you can use one of the TLE getters, for instance getCOSPAR.
Note that TLEs should be updated at least daily to avoid drift in calculations. You can get them online at Celestrak, where they are updated every few hours.
More info on TLEs:
Shared code
Let's start out with some code to define some variables which we'll use in many examples below.
// Satellite TLE; should be updated at least once a day for best results.
// TLE source: http://celestrak.com/NORAD/elements/
const tle = `ISS (ZARYA)
1 25544U 98067A 17206.18396726 .00001961 00000-0 36771-4 0 9993
2 25544 51.6400 208.9163 0006317 69.9862 25.2906 15.54225995 67660`;
Two-line variants and an array of strings are also accepted.
getLatLngObj(tle, optionalTimestampMS)
Computes the latitude/longitude of a spacecraft. Defaults to the current local time if optionalTimestampMS is not passed in.
Note: the greater the difference between this timestamp and the TLE epoch (when the TLE was generated) will result in inaccuracies or even errors.
import { getLatLngObj } from "tle.js";
const optionalTimestampMS = 1502342329860;
const latLonObj = getLatLngObj(tle, optionalTimestampMS);
->
{
lat: -47.64247588153391,
lng: -29.992233800623634
}
getGroundTracks(options)
Async function that returns a Promise that resolves with an array of longitude, latitude pairs for drawing the ground track (satellite path) for three orbits: one past orbit, one current orbit, and one future orbit.
Orbits start and stop at the international date line (antemeridian) because values passing over that line is commonly problematic in mapping.
Note: the synchronous version of this function, getGroundTracksSync, has the same function signature (it accepts the same inputs).
import { getGroundTracks } from 'tle.js';
const threeOrbitsArr = await getGroundTracks({
tle: tleStr,
// Relative time to draw orbits from. This will be used as the "middle"/current orbit.
startTimeMS: 1502342329860,
// Resolution of plotted points. Defaults to 1000 (plotting a point once for every second).
stepMS: 1000,
// Returns points in [lng, lat] order when true, and [lat, lng] order when false.
isLngLatFormat: true,
});
// Alternatively, if your setup doesn't support async/await:
getGroundTracks({
tle: tleStr,
startTimeMS: 1502342329860,
stepMS: 1000,
isLngLatFormat: true,
}).then(function (threeOrbitsArr) {
// Do stuff with three orbits array here.
});
// threeOrbitsArr contents
[
// previous orbit
[
[-179.93297540317567, 45.85524291891481],
// etc...
],
// current orbit
[
[-179.9398612198045, 51.26165992503701],
// etc...
],
// next orbit
[
[-179.9190165549038, 51.0273714070371],
// etc...
],
];
getSatelliteInfo(tle, optionalTimestamp, observerLat, observerLng, observerElevation)
Get both look angles (for a ground observer) as well as a few more tidbits of satellite info.
import { getSatelliteInfo } from "tle.js";
const satInfo = getSatelliteInfo(
tleStr, // Satellite TLE string or array.
1501039265000, // Timestamp (ms)
34.243889, // Observer latitude (degrees)
-116.911389, // Observer longitude (degrees)
0 // Observer elevation (km)
);
->
{
// satellite compass heading from observer in degrees (0 = north, 180 = south)
azimuth: 294.5780478624994,
// satellite elevation from observer in degrees (90 is directly overhead)
elevation: 81.63903620330046,
// km distance from observer to spacecraft
range: 406.60211015810074,
// spacecraft altitude in km
height: 402.9082788620108,
// spacecraft latitude in degrees
lat: 34.45112876592785,
// spacecraft longitude in degrees
lng: -117.46176597710809,
// spacecraft velocity (relative to observer) in km/s
velocity: 7.675627442183371
}
getVisibleSatellites(options)
Calculates satellites visible relative to an observer's position.
import { getVisibleSatellites } from "tle.js";
const allVisible = getVisibleSatellites({
observerLat: 34.439283990227125,
observerLng: -117.47561122364522,
observerHeight: 0,
// Array of 3-line TLE arrays.
tles: uniqTLES,
// Filters satellites above a certain elevation (0 is horizon, 90 is directly overhead).
// E.g. 75 will only return satellites 75 degrees or greater above the horizon.
// Defaults to 0.
elevationThreshold: 75,
// Defaults to current time.
timestampMS: 1570911182419
});
->
[
{
tleArr: [
'COSMOS 2492 [GLONASS-M]',
'1 39620U 14012A 19285.51719791 -.00000065 00000-0 10000-3 0 9999',
'2 39620 65.6759 35.9755 0011670 324.9338 289.9534 2.13103291 43246'
],
info: {
lng: -124.83404516738146,
lat: 32.070522714505586,
elevation: 81.2241916805502,
azimuth: 251.01601040118692,
range: 19217.756476304672,
height: 19161.979896618526,
velocity: 3.9490073154305385
}
},
{
tleArr: [
'GSAT0203 (GALILEO 7)',
'1 40544U 15017A 19284.43409211 -.00000061 00000-0 00000+0 0 9996',
'2 40544 56.2559 48.3427 0003736 223.0231 136.9337 1.70475323 28252'
],
info: {
lng: -117.86836105927033,
lat: 29.08239877156373,
elevation: 83.16839172166615,
azimuth: 183.67559090645165,
range: 23256.47316878015,
height: 23221.387218003325,
velocity: 3.6703580049175333
}
}
]
Basic TLE getters
In addition to the powerful functions above, there are also helpful functions for getting specific information from a TLE itself.
For further reading, see Kelso's article.
Shared TLE for below examples.
const tle = `ISS (ZARYA)
1 25544U 98067A 17206.18396726 .00001961 00000-0 36771-4 0 9993
2 25544 51.6400 208.9163 0006317 69.9862 25.2906 15.54225995 67660`;
getSatelliteName(tle)
Returns the name of the satellite. Note that this defaults to 'Unknown' for 2-line TLEs that lack the satellite name on the first line.
import { getSatelliteName } from "tle.js";
getSatelliteName(tle);
-> 'ISS (ZARYA)'
getCatalogNumber(tle)
Returns the NORAD satellite catalog number. Used since Sputnik was launched in 1957 (Sputnik's rocket was 00001, while Sputnik itself was 00002).
- Range: 0 to 99999
import { getCatalogNumber } from "tle.js";
getCatalogNumber(tle);
-> 25544
getCOSPAR(tle)
Returns the COSPAR id string, aka international designator.
import { getCOSPAR } from "tle.js";
getCOSPAR(tle);
-> "1998-067A"
getClassification(tle)
Returns the satellite classification.
- 'U' = unclassified
- 'C' = classified
- 'S' = secret
import { getClassification } from "tle.js";
getClassification(tle);
-> 'U'
getIntDesignatorYear(tle)
Launch year (last two digits) (international designator), which makes up part of the COSPAR id.
Note that a value between 57 and 99 means the launch year was in the 1900s, while a value between 00 and 56 means the launch year was in the 2000s.
- Range: 00 to 99
import { getIntDesignatorYear } from "tle.js";
getIntDesignatorYear(tle);
-> 98
getIntDesignatorLaunchNumber(tle)
Launch number of the year (international designator), which makes up part of the COSPAR id.
- Range: 1 to 999
import { getIntDesignatorLaunchNumber } from "tle.js";
getIntDesignatorLaunchNumber(tle);
-> 67
getIntDesignatorPieceOfLaunch(tle)
Piece of the launch (international designator), which makes up part of the COSPAR id.
- Range: A to ZZZ
import { getIntDesignatorPieceOfLaunch } from "tle.js";
getIntDesignatorPieceOfLaunch(tle);
-> 'A'
getEpochYear(tle)
TLE epoch year (last two digits) when the TLE was generated.
- Range: 00 to 99
import { getEpochYear } from "tle.js";
getEpochYear(tle);
-> 17
getEpochDay(tle)
TLE epoch day of the year (day of year with fractional portion of the day) when the TLE was generated.
- Range: 1 to 365.99999999
import { getEpochDay } from "tle.js";
getEpochDay(tl
Related Skills
node-connect
338.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
83.6kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
338.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
83.6kCommit, push, and open a PR
