Animations/Interactive 3D Globe

Interactive 3D Globe

Globe 3D interactif avec markers et rotation auto. Canvas-based, drag-to-rotate.

autoJS3Dcanvasinteractive
Trigger: Automatique + Drag
CSS requis: Non
Difficulte: hard

Preview live

Code

"use client";
import { useRef, useEffect } from "react";

export default function Globe3D() {
  const canvasRef = useRef<HTMLCanvasElement>(null);
  const rotation = useRef({ x: 0.3, y: 0 });

  useEffect(() => {
    const canvas = canvasRef.current;
    const ctx = canvas?.getContext("2d");
    if (!ctx || !canvas) return;

    let raf: number;
    const draw = () => {
      rotation.current.y += 0.003;
      ctx.clearRect(0, 0, canvas.width, canvas.height);

      const cx = canvas.width / 2, cy = canvas.height / 2, r = 120;
      // Dessiner grille de meridiens et paralleles
      // Projection 3D -> 2D pour chaque point
      // ctx.arc(projX, projY, 2, 0, Math.PI * 2);

      raf = requestAnimationFrame(draw);
    };
    raf = requestAnimationFrame(draw);
    return () => cancelAnimationFrame(raf);
  }, []);

  return <canvas ref={canvasRef} width={400} height={400} />;
}

Instructions

Globe 3D dessine sur canvas avec rotation automatique. Ajoutez des markers (lat/lon -> x/y/z -> projection) et un drag handler pour tourner manuellement. Ajustez le rayon (120) et la vitesse (0.003).