SDK JS
    Preparing search index...
    • Sunrise/sunset/twilight/golden-hour times for one day at a place — for driving a widget's timeline bands and presets. Thin wrapper over the vendored SunCalc getTimes with the SDK's (lng, lat) argument order.

      Parameters

      • date: Date

        Any instant on the day to compute (a Date; the result events are full Dates).

      • lng: number

        Longitude in degrees (−180..180).

      • lat: number

        Latitude in degrees (−90..90).

      • height: number = 0

        Observer height above the horizon in metres; raises the apparent horizon so sunrise/sunset come slightly earlier/later. Default 0.

      Returns SolarTimes

      A SolarTimes record keyed by SolarTimeKey (sunrise, sunset, dawn, dusk, goldenHour, solarNoon, nadir, …); each value is a Date. Events that do not occur (polar day/night) come back as Invalid Date — test with isValidSolarTime.

      Does not throw.

      import { solarTimes, isValidSolarTime } from '@bitruvius/sdk-maplibre';
      const t = solarTimes(new Date(), -73.98, 40.75);
      if (isValidSolarTime(t.sunset)) console.log('sunset', t.sunset.toLocaleTimeString());