Sansar Maps docs · Sky view

Sansar Maps · embedding

Embed the sky view

The real sky for any place and moment, drawn with WebGL 2: the atmosphere and twilight, 117,000 catalogue stars and 3.4 million deep ones, the Milky Way, the Sun, Moon and planets, deep-sky objects, satellites, constellations in 50 cultures, and information drawn in the sky. Put it in a page with an iframe, or build on the SkyView module.

The iframe: /embed.html

A bare sky view, set up entirely by URL parameters, that the page around it can drive with messages:

<iframe src="http://localhost:8080/embed.html?lat=40.71&lon=-74.01&projection=dome"
        title="The sky over New York" style="width:480px;height:480px;border:0;border-radius:50%"></iframe>
ParameterDefaultMeaning
lat, lon, elevationGreenwichThe observer (degrees, metres).
time, rate, tznow, 1The moment (ISO 8601 or now), its speed (1 real time, 0 paused, 3600 an hour a second), and the IANA time zone for times drawn in the sky.
projectionstereographicstereographic, perspective, fisheye, equirectangular, or dome (an all-sky fisheye looking straight up, with a flat horizon).
az, alt, fov180, 30, 100Where the view looks, and its field across the smaller side (degrees).
target, track—, 1Point at sun, moon or a planet, and follow it.
show, hide—Comma-separated layers to turn on or off: show=equatorialGrid,constellationArt.
labels, constellations, grid, ground, atmosphere—Shortcuts: 1 or 0.
bortle, landscape3, hillsLight pollution (1–9); hills, flat or none.
twinkle, satellites, deepStars, interactive, transparent1, 1, 1, 1, 0Star twinkle; the satellite layer (elements from this server); the deep-star tiles; mouse and touch; a transparent background.
night, nightDim0, 0Red night mode (every pixel red-only), and its dimmer (0 full red to 1 darkest).
ar0AR mode, to lay over a camera video.
culturewesternA sky culture: chinese, maori, norse, …
theme—A URL-encoded JSON theme.
dir, lang—The page’s writing direction and language, as a host app in a right-to-left language sets them.

Messages

The parent page sends { type: 'sky:…', … } with frame.contentWindow.postMessage(message, '*'); the embed answers on the parent window. The iframe example drives all of them.

MessageFieldsDoes
sky:setlat, lon, elevation, timeZone, time, rate, view, animate, layers, options, theme, skyCulture, lookAtAny of them: the observer, the moment, the view ({ az, alt, fov }, eased with animate), layers, options ({ bortle, nightMode, … }), the theme, a sky culture, or a target to turn to.
sky:annotatespecDraws an annotation; replies sky:annotated { id }.
sky:removeAnnotationidRemoves one.
sky:clearAnnotationsgroup?Removes all, or one group.
sky:orientationrotation, fov?, screenAngle?Drives the view from a device orientation (see setOrientation); rotation: null lets go.
sky:getState—Replies sky:state { state }.

From the embed: sky:ready { state } once everything has loaded, sky:select { object: { kind, id, name } | null } when the reader taps something, sky:annotation { id, annotationType, group } when an annotation is tapped, and the replies above.

frame.contentWindow.postMessage({ type: 'sky:set', time: '2026-08-12T21:30:00Z', view: { az: 45, alt: 40, fov: 90 }, animate: true }, '*');
frame.contentWindow.postMessage({ type: 'sky:annotate', spec: { type: 'pointer', target: 'saturn', text: 'Saturn' } }, '*');
addEventListener('message', (e) => { if (e.data?.type === 'sky:select') console.log(e.data.object); });

SkyView

import { SkyView } from 'http://localhost:8080/sky/skyview.js';
const sky = new SkyView(document.getElementById('sky'), {
  lat: -33.87, lon: 151.21,             // Sydney
  time: 'now',                           // or a Date, milliseconds or an ISO string
  az: 180, alt: 30, fov: 100,
  layers: { constellationArt: true },
});
await sky.firstSky;                       // the first frame with stars (~1.5 s on a phone): hide a splash here
await sky.ready;                          // everything loaded: the full catalogue, deep-sky objects, the Milky Way
sky.on('select', (obj) => console.log(obj?.name));

