Diorama

Made for a big screen.

This site is one 3D scene, built for a computer: a wide window and a mouse. Open dioramajs.dev on a desktop or a laptop to see it.This site is one 3D scene, built for a wide window. Make this one wider, or open dioramajs.dev on a larger screen.

GitHub

DioramaDocs

map

Maps and data

@dioramajs/data/mapSource

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

View as Markdown
On this page

Live preview needs WebGPU or WebGL 2. A dotted world map with the partner cafes of a coffee roaster, and arcs drawn in from its Lisbon roastery.

This example failed to draw.

Hover a marker or press Tab through the hidden list. Switch style to solid and region to europe or asia.

Hover a marker, or press Tab to move between the cafes.

Params of map
style

region

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. The tabs below are the example above, with the values you set.

To change its code, copy the source into your effects folder; the copy replaces the built-in.

Terminal window
npx @dioramajs/diorama add map
<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>
import { start } from '@dioramajs/diorama'
const app = start()
app.attach('.cafes', 'map', {
style: 'dots',
region: 'world',
center: 0,
zoom: 1,
color: '#8792a8',
sea: 0,
land: '#8792a8',
marker: '#ff5a36',
arc: '#ff5a36',
markerSize: 8,
})
import { start } from '@dioramajs/diorama'
import map from '@dioramajs/data/map'
const app = start()
app.attach('.cafes', map({
style: 'dots',
region: 'world',
center: 0,
zoom: 1,
color: '#8792a8',
sea: 0,
land: '#8792a8',
marker: '#ff5a36',
arc: '#ff5a36',
markerSize: 8,
}))

Markup it reads

  • 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.

Events

It dispatches these on its element; they bubble.

  • 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.

Page transitions

Fades with the page while settling from 98% of its size. How a flight flies.

Params

Every param is also an attribute, and both app.attach() and the handle take it by name.

ParamTypeDefaultDescription
markersrebuildsdata-dio-markersstring'[data-dio-lat]'Selector of the places: inside the element, or in the document when none are inside.
stylerebuildsdata-dio-style'dots' | 'solid''dots'Land as a grid of dots, or as a solid fill of the land mask.
regionrebuildsdata-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.
dotsrebuildsdata-dio-dotsnumber40 to 400160Dots across the width of the box, in the dots style.At most low 100, medium 130 by quality tier.
centerdata-dio-centernumber-180 to 180°0Moves the middle of the map east (positive) or west, in degrees of longitude.
zoomdata-dio-zoomnumber1 to 81Magnifies the region about its middle; 1 fits the whole region.
colordata-dio-colorcolor'#8792a8'Color of the sea, drawn only when sea is above 0.
seadata-dio-seanumber0 to 10Opacity of the sea dots or fill; 0 leaves the page background.
landdata-dio-landcolor'#8792a8'Color of the land.
markerdata-dio-markercolor'#ff5a36'Color of the markers.
arcdata-dio-arccolor'#ff5a36'Color of the arcs.
markerSizedata-dio-marker-sizenumber2 to 24 px8Diameter of a marker.

Params marked rebuilds re-run the effect's setup when they change, so set them before the element shows.

Inputs and frames

It reads delta, height, opacity, presence, reducedMotion, width and 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. How a frame is decided.

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.

To change what reduced motion does, patch it in start().

import { start } from '@dioramajs/diorama'
start({ effects: { map: { reducedMotion: 'off' } } })

Cost and quality

Download
5.0 KB min+gzip 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`.
Frames
Idle at rest

It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.

TierWhat changes
low100 dots across.
medium130 dots across.

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.

<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.

<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)