Eldora UI
Eldora UI
  1. Components
  2. Special Animations
  3. Cobeglobe

Cobeglobe

A globe animation which is Interactive and customizable.

<Cobe />

Installation

Install the following dependencies:

  npm install cobe

Copy and paste the following code into your project.

 
import createGlobe from "cobe";
import { useEffect, useRef } from "react";
 
export function Cobe() {
const canvasRef = useRef();
useEffect(() => {
  let phi = 0;
  let width = 0;
  const onResize = () => canvasRef.current && (width = canvasRef.current.offsetWidth)
  window.addEventListener('resize', onResize)
  onResize()
  const globe = createGlobe(canvasRef.current, {
    devicePixelRatio: 2,
    width: width * 2,
    height: width * 2,
    phi: 0,
    theta: 0.3,
    dark: 1,
    diffuse: 3,
    mapSamples: 16000,
    mapBrightness: 1.2,
    baseColor: [1, 1, 1],
    markerColor: [251 / 255, 100 / 255, 21 / 255],
    glowColor: [1.2, 1.2, 1.2],
    markers: [],
    onRender: (state) => {
      // Called on every animation frame.
      // `state` will be an empty object, return updated params.
      state.phi = phi
      phi += 0.005
      state.width = width * 2
      state.height = width * 2
    }
  })
  setTimeout(() => canvasRef.current.style.opacity = '1')
  return () => { 
    globe.destroy();
    window.removeEventListener('resize', onResize);
  }
}, [])
return <div style={{
  width: '100%',
  maxWidth: 600,
  aspectRatio: 1,
  margin: 'auto',
  position: 'relative',
}}>
  <canvas
    ref={canvasRef}
    style={{
      width: '100%',
      height: '100%',
      contain: 'layout paint size',
      opacity: 0,
      transition: 'opacity 1s ease',
    }}
  />
</div>
}
 
 
 

Update the import paths to match your project setup.

Variants

Draggable

<Cobe />

Draggable & Auto Rotate

<Cobe />

Rotate to Location

Rotate to:
<Cobe />

Scaled

<Cobe />

props

PropertyDescriptionRequired
devicePixelRatio
The “DPR”, defaults to 1
width
The width of the canvas
Required
height
The height of the canvas
Required
phi
The φ angle, 0 ≤ phi ≤ 2π
Required
theta
The θ angle, -π ≤ theta ≤ π
Required
dark
Display the globe in dark or light mode, 0 ≤ dark ≤ 1
Required
diffuse
Control the diffuse lighting, 0 ≤ diffuse
Required
mapSamples
Number of dots displayed, 0 ≤ mapSamples ≤ 100000
Required
mapBrightness
Brightness of the dots, 0 ≤ mapBrightness
Required
mapBaseBrightness
Brightness of samples that are not on the map, 0 ≤ mapBaseBrightness
baseColor
[r, g, b] of the base color, 0 ≤ r, g, b ≤ 1
markerColor
[r, g, b] of the markers’ color, 0 ≤ r, g, b ≤ 1
glowColor
[r, g, b] of the glow color, 0 ≤ r, g, b ≤ 1
scale
Scales the globe, 0 ≤ scale
offset
[offsetX, offsetY], offset of the globe in pixel
markers
An array of markers displayed
opacity
The transparency of the globe texture
onRender
A callback function called when a new frame is rendered
Required

Built by karthikmudunuri. The source code is available on GitHub.