The view fills its container (it adds two canvases, keeps them sized with a ResizeObserver, and makes the container position: relative if it was static). It needs WebGL 2 with float render targets, which every current desktop and phone browser has. Data load in stages, the first sky first; the modules for annotations, deep stars and constellation art load when they are first used. The canvas is focusable, labelled and keyboard-driven (arrows, + and −).

Options

OptionDefaultMeaning
lat, lon, elevation, timeZoneGreenwich, nullThe observer; the time zone for times drawn in the sky.
time, rate'now', 1The moment and its speed. With 'now' the view follows the clock.
projection'stereographic'stereographic (natural wide angle), perspective (a camera), fisheye (to 360°), equirectangular.
az, alt, fov, roll180, 28, 100, 0The view, in degrees; fov spans the smaller side. minFov 0.01, maxFov by projection.
layerssee LayersWhich layers are drawn.
bortle3Light pollution, Bortle 1 (pristine) to 9 (inner city): the sky’s brightness and how many stars show.
landscape'hills''hills', 'flat', 'none', or your horizon as [[azimuth, altitude], …].
twinkle, refraction, turbiditytrue, true, 1Scintillation; atmospheric refraction; haze.
starBrightness, starSize, blackPoint1, 1, 1Display tweaks; blackPoint: 0 turns off the dark-sky black point.
interactive, keyboardtrue, trueDrag, zoom, pinch, tap; arrow keys.
autoRender, maxFps, idleFps, twinkleFpstrue, 60, 30, 0autoRender: false draws only when you call render() (in step with a 3D engine). At rest the view draws on demand; twinkleFps (≤ 10) keeps stars twinkling on a wall display.
satellites, satelliteGroups, apiBasetrue, 'stations,visual', the module’s serverSatellites with elements from this server (/api/satellites/elements).
nightMode, nightDimfalse, 0Red night mode and its dimmer.
ar, transparent, preserveDrawingBufferfalseAR mode; a transparent canvas; keep the buffer for toDataURL.
pixelRatio, adaptiveResolution, minPixelRatio, qualityauto, true, 0.5, 'auto'Resolution; while frames are slow the sky canvas drops resolution (labels stay sharp); the quality governor (0–5, see getQuality()).
deepStars, deepStarSource, deepStarBudgetMBtrue, /data/deepstars/, 32The deep-star tiles.
skyCulture'western'The sky culture drawn.
themenullA partial theme.
yourViewnull (the whole sky)The directions the observer can see, { ranges: [[fromAz, toAz], …], minAlt } (each range clockwise, so [300, 60] runs through north); with the outsideView layer the rest of the horizon is shaded. /sky/view.js has the in-view math (inView, trackInView, passInView); plan() takes the same view and ranks what is up inside it first.
labelDensity, locale, compassLabels, deepSkyName0, nullMore or fewer labels (−1…1); the language of drawn times; the eight compass letters in your language; deep-sky names in your language (a function or a map).
formatTime, hourCycle—, the locale’sHow times in the sky read (path ticks, horizon marks): your own formatter, or 'h23' / 'h12'.
reducedMotionthe system’strue: no twinkle, flights become cuts, nothing pulses.
moonTexture, starTrails, starTrailSeconds, exactFrames'auto', true, 2, falseThe 4k Moon only when zoomed in ('full': always); star trails while time runs fast; recompute the planets every frame.

Layers

sky.setLayers({ … }) with any of these booleans (defaults in brackets): stars (on), starNames (on), constellations (on), constellationNames (on), constellationArt (off: each culture’s figure artwork as a faint engraving), asterisms (off), boundaries (off), planets, planetNames, sun, moon (on), deepSky, deepSkyNames (on), milkyWay, zodiacalLight, atmosphere, ground, cardinals, labels (on), satellites, satelliteNames, meteorShowers (on), azimuthalGrid, equatorialGrid, ecliptic, equator, meridian, galactic, horizonLine (off), zodiac and lunarMansions (off: the culture’s zodiac band and lunar mansions; getSkyCulture() says which it has), landmarks (on: what setLandmarks gave) and outsideView (on: the horizon outside yourView shaded).

