# Atlas

<StatusBadge status="preview" /> `format: atlas` turns a :term[story]{id=story} into an
**atlas**: a map that stays in place while the text of each view scrolls by, the camera moving from
one view to the next. Every scene is a **view**: a camera, a text, and the markers, routes and
areas it shows. The base maps come from the Natural Earth data of `@recit/geo`, cut and projected at
build time: the reader never loads a tile, a font or a geocoder.

`recit dev` and `recit build` open an atlas like any other format, and a Récit site publishes one
with `@recit/site-stories` (`publish.entries`, `<StoryEmbed slug="…" />`), as the maps site of the
repository does (`sites/maps`). A single map inside another format is the
[`::map` block](/documentation/writing/maps). `@recit/atlas` is a preview: it stays outside the 1.0
and a minor version may change it.

## A minimal atlas

```md title="tour.md"
---
title: Lorem Tour
lang: en
format: atlas
projection: conic-conformal
layout: side
---

--- id=start camera=FR

# Lorem ipsum

Dolor sit amet, consectetur adipiscing elit.

--- id=paris camera=[1.4,48.4,3.3,49.3] duration=4s

## Lorem in Paris

Sed do eiusmod tempor incididunt ut labore.

::marker{lat=48.8566 lon=2.3522 label="Lorem"}

--- id=south center=43.6,3.9 zoom=5

## Dolor and Sit

::marker{lat=43.6047 lon=1.4442 label="Sit"}
::marker{lat=43.2965 lon=5.3698 label="Dolor"}
::route{from="Sit" to="Dolor" style=dashed reveal=draw}
```

The full example, in English and French with its JSON twin, is `atlas-tour`.

### The camera of a view

Each view says what it frames, on its separator line:

| Attribute               | What it frames                                                                   |
| ----------------------- | -------------------------------------------------------------------------------- |
| `camera=FR`             | a country, by its ISO 3166-1 code (alpha-2 or alpha-3)                           |
| `camera=world`          | the whole world, in Equal Earth                                                  |
| `camera=[w,s,e,n]`      | an extent in degrees: west, south, east, north                                   |
| `center=lat,lon zoom=5` | a center and a zoom from 1 (180° of longitude) to 12, each step halving the span |
| no camera               | the extent of the view's layers; a view with neither is an error                 |
| `duration=4s`           | how long the view lasts in a film made from the atlas                            |

An unknown code, an extent out of bounds or a zoom past 12 is refused with the line of the view.

### Layers

The layers of a view are written **together at the end of its text**, one per line. A layer line
anywhere else is an error with its line, so that the Markdown and the JSON twin stay equivalent.

| Directive                       | What it draws                                                          |
| ------------------------------- | ---------------------------------------------------------------------- |
| `::marker{lat lon label}`       | a place, by its coordinates; its label is the story's own text         |
| `::marker{place label}`         | a populated place by its name (`place="Lyon, FR"`), resolved offline   |
| `::route{from to style reveal}` | a great-circle line between two markers (by label) or `lat,lon` points |
| `::area{src label reveal}`      | a GeoJSON file beside the story, never a URL                           |

`style` is `solid`, `dashed` or `dotted`; `reveal=draw` traces a route as the view opens and
`reveal=fade` fades an area in. A route end resolves against the markers of its view, then of the
whole atlas.

`place=` names a place of the offline gazetteer of `@recit/geo` (Natural Earth populated places), as
in a [`::map`](/documentation/writing/maps): the atlas resolves it when it is built, without
network, and its label is the place's name unless `label=` is written, so `::route{from="Lyon"}`
joins `::marker{place="Lyon"}`. An unknown or ambiguous name is an error of its view. The JSON twin
keeps `place` as written.

### Reading it

- **Scrolling**: the view whose text crosses the middle of the screen is the active one; the camera
  interpolates the projection to it, then reveals its layers.
- **Keyboard**: the reader is one focusable region. Arrow Up and Down, Page Up and Down, Home and
  End move view by view; the buttons under the map do the same.
- **Reduced motion**: with `prefers-reduced-motion`, each view appears settled, without a move.
- **Languages**: the names of countries and regions come from `Intl.DisplayNames`. In a
  right-to-left language (`lang: ar`, as in `examples/atlas-tour/atlas-tour.story.ar.md`), logical
  CSS properties move the `side` text column to the inline-start side and flip the view navigation
  bar, while `<svg>` keeps `direction: ltr`: the projection never mirrors (north stays up, west
  stays left) and marker `<text>` labels keep their `start` anchor to the right of the dot. On
  desktop, the sticky map stage reserves the navigation bar's height so the « Made with Natural
  Earth » attribution stays visible across every view.

## Settings

In the front matter, or for every atlas of a project in the `atlas:` section of `recit.config.ts`
(the front matter wins, then the section, then the default):

| Setting      | Values                                                                                                                                                  | Default       |
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------- |
| `projection` | the projections of `::map`                                                                                                                              | `equal-earth` |
| `basemap`    | `land`, `admin0`, `admin1`, `none`                                                                                                                      | `admin0`      |
| `layout`     | `side`, `overlay`, `full`                                                                                                                               | `side`        |
| `worldview`  | `default` (the de facto borders of Natural Earth), or a point of view: `IN`, `MA`… ([maps](/documentation/writing/maps))                                | `default`     |
| `insets`     | `none`, or `auto`: Guadeloupe, Martinique, French Guiana, Réunion and Mayotte in a column beside an atlas of `FR` ([maps](/documentation/writing/maps)) | `none`        |

```ts title="recit.config.ts"
import { defineConfig } from "recit/config";

export default defineConfig({
  atlas: { projection: "conic-conformal", basemap: "admin1", layout: "overlay" },
});
```

