Sansar Maps docs · Library

Sansar Maps · library

The library

Everything the app and the server compute is a plain ES module in public/sky/, with no dependencies, that runs unchanged in the browser and in Node 18 or later. Import it from this server (http://localhost:8080/sky/…) or from the folder. Functions return structured data (codes, numbers, ISO times) for you to word; summary fields are English prose for callers who want it.

// In a page
import * as Sky from 'http://localhost:8080/sky/positions.js';
// In Node, from the project folder (data load from public/data/ as files)
import * as Sky from './public/sky/positions.js';

public/examples/positions-node.mjs uses positions, plan and events from Node with no server: node public/examples/positions-node.mjs 40.71 -74.01 now America/New_York.

positions.js

Where anything is, for a place and a moment: the Sun, Moon, planets and Pluto (Astronomy Engine: VSOP87 and ELP, with light time, aberration, nutation and topocentric parallax), the stars (HYG 4.1 with proper motion), deep-sky objects (OpenNGC), constellations and comets. Checked against JPL Horizons to within 18.4″ and astropy to within 3.8″.

const here = { lat: 48.857, lon: 2.352, elevation: 35 };
Sky.position('saturn', { ...here, time: '2026-11-09T21:00:00Z' });   // the Sun, Moon and planets need nothing loaded
await Sky.loadCatalogs();                                           // once: stars, deep sky, constellations
Sky.position('Vega', here); Sky.position('alpha Cen', here); Sky.position('M31', here); Sky.position('HIP 32349', here);
Sky.positions({ ...here, aboveHorizon: true, stars: 20 });              // { time, observer, objects }
Sky.riseSet('moon', { ...here, hours: 48 });                          // { events, rise, transit, set, alwaysUp, alwaysDown }
Sky.sunTimes({ ...here, timeZone: 'Europe/Paris' });                // sunrise, sunset, noon, the three twilights
Sky.moonPhase();  Sky.tonight(here);  Sky.lighting(here);  Sky.meteorShowers();  Sky.eclipses(here);
Sky.search('orion');  Sky.resolve('Pleiades');  Sky.toThreeDirection(alt, az);   // → { x: east, y: up, z: south }

The fields are those of /api/position and its neighbours: the HTTP routes are thin wrappers. Sky.Astronomy re-exports Astronomy Engine.

satellites.js and brightsats.js

import * as Sats from '/sky/satellites.js';
import { curate, brightPasses } from '/sky/brightsats.js';
const sats = await Sats.loadSatellites({ groups: 'stations,visual' });   // elements from this server, or Sats.parseSatellites(ommJsonOrTle)
const iss = sats.find((s) => s.id === 25544);
Sats.satellitePosition(iss, here);                           // { altitude, azimuth, rangeKm, heightKm, sunlit, visible, magnitude, subpoint }
Sats.predictPasses(sats, { ...here, hours: 24, visibleOnly: true });   // rise, culmination, set, the visible part
Sats.overhead(sats, here);  Sats.skyPath(iss, { ...here, start, minutes: 10 });   // alt-az points of its arc
brightPasses(curate(sats), { ...here, start: Date.now(), hours: 24, timeZone })  // the passes worth going out for, with worth and summary

SGP4 comes from satellite.js. A pass is visible when the satellite is sunlit while the observer’s Sun is more than 4° below the horizon. curate() keeps the stations, Hubble, bright payloads and rocket bodies, and fresh Starlink trains, and leaves out debris and docked modules. Pass times agree with skyfield to within 0.65 s.

comets.js

import * as Comets from '/sky/comets.js';
await Comets.loadComets({ maxMagnitude: 15 });               // MPC elements from /api/comets/elements; or setComets(parseMpcComets(text))
Comets.brightComets({ maxMagnitude: 12 });                    // brightest first
Comets.cometPosition('2P', { ...here, time });               // like position(), with the orbit and an estimated coma
Comets.findComet('Encke');  Comets.cometTrack(c, { start, days: 60 });

Once comets are loaded, positions.position('2P', …) and search find them too.

plan.js and plan-worker.js

Tonight’s plan: the night’s timeline on a 10-minute grid, the conditions (darkness, the Moon, the forecast’s cloud, transparency, seeing and dew), one verdict for the night (good, fair, poor, bad) with its best windows, and ranked targets with go / maybe / skip, reasons, the best time and where to look, and how each looks through your gear. A full plan takes 100–250 ms, so the app runs it in a worker.

import { plan, tonightVerdict, prepare } from '/sky/plan.js';
await prepare({ lat, lon });                                    // once: showpieces, doubles, Messier objects, variable stars
const p = plan({ lat, lon, timeZone, gear: ['eyes', 'binoculars-10x50'], bortle: 5, weather, horizon,
  preferences: { maxTargets: 10, experience: 'beginner' } });
p.verdict.rating;  p.verdict.windows;  p.targets[0].best;  p.targets[0].views;   // see /api/plan for the whole shape
tonightVerdict({ lat, lon, timeZone, weather });               // the verdict alone, in tens of milliseconds

// In a worker: the same, off the main thread
const worker = new Worker('/sky/plan-worker.js', { type: 'module' });
worker.postMessage({ id: 1, type: 'verdict', opts });           // or type: 'plan' | 'prepare'
worker.onmessage = ({ data }) => { data.id; data.ok; data.result; data.error; data.ms; };

weather is a /api/weather answer; gear takes preset ids from /api/gear or gear objects; horizon is [[az, alt], …]. The tonight widget is built on the worker.

events.js

import { events } from '/sky/events.js';
events({ lat: 51.48, lon: 0, start: '2026-11-09', days: 60, timeZone: 'Europe/London', horizon, minImportance: 40 })
  // → { events: [{ id, type, subtype, time, window, bodies, data, best, visibility, importance, summary }], counts }

Moon phases and supermoons; lunar and solar eclipses with local circumstances; meteor showers (the IMO working list) with radiant height, moonlight and expected rates; conjunctions and occultations (listed only when both are well up in a dark-enough sky here); oppositions, elongations, Mars’ closest approach, Venus’ greatest brilliancy; equinoxes and solstices; bright comets; Algol’s minima. Checked against USNO, NASA, the IMO, JPL Horizons and published Algol minima.

observing.js, gear.js and skybrightness.js

import { nightTimeline, parseHorizon } from '/sky/observing.js';
import { gearProfile, gearPresets, view, cameraInfo, GEAR_PRESETS } from '/sky/gear.js';
import { skyBrightness, nakedEyeLimit, bortleFromSqm } from '/sky/skybrightness.js';
nightTimeline({ lat, lon, timeZone });                         // sunset to sunrise: twilights, darkness, the Moon, segments
parseHorizon('0:5,90:12,180:3');                               // your horizon as [[az, alt], …]
gearProfile('dobsonian-200');                                  // eyepieces with magnification, true field, exit pupil
view({ kind: 'dso', magnitude: 3.4, sizeArcmin: [178, 63] }, 'binoculars-10x50', { luminance, altitude: 60 });
  // → { visible, margin, appearance: 'bright core', rating, framing, … }
skyBrightness({ lat, lon, time, altitude: 90, bortle: 5 });       // { mpsas, luminance, nelm, components, … }

alerts.js

import { alertCandidates } from '/sky/alerts.js';
alertCandidates({ lat, lon, timeZone, days: 7, weather, passes })
  // → { candidates: [{ id, kind, time, window, title, importance, reasons: [{ code, … }], tonight, summary }], summary }

What is worth an alert: bright passes, eclipses, close pairs, showers at their peak, comets, oppositions, each with its reasons. The app’s alerts and the server’s web push both pick from these.

find.js

import { loadFindIndex, find, visibility, titleOf } from '/sky/find.js';
await loadFindIndex();                                         // once; names in every language load in the background
find('betelgeus');                                             // [{ id: 'HIP 27989', name: 'Betelgeuse', kind, ref, score, matched, lang, title }]
find('osa mayor', { lang: 'es' })[0].title;                     // 'Osa Mayor'
find('plough');  find('c14');  find('what is a nebula');  find('25544', { satellites });
visibility(ref, { lat, lon, time });                           // up now, or when it rises

Any name in 38 languages, nicknames, designations as people type them, misspellings, showers, satellites, comets, asterisms and concepts; the results have positions.search()’s shape plus score, matched, lang and title. /api/search runs it on the server.

content.js

import * as C from '/sky/content.js';
await C.loadSkyCultureIndex();  await C.loadSkyCulture('maori');    // 50 cultures, each with its licence and authors
await C.loadNames('ja');  C.nameFor({ kind: 'star', hip: 91262 }, 'ja');   // names in 38 languages (Wikidata)
await C.imageFor('M31');                                     // { url, thumbUrl, title, credit, licence, licenceUrl, sourceUrl, … }
await C.loadShowpieces();  C.loadDoubles();  C.loadVariables();  C.loadCaldwell();
await C.searchPlaces('reykjav');  await C.nearestPlace(64.1, -21.9);   // offline places (GeoNames)
await C.loadPacks();  await C.loadCredits();                    // download packs; every credit and licence

stories.js

import { storyFor, storyId, loadStoryIndex } from '/sky/stories.js';
await storyFor('HIP 91262');        // { id, group, lang, title, tagline, whatItIs, howToSee, story, detail, facts, sources, … } | null
await storyFor(Sky.position('Vega', here), 'de');   // German when written, else English with lang: 'en'
storyId({ kind: 'satellite', id: 25544 });   // '25544'
await loadStoryIndex('en');          // 698 English entries: the Sun, Moon and planets, 330 stars, 179 deep-sky objects, 88 constellations, 22 showers, …

Each story lists its sources (SIMBAD, the IAU’s star-name catalogue, NASA, Wikipedia and Wikidata for facts, Ian Ridpath’s Star Tales, the IMO, AAVSO, ESO and others).

The guide engine (guide/index.js)

import { createGuide } from '/sky/guide/index.js';
import { libraryContext } from '/sky/guide/context.js';
import { english } from '/sky/guide/english.js';
const ctx = await libraryContext({ lat: 51.48, lon: 0, timeZone: 'Europe/London', time: Date.now() });
const guide = createGuide(ctx, { say: (await english()).timeZone('Europe/London') });
const a = await guide.ask('what is that bright one in the west?');
// → { intent, confidence, text, speech, actions: [{ type: 'fly' | 'annotate' | 'select', … }], followUps, subject, claims, data }

Answers questions about the sky in plain words, from the app’s own positions, plan, events and passes, with no network and no model; actions say what to draw in the sky. /api/guide/answer runs it on the server.

starhop.js

import { starHop, finderProfile, FINDERS, validateRoute } from '/sky/starhop.js';
import { loadStars } from '/sky/catalog.js';
const route = starHop({ ra: 283.40, dec: 33.03, id: 'M57' }, await loadStars(), { finder: 'finder-8x50', sqm: 20.4 });
// → { ok: true, finder, target, start, hops: [{ n, from, to, distanceDeg, paDeg, direction, … }], placement, totalDeg, summary }
//   or { ok: false, reason }

A route from a bright, easy star to the target in hops that each fit the finder’s field (a finder scope, a Telrad or binoculars: FINDERS), choosing stepping stones the finder shows comfortably and naming the pairs, triangles and lines on the way. The app draws it as charts and in the sky.

renderChart (app/features/chart/chart.js)

import { renderChart, loadChartData } from '/app/features/chart/chart.js';
const svg = await renderChart({ center: { ra: 83.8, dec: -5.4 }, fovDeg: 20, theme: 'print',
  marks: [{ type: 'target', ra: 83.82, dec: -5.39, label: 'M42' }, { type: 'circle', ra: 83.82, dec: -5.39, radiusDeg: 0.5 }] });

Atlas charts as SVG strings, in the manner of a paper star atlas: stars by magnitude, figures, boundaries, deep-sky symbols by convention, the graticule numbered at the edge; theme: 'night' (the app’s tokens) or 'print'; constellation: 'Ori' frames one constellation. No app dependency: browsers and Node. The printed observing list is built on it.

oal.js

import { toOAL, fromOAL, checkOAL } from '/sky/oal.js';
const xml = toOAL(entries, { observer: { name: 'Ada', surname: 'Lovelace' } });   // OpenAstronomyLog 2.1
const { entries, warnings } = fromOAL(xml);                                  // reads OAL 1.7, 2.0 and 2.1
checkOAL(xml);                                                                  // { ok, errors }

Observing logs in the exchange format SkySafari, DeepskyLog and AstroPlanner use. The entry shape is in the module’s header; the app keeps the same.

offline.js

import { offlineApi, OFFLINE_ROUTES } from '/sky/offline.js';
await offlineApi('/api/rise-set', { target: 'mars', lat: 38.7, lon: -9.1 });   // the server's answer, computed here, with offline: true

The API with no connection: 28 of the routes answered in the browser (or a worker), computed with the same library or, for satellite and comet elements and the weather, from the last answer kept; anything else throws an OfflineError (status 503). The app’s app.api() falls back to it.

Inside the app

Features of the app reach each other through one contract, public/app/README.md: the sky (app.sky), the store, strings, the kit, sheets, commands and hooks. The feature APIs a builder uses most:

FeatureAPI
planstate(), onChange(fn), plan({ window, maxTargets }), remaining(), lightPollution(), setLightPollution({ bortle } | { sqm } | null), openTonight()
gearactive(), list(), get(id), setActive(id), edit(id?); app event gear
listsall(), get(id), add(listId | null, item), remove(listId, itemId), on(fn), exportFile('json' | 'csv'), importFile(), …; app event lists
observeopen({ tab, target }), chart(target?), frame(target?), log(target?, { entry }), observed(key), entries(), store(); the log stays in IndexedDB skymap-observe and leaves the device only by export
guideopen({ focus }), ask(question), tour(id), on(fn); app event guide:answer
tourstart(id), stop(), pause(), resume(), next(), prev(), ambient({ signal })
aboutopen('about' | 'credits' | 'privacy' | 'accessibility'), close(), credits()

Deep links (and install shortcuts): /?open=tonight | point | search | settings | place | about | credits | privacy | accessibility, ?select=<name> (also shower:, asterism:, concept:, dso:, satellite:, comet:), ?ask=<question>, ?tour=tonight | season | milkyway | planets, ?mode=wall, ?lang=<tag>, and lat, lon, time, az, alt, fov, projection for the view: every view is a link.