The home page of this site has a globe that turns to each city I have worked in as you scroll. It is built with three.js through React Three Fiber, inside a Next.js site that exports to static files. This post walks through the parts.

The map is lines, not a texture

Most globes wrap a satellite image around a sphere. I wanted something quieter, so the land is drawn as thin outlines.

The outlines come from the world-atlas package, which ships the Natural Earth country shapes in TopoJSON. topojson-client turns them into lines, and it can tell coastlines from shared borders:

const coast = mesh(topology, countries, (a, b) => a === b);
const borders = mesh(topology, countries, (a, b) => a !== b);

Each line is a list of longitude and latitude pairs. One function converts a pair into a point on the sphere, and every other part of the scene uses that same function, so cities, borders and arcs always agree on where things are:

function toVec(lat: number, lon: number, r = 1) {
  const phi = ((90 - lat) * Math.PI) / 180;
  const theta = ((lon + 180) * Math.PI) / 180;
  return new THREE.Vector3(
    -r * Math.sin(phi) * Math.cos(theta),
    r * Math.cos(phi),
    r * Math.sin(phi) * Math.sin(theta),
  );
}

Coastlines are drawn brighter than borders. A solid dark sphere underneath hides the far side of the globe without any extra work, because it writes to the depth buffer and the lines behind it fail the depth test.

Following the scroll

The text on the left is a normal page. Each city is a section, and an IntersectionObserver reports which section is crossing the middle of the screen. That index is the only thing the globe receives.

Inside the scene, the globe eases toward the rotation that brings the active city to the front. Two angles are enough: one turn around the vertical axis for longitude and one tilt for latitude. The only trick is to turn the short way around, so going from Madrid back to Miami does not spin across Asia.

let dy = (target.y - rotation.y) % (Math.PI * 2);
if (dy > Math.PI) dy -= Math.PI * 2;
if (dy < -Math.PI) dy += Math.PI * 2;
rotation.y += dy * Math.min(1, dt * 2.6);

Arcs that draw themselves

Each arc is a curve between two cities, lifted off the surface in the middle. The longer the trip, the higher it rises, so a transatlantic arc clears the sphere.

The curve becomes a thin tube. To animate it, the geometry stays the same and only the number of triangles to draw changes each frame:

geometry.setDrawRange(0, Math.floor(progress * SEGMENTS) * SIDES * 6);

Scrolling forward raises progress to 1 and scrolling back lowers it to 0, so the path retracts when you go up the page.

Keeping it fast and indexable

The globe is loaded with next/dynamic and server rendering turned off, so three.js never blocks the first paint and the text is in the HTML from the start. Search engines read the same content a visitor does; the globe is an addition, not the container.

People who ask their system to reduce motion get the globe without the easing: it jumps to each city.