`side` puts the text in a column beside the map, `overlay` in cards over it, `full` under it.
`basemap: "admin1"` draws the regions of the country a view shows. The scene attribute `camera=` is
in [the camera of a view](#the-camera-of-a-view), and `duration=` sets the length of a view in a
film.

## The JSON twin

Every atlas has a typed JSON form, `kind: "story"` with `format: "atlas"`, checked by
`AtlasSourceSchema` of `@recit/core/schema` and its JSON Schema
(`https://recit.dev/schema/v1/atlas.json`, `x-recit-stability: preview`). `recit convert` turns one
into the other, and the round-trip test checks that both compile to the same views. In JSON, a view
is `{ id, camera, layers?, body?, notes?, durationMs? }`; its layers are the scene's `layers`.

| Key                 | Type / values                                           | Effect                                                                                                                                                                   |
| ------------------- | ------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `scenes`            | `AtlasSceneSource[]`                                    | Required in `kind: "story"`. Views of the atlas, in scrolling order (`---` separators in Markdown).                                                                      |
| `scenes.id`         | `string` (non-empty)                                    | Required. Stable view identifier across languages (`--- id=…`).                                                                                                          |
| `scenes.camera`     | `"world"`, `"FR"`, `[w, s, e, n]` or `{ center, zoom }` | Framing of the view (`camera=` or `center=lat,lon zoom=N`, with `zoom` from `1` to `12`). Omitted, a later view keeps the previous camera and the first frames `layers`. |
| `scenes.durationMs` | `integer` (`> 0`)                                       | Optional shot duration in milliseconds for the bridge to a film (`duration=4s` ↔ `4000`).                                                                                |
| `scenes.layers`     | `AtlasLayer[]`                                          | Optional `marker`, `route` and `area` layers parsed from the closing layer lines of the view.                                                                            |
| `scenes.body`       | `string` or `Record<string, string>`                    | Optional Markdown or MDX prose of the view before its closing layer lines ([Scenes](/documentation/writing/scenes#in-the-json-twin)).                                    |
| `scenes.notes`      | `string` or `Record<string, string>`                    | Optional author notes (`:::notes`; [Scenes](/documentation/writing/scenes#in-the-json-twin)).                                                                            |
| `scenes.attrs`      | `Record<string, string \| number \| boolean>`           | Optional separator attributes (`--- key=value`) other than `id`, `camera`, `center`, `zoom` and `duration`.                                                              |

## Commands

| Command                                                   | What it does                                                  |
| --------------------------------------------------------- | ------------------------------------------------------------- |
| `recit dev tour.md`                                       | the atlas with live reload                                    |
| `recit build tour.md -o dist`                             | prerendered in one language (`--locale fr`), nothing off-site |
| `recit validate tour.md`                                  | the story against its schema, with the line of each problem   |
| `recit convert tour.md --to json -o tour.json`            | the JSON twin; `--to md` goes back to Markdown                |
| `recit convert tour.md --to deck -o tour.deck.md`         | one slide per view                                            |
| `recit convert tour.md --to film -o tour.film.json`       | one map shot per view, for `recit render`                     |
| `recit convert tour.md --to webstory -o tour.webstory.md` | one 9:16 card per view                                        |
| `recit convert events.md --to atlas -o events.atlas.md`   | the map view of a calendar                                    |

A view with no camera and no layer, an unknown country code, an extent out of bounds or a zoom past
12 are errors with the file and the line, in the form `✖ tour.md:12 — …`. Every command and its
flags are in [the CLI reference](/documentation/reference/cli).

## Bridges

Closed bridges, from `@recit/atlas/bridge`. The atlas owns its outgoing bridges; the one that comes
in, from a calendar, is the exception written on the [Bridges](/formats/bridges#who-owns-a-bridge)
page.

| From → to        | Function          | Command                               |
| ---------------- | ----------------- | ------------------------------------- |
| atlas → deck     | `atlasToDeck`     | `recit convert tour.md --to deck`     |
| atlas → film     | `atlasToFilm`     | `recit convert tour.md --to film`     |
| atlas → webstory | `atlasToWebstory` | `recit convert tour.md --to webstory` |
| calendar → atlas | `calendarToAtlas` | `recit convert events.md --to atlas`  |

- **To a deck**: each view becomes a slide with the same `id`, its text first, then a `:::map`
  framing what the camera framed (a centre and a zoom become their extent) with the view's layers. A
  view too dense for a slide is refused with its line, never summarised; a `worldview` other than
  `default` becomes the `worldview=` of each map, and `layout` is dropped with a warning. A view
  without a camera is framed on its markers, its `place=` markers included when the bridge is given
  the offline gazetteer (`places`, which `recit convert` passes); without it, such a view shows the
  world with a warning.
- **To a film**: each view becomes a `map` shot. The camera moves from the view before to its own by
  interpolating the projection, then the routes and areas appear as their `reveal` says; the text is
  the voice-over, and `duration=` the length of the shot. The base map rides in the film, so
  `recit render` reads no asset.
- **To a webstory story**: a title card, then each view becomes a 9:16 card with the same `id`, its
  text then its `:::map`, `duration=` as the card's `dur`. A view beyond the density of a card (40
  words, 5 bullets) is refused with its line; views beyond the 30 cards of a story are left out with
  a warning. An area's file is written from the folder of `-o`, which must be the atlas's folder or
  above it: a story reads no file outside its folder.
- **From a calendar** (`calendarToAtlas`, which reads the calendar model from
  `@recit/time/calendar`): the optional map view of a `calendar`. Its events whose place has a `geo`
  (`[lat, lon]`) become an atlas: a first view with all of them, then a view per event ahead,
  centred on its place, with its title, its date and its place. An event without `geo` stays off the
  map with a warning: nothing is geocoded, nothing is fetched.
