# map

A flat map of the world or a region with markers for a list of places and arcs between them.

The continents as a grid of dots or a solid fill on an Equal Earth projection, fitted to the box with no frame or ocean unless asked. Each place is a round marker; the one under the pointer or in focus grows and gets a ring. Arcs between places bow towards the north and draw themselves in once the map scrolls into view.

Module `data`, category Maps and data. Import `@dioramajs/data/map`. [Source](https://github.com/MasterKurosava/diorama/blob/main/packages/data/src/map.ts)

A dotted world map with the partner cafes of a coffee roaster, and arcs drawn in from its Lisbon roastery.

```html title="index.html"
<div class="cafes-stage">
  <div class="cafes" data-dio="map">
    <ul aria-label="Partner cafes, with green coffee shipped from the Lisbon roastery">
      <li id="lisbon" data-dio-lat="38.72" data-dio-lng="-9.14" data-dio-to="new-york sao-paulo melbourne tokyo cape-town"><a href="#lisbon">Lisbon roastery</a></li>
      <li id="new-york" data-dio-lat="40.72" data-dio-lng="-74.0"><a href="#new-york">New York</a></li>
      <li id="sao-paulo" data-dio-lat="-23.55" data-dio-lng="-46.63"><a href="#sao-paulo">Sao Paulo</a></li>
      <li id="cape-town" data-dio-lat="-33.92" data-dio-lng="18.42"><a href="#cape-town">Cape Town</a></li>
      <li id="tokyo" data-dio-lat="35.68" data-dio-lng="139.69"><a href="#tokyo">Tokyo</a></li>
      <li id="melbourne" data-dio-lat="-37.81" data-dio-lng="144.96"><a href="#melbourne">Melbourne</a></li>
      <li data-dio-lat="51.51" data-dio-lng="-0.13"><a href="/london">London</a></li>
      <li data-dio-lat="52.52" data-dio-lng="13.4"><a href="/berlin">Berlin</a></li>
      <li data-dio-lat="49.28" data-dio-lng="-123.12"><a href="/vancouver">Vancouver</a></li>
    </ul>
  </div>
</div>
```

## Usage

Put it on: an element with a list of places inside, or an empty element with `markers` pointing at a list elsewhere, sized with CSS.

`start()` registers `map`, so the attribute alone puts it on an element.

```html
<div class="map" data-dio="map"><ul><li id="ams" data-dio-lat="52.37" data-dio-lng="4.90" data-dio-to="nyc sin"><a href="/offices/amsterdam">Amsterdam</a></li><li id="nyc" data-dio-lat="40.71" data-dio-lng="-74.01"><a href="/offices/new-york">New York</a></li><li id="sin" data-dio-lat="1.35" data-dio-lng="103.82"><a href="/offices/singapore">Singapore</a></li></ul></div>
```

- `data-dio-lat`: Latitude of the place in degrees, -90 to 90.

- `data-dio-lng`: Longitude of the place in degrees, -180 to 180.

- `data-dio-to`: Ids of other places to draw arcs to, separated by spaces.

In page transitions: Fades with the page while settling from 98% of its size.

- Event `dio:marker`, detail `{ marker: Element | null; id: string | null }`: A marker lights up under the pointer, from a hovered legend item or a focused link, or goes dark (marker and id null). Bubbles.

## Params

| Name | Attribute | Type | Default | Description |
| --- | --- | --- | --- | --- |
| `markers` (rebuilds) | `data-dio-markers` | `string` | `'[data-dio-lat]'` | Selector of the places: inside the element, or in the document when none are inside. |
| `style` (rebuilds) | `data-dio-style` | `'dots' \| 'solid'` | `'dots'` | Land as a grid of dots, or as a solid fill of the land mask. |
| `region` (rebuilds) | `data-dio-region` | `'world' \| 'europe' \| 'americas' \| 'asia' \| 'africa' \| 'oceania'` | `'world'` | Part of the world to frame: world without Antarctica; europe; americas; asia; africa; oceania. The box shows more map around it. |
| `dots` (rebuilds) | `data-dio-dots` | `number` 40 to 400 | `160` | Dots across the width of the box, in the dots style. At most low 100, medium 130. |
| `center` | `data-dio-center` | `number` -180 to 180° | `0` | Moves the middle of the map east (positive) or west, in degrees of longitude. |
| `zoom` | `data-dio-zoom` | `number` 1 to 8 | `1` | Magnifies the region about its middle; 1 fits the whole region. |
| `color` | `data-dio-color` | `color` | `'#8792a8'` | Color of the sea, drawn only when `sea` is above 0. |
| `sea` | `data-dio-sea` | `number` 0 to 1 | `0` | Opacity of the sea dots or fill; 0 leaves the page background. |
| `land` | `data-dio-land` | `color` | `'#8792a8'` | Color of the land. |
| `marker` | `data-dio-marker` | `color` | `'#ff5a36'` | Color of the markers. |
| `arc` | `data-dio-arc` | `color` | `'#ff5a36'` | Color of the arcs. |
| `markerSize` | `data-dio-marker-size` | `number` 2 to 24 px | `8` | Diameter of a marker. |

Changing a param marked rebuilds re-runs the effect setup.

### Variants

- `style`: `dots`, `solid`
- `region`: `world`, `europe`, `americas`, `asia`, `africa`, `oceania`

## Inputs and frames

Reads [`delta`](/docs/api/inputs#input-delta), [`height`](/docs/api/inputs#input-height), [`opacity`](/docs/api/inputs#opacity), [`presence`](/docs/api/inputs#presence), [`reducedMotion`](/docs/api/inputs#input-reducedMotion), [`width`](/docs/api/inputs#input-width), [`y`](/docs/api/inputs#input-y). Draws only while something on it moves, then stops. Only while the arcs draw in and for a few frames as a marker lights up or goes dark; none at rest. See [how a frame is decided](/docs/concepts/frames).

## Reduced motion and touch

With reduced motion it shows a still frame: motion inputs are zero and time stands still. Arcs stand drawn from the first frame and markers light up without easing.

Runs on every device. Nothing hovers: a tap on a marker works as a click on its link.

```ts
import { start } from '@dioramajs/diorama'

start({ effects: { map: { reducedMotion: 'off' } } })
```

## Cost and quality

Loads 5.0 KB the first time a page uses it. GPU: Three draw calls: all dots (or the land mesh), all markers and all arcs. Memory: About 12 bytes per dot (under 150 KB at 160 across), or a 260 KB land mask texture for `solid`.

- low: 100 dots across.
- medium: 130 dots across.

See [the quality plugin](/docs/effects/quality).

## Recipes

### A store locator with a visible list

Keep the stores in a list next to the map and point `markers` at its items. Hovering an item lights its marker and a click on a marker follows the item’s link. The map itself is `aria-hidden`: the list already says everything it shows.

```html
<div
  class="map"
  data-dio="map"
  data-dio-region="europe"
  data-dio-style="solid"
  data-dio-markers="#stores li"
  aria-hidden="true"
></div>
<ul id="stores">
  <li data-dio-lat="48.86" data-dio-lng="2.35">
    <a href="/stores/paris">Paris</a>
  </li>
  <li data-dio-lat="41.39" data-dio-lng="2.17">
    <a href="/stores/barcelona">Barcelona</a>
  </li>
</ul>
```

### A Pacific view with the sea drawn in

`center` moves the middle of the map east or west, so 150 puts the Pacific in the middle. `sea` draws the sea in `color` at that opacity: faint dots in the dots style, a fill in the solid one.

```html
<div
  class="map"
  data-dio="map"
  data-dio-center="150"
  data-dio-sea="0.2"
  data-dio-color="#3a4a66"
></div>
```

`dio:marker` fires on the map each time a marker lights up or goes dark, with the element of the place in `detail.marker`. Use it for a tooltip or for the address of the store under the pointer.

## Notes

The map is an Equal Earth projection of the Natural Earth land mask (public domain), the same data as `globe`, loaded once for both. The region always fits the box, and a box wider or taller than the region shows more map around it. Antarctica is left out.

It draws only while the arcs draw in, once when the map scrolls into view, and for a few frames as a marker lights up. Under reduced motion the arcs stand drawn and markers light up without easing. Nothing hovers on touch screens, so a tap on a marker works as a click.

Dots take about 12 bytes each, under 150 KB at the default 160 across; `solid` keeps a 260 KB land mask texture on the GPU instead. The `low` tier draws 100 dots across.

## Credits

Land data: Natural Earth (public domain)

## Related

- [chart](/docs/effects/chart.md): A plain HTML table or definition list drawn as an animated chart that grows in on scroll.
- [globe](/docs/effects/globe.md): An interactive globe of land dots with markers and arcs for a list of places.
- [graph](/docs/effects/graph.md): A list or a table of links drawn as a network graph: partners, integrations, teams, knowledge maps.
- [heatmap](/docs/effects/heatmap.md): A table drawn as a heatmap: a matrix of rows and columns, or a calendar of days like a contributions chart.
- [counter](/docs/effects/counter.md): Stats count up to their value on real 3D mechanics: odometer drums, slot machine reels or flip cards.
- [split-flap](/docs/effects/split-flap.md): A departure board: each character flips through a drum of letters to its own, on view and whenever the site changes the text.
- [Performance and quality](/docs/guides/performance.md)
- [Reduced motion](/docs/guides/reduced-motion.md)