Methods

MethodDoes
setLocation({ lat, lon, elevation, timeZone }) · getLocation()Moves the observer.
setTime(t, { rate }) · setRate(r) · getTime()The moment ('now' follows the clock again) and its speed; getTime() → { time, rate, live }.
setView({ az, alt, fov, roll, projection }, { animate, duration }) · getView()Where the view looks.
pan(dAz, dAlt, { animate }) · zoomBy(factor, { animate }) · animateTo({ az, alt, fov }, ms)Turn, zoom (2 = twice as close), fly (eased; a cut with reduced motion).
lookAt(target, { fov, duration, track })Turns to 'mars', { alt, az } or an object descriptor; returns false if it has no direction.
pick(x, y, radius = 16) · select(obj, { center, track, fov })The object under a CSS pixel ({ kind, id, name, ref, … }), and selecting it (a ring, and a path for satellites); emits select.
directionOf(ref) · limitingMagAt(enu)An object’s apparent direction (a unit ENU vector); the faintest star visible in a direction.
setLayers({ … }) · getLayers() · setOptions({ … })Layers and options (bortle, landscape, night mode, AR, deep stars, …).
setTheme(theme) · getTheme()The look of labels, lines and symbols (Theme).
annotate(spec) · clearAnnotations(group?) · getAnnotations() · describeAnnotations()Information drawn in the sky.
setInsets({ top, right, bottom, left }) · setOccluders([{ x, y, w, h }])Room for your interface.
setLandmarks([{ id, text, az, kind }]) · getLandmarks()Names on the horizon at their azimuth, standing on the skyline (kind 'town', 'airport' or 'lake'; first in the list wins a crowded spot); the landmarks layer. /sky/landmarks.js has distanceKm, bearingDeg and pickLandmarks to choose them from /data/map/landmarks/.
setOrientation(rotation, { fov, screenAngle }) · SkyView.arFieldOfView(opts)Drives the view from a device orientation (a quaternion [x, y, z, w], a 3×3 matrix or device axes in ENU) with no gimbal lock; null hands it back to touch. The field matching a camera video.
setDeepStarSource(source) · findDeepStar(id) · getDeepStarStats()Deep stars.
setSkyCulture(culture, { names, translate }) · getSkyCulture()Sky cultures.
setTexture('milkyway' | 'moon', src)Your own Milky Way or Moon image (URL, Blob, bitmap or canvas); null restores the built-in one.
describeView()What is in view, for screen readers and guides (Describing the view).
getState()Time, location, view, layers, the Sun and Moon, the sky’s brightness (mag/arcsec²) and the naked-eye limit, the selection, night mode, AR and culture.
sampleColor(alt, az) · renderPanorama({ width, azimuthLeft, labels, ground }) · snapshot()The sky’s colour in a direction (sRGB 0–1); a 360°×180° panorama canvas; a PNG data URL of the view.
getStats() · getQuality() · render() · destroy()Frame statistics; the quality governor’s level; draw now; free the GPU.

Events

const off = sky.on(name, fn) returns a function that removes the listener; sky.off(name, fn) does too.

EventPayloadWhen
firstsky{ ms, sinceStart }The first frame with stars and the horizon (also the sky.firstSky promise).
readythe viewEverything has loaded (also sky.ready).
selectdescriptor or nullA tap, a click or select().
hoverdescriptor or nullThe mouse over an object.
annotation{ id, type, group, spec, x, y }A tappable annotation was tapped.
view · time · location · layers · themethe new valueAfter each change.
framethe viewAfter each frame drawn.
stars · satellites{ loaded, count } · the listThe full catalogue, or satellite elements, arrived.
skyculture{ id, name }A culture was drawn.
qualitygetQuality()The quality governor changed level.

