← All components Next componentIsometric City Chart→
Advanced · Data
Interactive Globe
A dotted world map with glowing arcs carrying traffic between cities. Orbit it, click a marker to fly there.
<InteractiveGlobe3D />Live
Drag to orbit · click a marker
Customize
Land#a1a1aa
Arcs#a78bfa
Installation
Use it in your project
Or skip the copy-paste
One command: writes the file and installs the dependencies.
$ npx deepui-cli add interactive-globe
01
Install
The 3D packages this component is built on.
$ npm install three @react-three/fiber @react-three/drei three-stdlib && npm install -D @types/three
02
Add the component
One self-contained file: create components/InteractiveGlobe3D.tsx and paste it in.
components/InteractiveGlobe3D.tsx
1"use client";23import { memo, useEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from "react";4import * as THREE from "three";5import { Canvas, useFrame, useThree, type CanvasProps, type ThreeEvent } from "@react-three/fiber";6import { Html, OrbitControls } from "@react-three/drei";7import type { OrbitControls as OrbitControlsImpl } from "three-stdlib";89/**10 * The shared props API of DeepUI's individual 3D components (not the full-page templates, which keep11 * their own tailored scenes).12 *13 * The props are grouped by concern. A component extends ONLY the groups it really applies, so its14 * type never advertises a knob that does nothing (a card has no particles, a background has no tilt):15 *16 * interface MyCardProps extends CursorProps, TiltProps, MaterialProps, PerformanceProps { … }17 *18 * `Base3DComponentProps` is every group at once, for tooling that handles any component. Same name,19 * same unit and same meaning everywhere; the default values live in DEFAULT_3D_PROPS. These files are20 * inlined into each component's single-file bundle (lib/bundle-source.mjs), only what it uses.21 */2223/** Which rotation axes follow the pointer. "x-only": the object nods (up / down); "y-only": it turns (left / right). */24export type TiltAxis = "both" | "x-only" | "y-only" | "none";2526/** 1. Cursor: how the pointer pulls, pushes and drags the object. */27interface CursorProps {28 /** Reach of the pointer's influence, in the component's own space: CSS pixels for pixel-laid-out widgets, world units for 3D scenes (each component says which). Default 220 (px). */29 cursorRadius?: number;30 /** Positive pulls things towards the pointer, negative pushes them away (repulsion, shockwave). Default 1. */31 cursorForce?: number;32 /** How far the object slides towards the pointer, 0 (stays put) to 1 (follows closely). Default 0. */33 magneticStrength?: number;34 /** Share of the remaining distance the motion closes each frame (at 60 fps), 0.01 (heavy, slow) to 1 (instant). Default 0.1. */35 cursorDamping?: number;36}3738/** 2. Tilt and parallax: the object leans towards the pointer, its layers slide against each other. */39interface TiltProps {40 /** Largest lean towards the pointer, in degrees. Default 15. */41 maxTiltAngle?: number;42 /** Axes that follow the pointer. Default "both". */43 tiltAxis?: TiltAxis;44 /** Lean away from the pointer instead of towards it. Default false. */45 invertTilt?: boolean;46 /** How far apart the depth layers slide when the object tilts, 0 (flat) to 2. Default 1. */47 parallaxOffset?: number;48}4950/** 3. Text and 3D typography, for components that draw a label. */51interface Text3DProps {52 /** The label drawn by the component. */53 text?: string;54 /** Scale of the lettering. Default 1. */55 fontSize?: number;56 /** Extrusion depth of 3D letters. Default 0.2. */57 textDepth?: number;58 /** Bevelled, light-catching edges on 3D letters. Default true. */59 bevelEnabled?: boolean;60 /** Custom font: a .woff / .ttf (flat text) or a typeface .json (extruded text). */61 fontUrl?: string;62}6364/** 4. Rendering, materials and glow. */65interface MaterialProps {66 /** Main color of the object. Default "#6366f1". */67 primaryColor?: string;68 /** Color of the glow. Default "#00f0ff". */69 emissiveColor?: string;70 /** Strength of the glow, 0 (none) to 3. Default 1. */71 emissiveIntensity?: number;72 /** 0 (mirror, glass) to 1 (matte). Default 0.3. */73 roughness?: number;74 /** 0 (plastic, organic) to 1 (metal). Default 0.5. */75 metalness?: number;76 /** 0 (opaque) to 1 (clear glass): see-through, refracting surfaces. Default 0. */77 transmission?: number;78 /** Technical wireframe rendering. Default false. */79 wireframe?: boolean;80}8182/** 5. Particles, idle motion and shader animation. */83interface MotionProps {84 /** Number of instanced elements. Default depends on the component. */85 particleCount?: number;86 /** Spin on its own, in radians per second (negative: the other way; 0.5 ≈ one turn in 12 s). Default 0. */87 autoRotateSpeed?: number;88 /** Pulses or ripples per second. Default 1. */89 pulseRate?: number;90 /** Amplitude of the noise deformation, 0 (none) to 2. Default 1. */91 displacementScale?: number;92}9394/** 6. Environment and camera. */95interface EnvironmentProps {96 /** Camera field of view, in degrees. Default depends on the component. */97 cameraFov?: number;98 /** Color of the depth fog. Default "#0a0a0a". */99 fogColor?: string;100 /** Thickness of the fog, 0 (none) to 0.2. Default 0. */101 fogDensity?: number;102}103104/** 7. Performance and accessibility. */105interface PerformanceProps {106 /** Lighter rendering for weak devices: pixel ratio 1, fewer instances, smaller environment maps. Default false. */107 lowPowerMode?: boolean;108 /** Under the OS "reduce motion" setting, stop idle spin, pulses and deformation (pointer feedback stays). Default true. */109 respectReducedMotion?: boolean;110 /** Stop the render loop while the component is scrolled out of view. Default true. */111 pauseWhenOffscreen?: boolean;112}113114/** Every group at once. Components extend only the groups they apply (see the top of this file). */115interface Base3DComponentProps116 extends CursorProps,117 TiltProps,118 Text3DProps,119 MaterialProps,120 MotionProps,121 EnvironmentProps,122 PerformanceProps {}123124type Defaults = Required<Omit<Base3DComponentProps, "text" | "fontUrl" | "particleCount" | "cameraFov">>;125126/** The values a prop takes when it is left out. A component may override one, and then documents it. */127const DEFAULT_3D_PROPS: Defaults = {128 cursorRadius: 220,129 cursorForce: 1,130 magneticStrength: 0,131 cursorDamping: 0.1,132 maxTiltAngle: 15,133 tiltAxis: "both",134 invertTilt: false,135 parallaxOffset: 1,136 fontSize: 1,137 textDepth: 0.2,138 bevelEnabled: true,139 primaryColor: "#6366f1",140 emissiveColor: "#00f0ff",141 emissiveIntensity: 1,142 roughness: 0.3,143 metalness: 0.5,144 transmission: 0,145 wireframe: false,146 autoRotateSpeed: 0,147 pulseRate: 1,148 displacementScale: 1,149 fogColor: "#0a0a0a",150 fogDensity: 0,151 lowPowerMode: false,152 respectReducedMotion: true,153 pauseWhenOffscreen: true,154};155156/** Inline widget: fills its positioned parent and receives pointer events. */157const FILL_STYLE: CSSProperties = { position: "absolute", top: 0, left: 0, width: "100%", height: "100%" };158159/** Cursor overlay: covers the viewport, above everything, never intercepts the page's events. */160const OVERLAY_STYLE: CSSProperties = {161 position: "fixed",162 top: 0,163 left: 0,164 width: "100%",165 height: "100%",166 pointerEvents: "none",167 zIndex: 9999,168};169170interface UICanvasProps extends Omit<CanvasProps, "children" | "style" | "gl">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {171 children: ReactNode;172 /** Full-viewport, click-through overlay (cursors) instead of an inline widget. */173 overlay?: boolean;174}175176/**177 * Ready-to-use <Canvas>: pauses its render loop while scrolled out of view (pauseWhenOffscreen), pixel178 * ratio 1 in lowPowerMode; R3F disposes the renderer and its WebGL context on unmount.179 */180function UICanvas({ children, overlay = false, dpr = [1, 2], pauseWhenOffscreen = DEFAULT_3D_PROPS.pauseWhenOffscreen, lowPowerMode = DEFAULT_3D_PROPS.lowPowerMode, ...canvasProps }: UICanvasProps) {181 const containerRef = useRef<HTMLDivElement>(null);182 // In view at first: the first frame is always drawn before the loop can be paused183 const [inView, setInView] = useState(true);184 useEffect(() => {185 const el = containerRef.current;186 if (!el || !pauseWhenOffscreen) return undefined;187 const observer = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));188 observer.observe(el);189 return () => observer.disconnect();190 }, [pauseWhenOffscreen]);191 return (192 <div ref={containerRef} style={overlay ? OVERLAY_STYLE : FILL_STYLE} aria-hidden="true">193 <Canvas194 dpr={lowPowerMode ? 1 : dpr}195 frameloop={inView || !pauseWhenOffscreen ? "always" : "never"}196 gl={{ antialias: true, alpha: true, powerPreference: "high-performance" }}197 style={overlay ? { pointerEvents: "none" } : undefined}198 {...canvasProps}199 >200 {children}201 </Canvas>202 </div>203 );204}205206export interface GlobeMarker {207 lat: number;208 lng: number;209 label: string;210}211212export interface GlobeConnection {213 /** [lat, lng] */214 from: [number, number];215 /** [lat, lng] */216 to: [number, number];217}218219export interface GlobeProps extends Pick<MaterialProps, "primaryColor" | "emissiveColor">, Pick<PerformanceProps, "pauseWhenOffscreen" | "lowPowerMode"> {220 /** Radius in world units. Default 2. */221 globeRadius?: number;222 primaryColor?: string;223 /** @deprecated Use `primaryColor`. */224 dotColor?: string;225 /** Color of the arcs, markers and atmosphere. */226 emissiveColor?: string;227 /** @deprecated Use `emissiveColor`. */228 arcColor?: string;229 markers?: GlobeMarker[];230 connections?: GlobeConnection[];231 /** Spin on its own while idle. Default true. */232 autoRotate?: boolean;233}234235const DEFAULT_MARKERS: GlobeMarker[] = [236 { lat: 48.86, lng: 2.35, label: "Paris" },237 { lat: 51.51, lng: -0.13, label: "London" },238 { lat: 40.71, lng: -74.0, label: "New York" },239 { lat: 37.77, lng: -122.42, label: "San Francisco" },240 { lat: -23.55, lng: -46.63, label: "São Paulo" },241 { lat: 25.2, lng: 55.27, label: "Dubai" },242 { lat: 1.35, lng: 103.82, label: "Singapore" },243 { lat: 35.68, lng: 139.69, label: "Tokyo" },244 { lat: -33.87, lng: 151.21, label: "Sydney" },245];246247const DEFAULT_CONNECTIONS: GlobeConnection[] = [248 { from: [48.86, 2.35], to: [40.71, -74.0] },249 { from: [40.71, -74.0], to: [37.77, -122.42] },250 { from: [51.51, -0.13], to: [25.2, 55.27] },251 { from: [25.2, 55.27], to: [1.35, 103.82] },252 { from: [1.35, 103.82], to: [35.68, 139.69] },253 { from: [1.35, 103.82], to: [-33.87, 151.21] },254 { from: [48.86, 2.35], to: [-23.55, -46.63] },255 { from: [37.77, -122.42], to: [35.68, 139.69] },256];257258// Simplified continent outlines, [lng, lat]: enough for a recognizable dotted map with no data file259const CONTINENTS: [number, number][][] = [260 // North America261 [[-168, 65], [-140, 70], [-95, 72], [-80, 63], [-62, 55], [-55, 47], [-70, 43], [-76, 35], [-81, 25], [-97, 26], [-105, 20], [-95, 16], [-83, 9], [-78, 8], [-87, 14], [-106, 23], [-117, 32], [-124, 40], [-125, 49], [-135, 58], [-150, 60], [-165, 60]],262 // Greenland263 [[-55, 60], [-43, 60], [-20, 70], [-20, 81], [-60, 82], [-72, 77], [-56, 68]],264 // South America265 [[-80, 8], [-60, 11], [-50, 1], [-35, -6], [-40, -22], [-48, -28], [-58, -38], [-66, -55], [-74, -50], [-72, -30], [-71, -18], [-81, -5]],266 // Europe267 [[-10, 36], [-1, 43], [-9, 43], [-4, 48], [1, 50], [5, 53], [8, 57], [5, 62], [14, 68], [28, 71], [40, 67], [45, 60], [40, 48], [30, 45], [27, 41], [23, 37], [16, 38], [12, 44], [3, 43]],268 // Great Britain269 [[-5, 50], [1.5, 51.5], [-1.5, 57], [-5, 58.5], [-6, 54]],270 // Africa271 [[-17, 15], [-17, 21], [-10, 30], [-5, 36], [10, 37], [20, 32], [32, 31], [35, 28], [43, 12], [51, 12], [40, -2], [40, -15], [35, -25], [20, -35], [17, -29], [12, -17], [13, -5], [8, 4], [-8, 4], [-15, 10]],272 // Madagascar273 [[44, -25], [50, -15], [49, -12], [44, -17]],274 // Asia275 [[27, 41], [35, 36], [45, 40], [50, 30], [57, 25], [60, 22], [66, 25], [73, 20], [78, 8], [80, 15], [88, 22], [92, 22], [98, 16], [100, 6], [104, 1], [106, 10], [109, 12], [108, 21], [118, 24], [122, 30], [121, 40], [130, 42], [142, 46], [140, 52], [160, 60], [180, 66], [180, 72], [140, 73], [110, 77], [80, 73], [60, 70], [45, 68], [40, 67], [45, 60], [40, 48], [30, 45]],276 // Arabian Peninsula277 [[35, 28], [43, 13], [52, 16], [59, 22], [56, 26], [48, 30], [39, 32]],278 // Japan279 [[130, 31], [136, 34], [141, 38], [142, 45], [140, 41], [135, 35]],280 // Indonesia (simplified)281 [[95, 5], [106, -6], [115, -8], [125, -9], [140, -3], [131, 0], [119, 2], [109, 2], [100, 1]],282 // Australia283 [[114, -22], [122, -18], [130, -12], [137, -12], [142, -11], [146, -19], [153, -26], [150, -37], [140, -38], [131, -31], [115, -34]],284];285286function inPolygon(lng: number, lat: number, polygon: [number, number][]) {287 let inside = false;288 for (let i = 0, j = polygon.length - 1; i < polygon.length; j = i++) {289 const [xi, yi] = polygon[i];290 const [xj, yj] = polygon[j];291 if (yi > lat !== yj > lat && lng < ((xj - xi) * (lat - yi)) / (yj - yi) + xi) inside = !inside;292 }293 return inside;294}295296export function isLand(lat: number, lng: number) {297 if (lat < -72) return true; // Antarctica298 return CONTINENTS.some((polygon) => inPolygon(lng, lat, polygon));299}300301/** [lat, lng] in degrees → point on the sphere. */302export function latLngToVector(lat: number, lng: number, radius: number, target = new THREE.Vector3()) {303 const phi = THREE.MathUtils.degToRad(90 - lat);304 const theta = THREE.MathUtils.degToRad(lng + 180);305 return target.set(-radius * Math.sin(phi) * Math.cos(theta), radius * Math.cos(phi), radius * Math.sin(phi) * Math.sin(theta));306}307308const arcVertex = /* glsl */ `309varying float vT;310void main() {311 vT = uv.x; // TubeGeometry: uv.x runs along the curve312 gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);313}314`;315316const arcFragment = /* glsl */ `317uniform vec3 uColor;318uniform float uTime;319uniform float uOffset;320varying float vT;321void main() {322 // A bright pulse travelling from source to destination, over a faint permanent trail323 float head = fract(uTime * 0.35 + uOffset) * 1.4 - 0.2;324 float pulse = smoothstep(head - 0.28, head, vT) * (1.0 - smoothstep(head, head + 0.02, vT));325 float ends = smoothstep(0.0, 0.06, vT) * (1.0 - smoothstep(0.94, 1.0, vT));326 float intensity = (0.16 + pulse * 1.6) * ends;327 gl_FragColor = vec4(uColor * intensity, intensity);328 #include <colorspace_fragment>329}330`;331332const atmosphereFragment = /* glsl */ `333uniform vec3 uColor;334varying vec3 vNormal;335varying vec3 vView;336void main() {337 // Back faces of a slightly larger sphere: a rim of light just outside the globe's edge338 float rim = pow(max(dot(-vNormal, vView), 0.0), 3.0);339 gl_FragColor = vec4(uColor * rim * 1.3, rim);340 #include <colorspace_fragment>341}342`;343344const atmosphereVertex = /* glsl */ `345varying vec3 vNormal;346varying vec3 vView;347void main() {348 vec4 world = modelMatrix * vec4(position, 1.0);349 vNormal = normalize(mat3(modelMatrix) * normal);350 vView = normalize(cameraPosition - world.xyz);351 gl_Position = projectionMatrix * viewMatrix * world;352}353`;354355const Globe = memo(function Globe({356 globeRadius = 2,357 primaryColor,358 dotColor = primaryColor ?? "#a1a1aa",359 emissiveColor,360 arcColor = emissiveColor ?? "#a78bfa",361 markers = DEFAULT_MARKERS,362 connections = DEFAULT_CONNECTIONS,363 autoRotate = true,364}: GlobeProps) {365 const R = globeRadius;366 const controls = useThree((state) => state.controls) as OrbitControlsImpl | null;367 const gl = useThree((state) => state.gl);368 const [selected, setSelected] = useState(-1);369 const [hovered, setHovered] = useState(-1);370 const flight = useRef<{ active: boolean; direction: THREE.Vector3 }>({ active: false, direction: new THREE.Vector3() });371 const markerRefs = useRef<(THREE.Mesh | null)[]>([]);372373 // Dotted land: Fibonacci points on the sphere, kept where the outlines say there is land374 const dots = useMemo(() => {375 const total = 18000;376 const golden = Math.PI * (3 - Math.sqrt(5));377 const geometry = new THREE.CircleGeometry(R * 0.0085, 6);378 const material = new THREE.MeshBasicMaterial({ side: THREE.DoubleSide, toneMapped: false });379 const positions: THREE.Vector3[] = [];380 for (let i = 0; i < total; i++) {381 const y = 1 - ((i + 0.5) / total) * 2;382 const r = Math.sqrt(1 - y * y);383 const theta = i * golden;384 const p = new THREE.Vector3(Math.cos(theta) * r, y, Math.sin(theta) * r);385 const lat = THREE.MathUtils.radToDeg(Math.asin(p.y));386 // Inverse of latLngToVector's longitude convention387 const lng = ((THREE.MathUtils.radToDeg(Math.atan2(p.z, -p.x)) + 360) % 360) - 180;388 if (isLand(lat, lng)) positions.push(p.multiplyScalar(R));389 }390 const mesh = new THREE.InstancedMesh(geometry, material, positions.length);391 const m = new THREE.Matrix4();392 const q = new THREE.Quaternion();393 const z = new THREE.Vector3(0, 0, 1);394 const one = new THREE.Vector3(1, 1, 1);395 positions.forEach((p, i) => {396 q.setFromUnitVectors(z, p.clone().normalize()); // each dot lies flat on the surface397 mesh.setMatrixAt(i, m.compose(p, q, one));398 });399 return { mesh, geometry, material };400 }, [R]);401402 const shell = useMemo(() => {403 const core = new THREE.SphereGeometry(R * 0.99, 64, 64);404 const atmosphere = new THREE.SphereGeometry(R * 1.14, 64, 64);405 const coreMaterial = new THREE.MeshBasicMaterial({ color: "#07060c" });406 const atmosphereMaterial = new THREE.ShaderMaterial({407 uniforms: { uColor: { value: new THREE.Color() } },408 vertexShader: atmosphereVertex,409 fragmentShader: atmosphereFragment,410 side: THREE.BackSide,411 transparent: true,412 depthWrite: false,413 blending: THREE.AdditiveBlending,414 });415 return { core, atmosphere, coreMaterial, atmosphereMaterial };416 }, [R]);417418 const connectionsKey = JSON.stringify(connections);419 const arcs = useMemo(() => {420 const list = JSON.parse(connectionsKey) as GlobeConnection[];421 return list.map((c, i) => {422 const a = latLngToVector(c.from[0], c.from[1], R);423 const b = latLngToVector(c.to[0], c.to[1], R);424 // The arc lifts off the surface in proportion to the distance it covers425 const lift = 1 + a.distanceTo(b) / (R * 2) * 0.55;426 const mid = a.clone().add(b).normalize().multiplyScalar(R * lift);427 const curve = new THREE.CatmullRomCurve3([a, a.clone().lerp(mid, 0.5).normalize().multiplyScalar(R * (1 + (lift - 1) * 0.7)), mid, b.clone().lerp(mid, 0.5).normalize().multiplyScalar(R * (1 + (lift - 1) * 0.7)), b]);428 const geometry = new THREE.TubeGeometry(curve, 96, R * 0.0045, 6, false);429 const material = new THREE.ShaderMaterial({430 uniforms: { uColor: { value: new THREE.Color() }, uTime: { value: 0 }, uOffset: { value: i * 0.37 } },431 vertexShader: arcVertex,432 fragmentShader: arcFragment,433 transparent: true,434 depthWrite: false,435 blending: THREE.AdditiveBlending,436 });437 return { geometry, material };438 });439 }, [connectionsKey, R]);440441 const markerGeometry = useMemo(() => new THREE.SphereGeometry(R * 0.018, 16, 16), [R]);442 const markerMaterial = useMemo(() => new THREE.MeshBasicMaterial({ toneMapped: false }), []);443 const markerPositions = useMemo(() => markers.map((m) => latLngToVector(m.lat, m.lng, R * 1.004)), [markers, R]);444445 useEffect(() => {446 dots.material.color.set(dotColor);447 markerMaterial.color.set(arcColor).multiplyScalar(1.6);448 (shell.atmosphereMaterial.uniforms.uColor.value as THREE.Color).set(arcColor);449 arcs.forEach(({ material }) => (material.uniforms.uColor.value as THREE.Color).set(arcColor));450 }, [dots, shell, arcs, markerMaterial, dotColor, arcColor]);451452 useEffect(453 () => () => {454 dots.mesh.dispose();455 dots.geometry.dispose();456 dots.material.dispose();457 },458 [dots]459 );460 useEffect(461 () => () => {462 shell.core.dispose();463 shell.atmosphere.dispose();464 shell.coreMaterial.dispose();465 shell.atmosphereMaterial.dispose();466 },467 [shell]468 );469 useEffect(() => () => arcs.forEach(({ geometry, material }) => (geometry.dispose(), material.dispose())), [arcs]);470 useEffect(() => () => markerGeometry.dispose(), [markerGeometry]);471 useEffect(() => () => markerMaterial.dispose(), [markerMaterial]);472473 const select = (index: number) => {474 setSelected(index);475 if (index < 0) return;476 flight.current.direction.copy(markerPositions[index]).normalize();477 flight.current.active = true;478 };479480 useFrame((state, delta) => {481 const dt = Math.min(delta, 1 / 30);482 const t = state.clock.elapsedTime;483 arcs.forEach(({ material }) => (material.uniforms.uTime.value = t));484485 // Markers pulse; the selected one is bigger486 markerRefs.current.forEach((mesh, i) => {487 if (!mesh) return;488 const base = i === selected ? 1.9 : i === hovered ? 1.5 : 1;489 mesh.scale.setScalar(base * (1 + Math.sin(t * 3 + i) * 0.15));490 });491492 if (controls) {493 controls.autoRotate = autoRotate && selected === -1 && hovered === -1;494 // Click on a marker: the camera swings round (same distance) until the marker faces it495 if (flight.current.active) {496 const camera = state.camera;497 const distance = camera.position.length();498 const goal = flight.current.direction.clone().multiplyScalar(distance);499 camera.position.lerp(goal, 1 - Math.exp(-3.5 * dt)).setLength(distance);500 if (camera.position.distanceTo(goal) < 0.01) flight.current.active = false;501 controls.update();502 }503 }504 });505506 return (507 <group onPointerMissed={() => select(-1)}>508 <mesh geometry={shell.core} material={shell.coreMaterial} />509 <mesh geometry={shell.atmosphere} material={shell.atmosphereMaterial} />510 <primitive object={dots.mesh} />511 {arcs.map(({ geometry, material }, i) => (512 <mesh key={i} geometry={geometry} material={material} />513 ))}514 {markers.map((marker, i) => (515 <mesh516 key={`${marker.label}-${i}`}517 ref={(mesh) => {518 markerRefs.current[i] = mesh;519 }}520 geometry={markerGeometry}521 material={markerMaterial}522 position={markerPositions[i]}523 onPointerOver={(e: ThreeEvent<PointerEvent>) => {524 e.stopPropagation();525 setHovered(i);526 gl.domElement.style.cursor = "pointer";527 }}528 onPointerOut={() => {529 setHovered((h) => (h === i ? -1 : h));530 gl.domElement.style.cursor = "";531 }}532 onClick={(e: ThreeEvent<MouseEvent>) => {533 e.stopPropagation();534 select(selected === i ? -1 : i);535 }}536 >537 {i === selected || i === hovered ? (538 <Html center zIndexRange={[20, 0]} style={{ pointerEvents: "none", transform: "translateY(-22px)" }}>539 <span540 style={{541 whiteSpace: "nowrap",542 borderRadius: 999,543 background: "rgba(10,10,14,0.85)",544 border: "1px solid rgba(255,255,255,0.15)",545 padding: "4px 10px",546 font: "600 12px/1.2 system-ui, sans-serif",547 color: "white",548 }}549 >550 {marker.label}551 </span>552 </Html>553 ) : null}554 </mesh>555 ))}556 </group>557 );558});559560/** Self-contained globe: fills its positioned parent. Drag to orbit, scroll to zoom, click a marker. */561function InteractiveGlobe3D(props: GlobeProps) {562 const R = props.globeRadius ?? 2;563 return (564 <>565 <UICanvas pauseWhenOffscreen={props.pauseWhenOffscreen} lowPowerMode={props.lowPowerMode} camera={{ position: [0, R * 0.6, R * 3.1], fov: 40, near: 0.05, far: R * 20 }}>566 <OrbitControls makeDefault enablePan={false} enableDamping dampingFactor={0.08} rotateSpeed={0.6} autoRotateSpeed={0.5} minDistance={R * 1.6} maxDistance={R * 5} />567 <Globe {...props} />568 </UICanvas>569 <ul style={{ position: "absolute", width: 1, height: 1, overflow: "hidden", clip: "rect(0,0,0,0)" }}>570 {(props.markers ?? DEFAULT_MARKERS).map((m, i) => (571 <li key={`${m.label}-${i}`}>{m.label}</li>572 ))}573 </ul>574 </>575 );576}577578export default memo(InteractiveGlobe3D);
03
Drop it in a page
Updated live with the settings above.
app/page.tsx
1import InteractiveGlobe3D from "@/components/InteractiveGlobe3D";23export default function Section() {4 return (5 // The component fills this box: give it a position and a height6 <div style={{ position: "relative", width: "100%", height: "100vh" }}>7 <InteractiveGlobe3D8 globeRadius={2}9 primaryColor="#a1a1aa"10 emissiveColor="#a78bfa"11 />12 </div>13 );14}