globe
An interactive globe of land dots with markers and arcs for a list of places.
Live preview needs WebGPU or WebGL 2. A dark globe of land dots with nine furniture showrooms as markers and arcs drawn from the Copenhagen workshop.
This example failed to draw.
Hover a marker, or press Tab to move between the places.
Usage
Put it on an element with a list of places inside, or an empty element with markers pointing at a list elsewhere. start() registers globe, 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.
npx @dioramajs/diorama add globe<div class="showrooms" data-dio="globe" data-dio-lat="40" data-dio-lng="10" style="touch-action: pan-y"> <ul aria-label="Showrooms, with deliveries from the Copenhagen workshop"> <li id="copenhagen" data-dio-lat="55.7" data-dio-lng="12.54" data-dio-to="stockholm berlin amsterdam london milan new-york tokyo" > <button type="button">Copenhagen</button> </li> <li id="stockholm" data-dio-lat="59.31" data-dio-lng="18.07" > <button type="button">Stockholm</button> </li> <li id="berlin" data-dio-lat="52.5" data-dio-lng="13.4"> <button type="button">Berlin</button> </li> <li id="amsterdam" data-dio-lat="52.36" data-dio-lng="4.89" > <button type="button">Amsterdam</button> </li> <li id="london" data-dio-lat="51.52" data-dio-lng="-0.11" > <button type="button">London</button> </li> <li id="milan" data-dio-lat="45.47" data-dio-lng="9.19"> <button type="button">Milan</button> </li> <li id="new-york" data-dio-lat="40.72" data-dio-lng="-74.01" > <button type="button">New York</button> </li> <li id="tokyo" data-dio-lat="35.65" data-dio-lng="139.7" > <button type="button">Tokyo</button> </li> <li id="melbourne" data-dio-lat="-37.8" data-dio-lng="144.98" > <button type="button">Melbourne</button> </li> </ul></div>import { start } from '@dioramajs/diorama'
const app = start()app.attach('.showrooms', 'globe', { style: 'dots', motion: 'draw', lat: 40, lng: 10, spin: 3.6, drag: true, scale: 0.8, color: '#0d1220', land: '#5b6b8c', marker: '#ffb547', arc: '#ffb547', atmosphere: '#6ea8ff', glow: 0.4, markerSize: 6, fps: 30,})import { start } from '@dioramajs/diorama'import globe from '@dioramajs/globe/globe'
const app = start()app.attach('.showrooms', globe({ style: 'dots', motion: 'draw', lat: 40, lng: 10, spin: 3.6, drag: true, scale: 0.8, color: '#0d1220', land: '#5b6b8c', marker: '#ffb547', arc: '#ffb547', atmosphere: '#6ea8ff', glow: 0.4, markerSize: 6, fps: 30,}))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; tooltips and the pointer cursor are up to the site.
Page transitions
Leaves by dithering its pixels away while shrinking to 96%, so its opaque sphere never switches to transparent mid-transition. How a flight flies.
Params
Every param is also an attribute, and both app.attach() and the handle take it by name.
| Param | Type | Default | Description |
|---|---|---|---|
markersrebuildsdata-dio-markers | string | '[data-dio-lat]' | Selector of the places: inside the element, or in the document when none are inside. |
datarebuildsdata-dio-data | string | '' | URL of JSON { markers: [{ id, lat, lng }], arcs: [{ from, to }] }, added to the places. |
latdata-dio-lat | number-90 to 90° | 20 | Latitude that faces the viewer; a change turns to it. |
lngdata-dio-lng | number-180 to 180° | 0 | Longitude that faces the viewer. |
spindata-dio-spin | number-72 to 72 deg/s | 3.6 | Turns on its own around the poles; 0 stands still. |
dragdata-dio-drag | boolean | true | Turn it by dragging, and with the arrow keys when it has a tabindex. |
stylerebuildsdata-dio-style | 'dots' | 'solid' | 'dots' | Land as dots, or as a solid fill of the land mask. |
motionrebuildsdata-dio-motion | 'draw' | 'flow' | 'draw' |
|
dotsrebuildsdata-dio-dots | number1000 to 20000 | 12000 | Dots over the whole sphere, about a third of them land up on land.At most low 4000, medium 8000 by quality tier. |
scaledata-dio-scale | number0.3 to 1 | 0.8 | Diameter as a fraction of the smaller side of the box. |
colordata-dio-color | color | '#0d1220' | Color of the sphere, the ocean. |
landdata-dio-land | color | '#5b6b8c' | Color of the land. |
markerdata-dio-marker | color | '#ffb547' | Color of the markers. |
arcdata-dio-arc | color | '#ffb547' | Color of the arcs. |
atmospheredata-dio-atmosphere | color | '#6ea8ff' | Color of the glow along the rim. |
glowdata-dio-glow | number0 to 1 | 0.4 | Strength of the glow along the rim. |
markerSizedata-dio-marker-size | number2 to 24 px | 6 | Diameter of a marker. |
fpsdata-dio-fps | number0 to 60 | 30 | Most frames a second while it spins on its own; dragging runs at full rate.At most low 20 by quality tier. |
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, presence, reducedMotion and size
. Draws at a steady rate while it is on screen and stops when it leaves. While it spins or its arcs flow, at most `fps` frames a second; at full rate while dragged, coasting, turning to a place, drawing arcs or lighting a marker. None at rest without spin or flowing arcs, and none off screen. 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. No spin, no coasting after a drag, arcs drawn whole at once without a flowing dash, and turns to a focused place made in one step. Dragging, arrow keys and lit markers still work: the visitor starts them.
Runs on every device. Nothing hovers: a tap on a marker works as a click. A finger turns the globe only when the element has `touch-action: pan-y` or `none`, otherwise the gesture scrolls the page.
To change what reduced motion does, patch it in start().
import { start } from '@dioramajs/diorama'
start({ effects: { globe: { reducedMotion: 'off' } } })Cost and quality
- Download
- 10.0 KB min+gzip the first time a page uses it, 3.6 KB of it data
- GPU
- Five draw calls: the sphere, all land dots as one instanced call, all markers, all arcs and the glow.
- Memory
- About 12 bytes per land dot (40 KB at 12000 dots), or a 260 KB land mask texture for `solid`.
- Frames
- Draws while on screen
It runs from the low tier up. Each tier changes this: The quality plugin picks the tier for each device.
| Tier | What changes |
|---|---|
low | 4000 dots, spin at 20 frames a second. |
medium | 8000 dots. |
Recipes
A store locator with a list beside it
Keep the places in a visible list next to the globe and point markers at its items. Hovering an item lights its marker, focusing its link turns the globe to the place, and a click on a marker follows the link. The globe itself is aria-hidden: the list already says everything it shows.
Live preview needs WebGPU or WebGL 2. A globe turned to Europe beside a list of six showrooms; hovering or focusing a city lights its marker and turns the globe to it.
This example failed to draw.
<div class="locator"> <div class="earth" data-dio="globe" data-dio-markers="#showroom-list li" data-dio-lat="48" data-dio-lng="8" data-dio-spin="0" aria-hidden="true" style="touch-action: pan-y" ></div> <ul id="showroom-list" class="list"> <li data-dio-lat="55.7" data-dio-lng="12.54"> <a href="https://www.openstreetmap.org/#map=15/55.700/12.540">Copenhagen</a> <span>Nordvest, Tue to Sat</span> </li> <li data-dio-lat="59.31" data-dio-lng="18.07"> <a href="https://www.openstreetmap.org/#map=15/59.314/18.072">Stockholm</a> <span>Södermalm, Wed to Sun</span> </li> <li data-dio-lat="52.5" data-dio-lng="13.4"> <a href="https://www.openstreetmap.org/#map=15/52.499/13.403">Berlin</a> <span>Kreuzberg, Tue to Sat</span> </li> <li data-dio-lat="52.36" data-dio-lng="4.89"> <a href="https://www.openstreetmap.org/#map=15/52.355/4.894">Amsterdam</a> <span>De Pijp, Tue to Sat</span> </li> <li data-dio-lat="51.52" data-dio-lng="-0.11"> <a href="https://www.openstreetmap.org/#map=15/51.524/-0.106">London</a> <span>Clerkenwell, Mon to Sat</span> </li> <li data-dio-lat="45.47" data-dio-lng="9.19"> <a href="https://www.openstreetmap.org/#map=15/45.472/9.187">Milan</a> <span>Brera, Tue to Sat</span> </li> </ul></div>dio:marker fires on the globe each time a marker lights up or goes dark, with the element of the place in detail.marker. Use it for a tooltip or to show the hours of the showroom under the pointer.
document.querySelector('.earth').addEventListener('dio:marker', (e) => { tip.textContent = e.detail.marker?.querySelector('a')?.textContent ?? ''})Routes from a JSON file
Hundreds of places do not belong in the markup. data loads { markers, arcs } and adds them to any places in the page, and arcs may join places from both. flow runs a dash along each arc again and again, from the place that names the arc to the other, which reads as freight, flights or traffic.
<div class="routes" data-dio="globe" data-dio-data="/data/routes.json" data-dio-motion="flow" data-dio-style="solid" data-dio-spin="1.8"></div>{ "markers": [ { "id": "rtm", "lat": 51.95, "lng": 4.14 }, { "id": "sin", "lat": 1.26, "lng": 103.84 }, { "id": "lax", "lat": 33.74, "lng": -118.27 } ], "arcs": [ { "from": "rtm", "to": "sin" }, { "from": "sin", "to": "lax" } ]}Brand colors
Every color is a param: the ocean in color, the land, markers, arcs and the glow along the rim. A light globe on a light page needs a darker marker and a stronger glow to keep its edge.
<div class="globe" data-dio="globe" data-dio-color="#d3d7cf" data-dio-land="#6f766f" data-dio-marker="#1f2224" data-dio-arc="#1f2224" data-dio-atmosphere="#ffffff" data-dio-glow="0.5" data-dio-marker-size="9"></div>Notes
It draws only while something moves: spin or flowing arcs at most fps frames a second, and a drag, a turn to a place or a marker lighting up at full rate. Set spin to 0 and keep draw for a globe that costs no frames at rest. The low tier draws 4000 dots and spins at 20 frames a second.
Land dots take about 12 bytes each, 40 KB at the default 12000 dots over the sphere. solid keeps a 260 KB land mask texture on the GPU instead. The land data is Natural Earth, in the public domain.
A finger turns the globe only with touch-action: pan-y or none on the element; otherwise it scrolls the page. Nothing hovers on touch screens, so a tap on a marker works as a click.
Under reduced motion the globe does not spin or coast, arcs appear whole without a flowing dash, and turns to a place happen in one step. Places inside the globe are hidden with it but keep their focus, so the keyboard reaches each marker through its button or link.
Credits
Land data: Natural Earth (public domain)