Theme, night mode and AR

setTheme() deep-merges over the current theme (setTheme(null) restores the defaults). The app passes its design tokens this way, so the sky’s typography matches the interface:

sky.setTheme({
  fonts: { serif: '"Sky Map Serif", Georgia, serif', sans: '"Sky Map Sans", system-ui, sans-serif' },
  labels: {
    constellation: { family: 'serif', size: 11, letterSpacing: 3, transform: 'uppercase', color: 'rgba(150,168,214,.64)' },
    star: { family: 'serif', italic: true, size: 13, color: 'rgba(214,218,230,.92)' },
  },
  lines: { constellations: [0.56, 0.65, 0.87, 0.3] },     // [r, g, b, a] in 0–1
  halo: { color: 'rgba(2,3,7,.66)', width: 3 },
  scale: 1.3,                                                // large text
});

Label styles: constellation, star, starDim, bayer, flamsteed, planet, sunMoon, deepSky, satellite, cardinal, cardinalMinor, grid, radiant, selection, annotation, annotationMuted, asterism, each { family, size, weight, color, letterSpacing, transform, italic, smallCaps }. Lines: constellations, boundaries, azimuthalGrid, equatorialGrid, ecliptic, equator, meridian, galactic, horizonLine, satellitePath, annotations, asterisms (with lineWidths by the same keys); symbols, halo, scale and art (the engraving ink). render/theme.js has every default.

Red night mode: setOptions({ nightMode: true, nightDim }) draws every pixel (sky, labels, annotations) with green and blue exactly 0, dimmable to about 15 %. AR mode: setOptions({ ar: true }) gives a transparent background over a camera video, with no ground, atmosphere or Milky Way, a perspective projection and labels tuned to read over video; arDistortion: { k1, k2 } matches the camera’s lens.

Annotations

sky.annotate(spec) draws information in the sky, where it belongs, and returns a handle { id, spec, update(patch), remove() }. Annotations follow the theme, fade in and out, work in every projection, turn red in night mode and, for pointers, callouts, rings, markers and horizon marks, can be tapped (the view emits annotation). The annotations example switches each on and off.

Common fields: type, id?, group? (for clearAnnotations(group)), label? (screen-reader text), color? (CSS), muted?, lineWidth?, dash? (true or [on, off]), interactive?. Targets: a body name ('mars'); a ref ({ kind: 'body' | 'star' | 'deepstar' | 'dso' | 'satellite' | 'constellation', … } from pick(), select or positions.search()); or a direction: { alt, az } (apparent), { ra, dec } (J2000, ra in hours), { raDeg, dec } or { enu: [x, y, z] }.

Saturn's path across the southern sky with hour ticks from 17:00 to 01:00
path — a target’s track between two moments, with hour ticks in the view’s time zone.
A rise mark with its time on the eastern horizon
horizonMark — where something rises or sets, with the time.
A circle round the Andromeda Galaxy and an arrow at the screen's edge pointing to Jupiter
pointer — a circle round the target; off screen, an arrow at the edge with the name and angle.
A callout beside Saturn: 39 degrees up in the south, magnitude 0.4
callout — a title and up to three lines beside an object, with a leader line.
A highlight ring round the Pleiades
ring — a highlight round a target or a screen point; it pulses unless reduced motion is on.
Numbered markers 1 to 3 on M31, M33 and the Double Cluster
marker — numbered markers, as tonight’s plan numbers its targets.
A camera frame around the Pleiades
fov — an eyepiece, binocular or camera field, or a Telrad, on a target or the view’s centre.
A dashed star-hop line from Alpheratz to the Andromeda Galaxy
polyline — any line in the sky, in horizontal or equatorial coordinates.
TypeFields
pathtarget, start, end (Date, ms or ISO), ticks? ('hour', minutes or false), tickLabels? (true, false or every n-th), arrow? ('end' | 'mid' | 'none'), text?; or points: [{ alt, az, label? } | { ra, dec, label? }] for a track of your own.
horizonMarkaz, event? ('rise' | 'set'), text?, time? (written in the view’s time zone when there is no text).
pointertarget, text?
callouttarget, title, lines? (up to 3), placement? ('auto', 'right', 'left', 'upper-right', …)
ringtarget or screen: 'center' | { x, y }, radiusDeg? or radiusPx?, pulse?, text?
markertarget, number?, text?
fovkind ('eyepiece' | 'binocular' | 'camera' | 'telrad'), target? (default: the view’s centre), fovDeg (true field), width, height (camera, degrees), rotation (camera: from celestial north through east), crosshair?, text?
polylinepoints: [[az, alt], …] (frame: 'horizontal', the default) or [[raDeg, dec], …] (frame: 'equatorial') or [{ alt, az, label? } | { ra, dec, label? }], closed?, arrow?, dash?
const dusk = Date.parse('2026-11-09T17:00:00Z'), dawn = Date.parse('2026-11-10T06:00:00Z');
sky.annotate({ type: 'path', target: 'saturn', start: dusk, end: dawn, group: 'plan' });
sky.annotate({ type: 'callout', target: 'saturn', title: 'Saturn', lines: ['39° up in the south'], group: 'plan' });
const m = sky.annotate({ type: 'marker', target: { ra: 0.7123, dec: 41.269 }, number: 1, text: 'M31', group: 'plan' });
m.update({ number: 2 });   sky.clearAnnotations('plan');

