Globe

Pro

A 3D globe of real country shapes that wears your theme. Hairline borders, markers from the Map, routes that draw themselves in, countries to pick and a real day and night, with drag and inertia, on a plain canvas with no dependencies.

Drag or use the arrow keys to turn it.

Installation#

# One-time setup (tokens + lib helpers)npx koalaui-cli@latest init# Activate your Pro license (once per machine)npx koalaui-cli@latest login <key># Add this component (its dependencies come along)npx koalaui-cli@latest add globe

Usage#

This example is part of Koala UI Pro

The preview is yours to explore. Its code comes with a Pro license, paid once and used in every project.

Have a license? Unlock it here

The Globe is square and fills its width, so cap it with a max-w-*. It shares the Map's coordinates, [longitude, latitude], and its markers: anything that works inside MapMarker, MapPin in every shape included, works inside GlobeMarker. Use the Map to find a street; use the Globe to show where in the world things are.

Anatomy#

import { Globe, GlobeMarker, GlobeArc } from "@/components/ui/globe"<Globe>  <GlobeArc from={…} to={…} />  <GlobeMarker lngLat={…}>…</GlobeMarker></Globe>

Markers#

Markers stay in your tree, so Context, state and events work as usual. They fade out at the edge of the sphere rather than popping, and a marker behind the globe stops taking the pointer. Every marker stays in the accessibility tree as an item of the marker list, and tabbing to an interactive one turns the globe to face it. A dot with a captionkeeps the map readable; a labelled chip suits one or two places.

Drag or use the arrow keys to turn it.

Routes#

GlobeArc draws the shortest path between two points, lifted more the further it travels. Routes draw in one after another by order, land with a ring, then send a short pulse along themselves now and then. Many to many reads as a network; keep the markers small, such as MapPin shape="dot" with a caption, so the routes lead.

Drag or use the arrow keys to turn it.

Day and night#

daylight veils the half of the world in darkness, from the sun's real position, and follows the clock as it turns. Pass a Date to show another moment. Pair it with local times in the markers for a distributed team or the status of regions.

Drag or use the arrow keys to turn it.

Select countries#

selectionMode turns the globe into a picker. Hovering a country tints it, traces its outline and names it with its flag beside the pointer, with a check once it is picked. The label holds for a beat across a border or a strait, so it glides from one country to the next instead of blinking, and turns below the pointer near the top edge. A click fills the country in ink, and the hairline borders keep neighbours apart. countries limits the choice, here to Europe, and rests everything else lighter; zoom frames the region. Selection is ISO codes, the same as Flag, so the list beside the globe is yours to compose. Behind the canvas sits a real checkbox per country (radios in "single" mode): tabbing through them turns the globe to each one, and Space picks it.

Drag or use the arrow keys to turn it.
Markets

Markets 3

  • Spain
  • France
  • Germany

"single" keeps one country, for a shipping or billing country picked on the map. A second click on it clears the choice.

Drag or use the arrow keys to turn it.
Shipping country

Surface#

Every colour is a mix of the theme's ink and background, with no accent, read from the --globe-* variables, so the globe re-paints in place when the theme changes and any one of them can be re-tinted with a utility. graticule adds hairline meridians and parallels; sphere={false} leaves the land on the page inside a hairline outline.

Drag or use the arrow keys to turn it.
default
Drag or use the arrow keys to turn it.
graticule
Drag or use the arrow keys to turn it.
sphere=false

Still#

autoRotate={false} and draggable={false} make a still globe framed on center, for a contact page or a card. It draws once and then only when the theme or its size changes.

Barcelona

API reference#

Globe

A labelled, focusable group that draws every country as a real shape, with hairline borders, on a canvas. It is square and fills its width. Forwards native <div> props. Every part accepts className, merged last.

PropTypeDefaultDescription
center[number, number]-The point that faces you first, [longitude, latitude]. Seeds the camera once. Without it the globe turns to the visitor's time zone.
autoRotateboolean | numbertrueTurns the globe slowly when nobody is dragging it. A number sets the speed in degrees per second (true is 4). Off under reduced motion.
draggablebooleantrueDrag with inertia and turn with the arrow keys. false also takes it out of the tab order.
daylightboolean | DatefalseDims the night side from the sun's real position, now or at the Date you pass.
zoomnumber1Brings the sphere closer for a region such as Europe. Above 1 the globe becomes a framed, rounded view that crops the sphere.
spherebooleantruePaints the sea with --globe-ocean. false leaves the land on the page inside the outline of the sphere.
graticulebooleanfalseDraws hairline meridians and parallels every 30 degrees.
labelstring"Globe"The group's accessible name.
selectionMode"none" | "single" | "multiple""none"Lets the reader pick countries: hover tints one and names it, a click fills it in ink, a second click lets it go.
countriesstring[]-The ISO codes that can be picked, such as Europe only. The rest of the world rests dimmer. Every country when unset.
selectedstring[]-The picked ISO codes, controlled.
defaultSelectedstring[][]The picked ISO codes to start with, uncontrolled.
onSelectedChange(selected: string[]) => void-Called with every new selection.
Data attributeDescription
data-slotglobe, globe-canvas, globe-markers, globe-tooltip, globe-choices.
CSS variableDescription
--globe-landCountry fill. Defaults to 17% ink over --background, 30% in dark themes so the land stays readable beside a selection.
--globe-oceanThe sea. Defaults to 4% ink over --background.
--globe-borderCountry borders and coastlines, hairline. Defaults to --background, so borders read as cuts.
--globe-limbThe outline of the sphere. Defaults to --border.
--globe-selectedSelected and hovered countries. Defaults to --foreground, softened to 88% in dark themes.
--globe-arcRoutes and their end points. Defaults to --foreground.

GlobeMarker

Pins any React content to a coordinate, centred on it. It fades out as it turns past the edge and stops taking the pointer behind the globe. Focusing anything inside turns the globe to face it. Forwards native <div> props.

PropTypeDefaultDescription
lngLat[number, number]-Where it sits, [longitude, latitude].
labelstring-The list item's accessible name, read in the marker list.
Data attributeDescription
data-slotglobe-marker.
data-hiddenPresent while the marker is behind the globe.

GlobeArc

A great-circle route that lifts with its length, draws itself in and sends a pulse along now and then. Renders nothing in the DOM.

PropTypeDefaultDescription
from[number, number]-Where it leaves, [longitude, latitude].
to[number, number]-Where it lands.
ordernumber0Its place in the stagger, so routes draw in one after another.

FAQ#

No dependencies. The 177 countries come from Natural Earth's public-domain 1:110m boundaries, baked into a 30 KB module as shared, delta-encoded arcs, and drawn on a 2D canvas with our own orthographic projection and horizon clipping. No WebGL and no map tiles.