Insets and occluders

When your interface covers part of the view, setInsets({ top, right, bottom, left }) (CSS px) moves the view’s centre to the middle of what is left, with an off-axis projection so nothing is distorted: select, lookAt, flights, tracking, the AR reticle and off-screen pointers all use the uncovered part. setOccluders([{ x, y, w, h }]) lists rectangles (a clock, a dock, an open panel) that labels and callouts keep clear of; setOccluders([]) clears them. The annotations example sets both for its panel.

Deep stars

Beyond the 117,000 catalogue stars, the view streams about 3.4 million Gaia DR3 stars (to magnitude 12.5) as you zoom, from packed tile files read by HTTP range requests (tools/data/deepstars-format.md describes the SKYT1 format). setDeepStarSource(source) takes:

findDeepStar(id) finds a star by its Gaia DR3 source_id; getDeepStarStats() reports tiles, stars, requests and bytes.

The deep-star tiles are Gaia DR3 data (ESA/Gaia/DPAC) under CC BY-NC 3.0 IGO: non-commercial use only. For a commercial product, ask ESA, or pass deepStars: false or a deep-star source under another licence.

Sky cultures

await sky.setSkyCulture('maori') draws another culture’s figures and names (the IAU boundaries stay): any id in /data/skycultures/index.json (50 cultures from Stellarium, each with its own licence and authors), 'western' to go back, or a culture object of your own in the same format (tools/data/skycultures-format.md). { names: 'english' | 'native' | 'pronounce' | 'native+pronounce' } picks which name to show; { translate: (name, kind) => string } supplies your own. getSkyCulture() → { id, name, zodiac, lunarMansions }.

Describing the view

For screen readers and guides, describeView() returns the view’s direction (direction, az, alt, fov), the labelled objects drawn, most important first (objects: [{ kind, id, name, x, y }]), and the annotations on screen. The app turns it into a sentence (press V). The canvas has role="img" and a label; selections arrive as select events for you to announce.

Panoramas and 3D scenes

  1. A live layer: put a SkyView with projection: 'perspective', autoRender: false, interactive: false behind a transparent WebGL canvas, copy the 3D camera’s direction and field into sky.setView() each frame, then call sky.render(). The house example does this.
  2. An environment map: sky.renderPanorama({ width: 1024, azimuthLeft: 270 }) returns an equirectangular canvas whose left edge is azimuth 270°, which matches three.js’s EquirectangularReflectionMapping with north at −z.

For the lights, Sky.lighting() gives the Sun’s and Moon’s directions in three.js axes, their colours after extinction and their illuminance in lux, and sky.sampleColor(alt, az) matches fog to the horizon.