Map Animated Footprint
terrae/animated-footprintFreeComponent
Animated footprint steps that walk along a path on the map.
Install it
npx shadcn@latest add https://www.terrae.dev/animated-footprint.jsonSource
1"use client"23import { useEffect, useMemo, useRef, useState } from "react"4import { createPortal } from "react-dom"5import type mapboxgl from "mapbox-gl"6import { Footprints } from "lucide-react"7import { mapgl } from "./map-library"8import { useMap } from "./hooks"9import type { MapPath, MapCoordinates } from "./types"1011type FootprintStep = {12 coordinates: MapCoordinates13 bearing: number14 isLeft: boolean15}1617type MarkerEntry = {18 marker: mapboxgl.Marker19 element: HTMLDivElement20}2122type FootprintControl = {23 start: () => void24 reset: () => void25 isActive: boolean26}2728type FootprintProps = {29 entry: MarkerEntry30 step: FootprintStep31 color: string32 size: number33 className?: string34}3536type MapAnimatedFootprintProps = {37 path: MapPath38 id?: string39 color?: string40 size?: number41 stepSpacing?: number42 staggerDelay?: number43 duration?: number44 autoStart?: boolean45 loop?: boolean46 className?: string47}4849const footprintControls = new Map<string, FootprintControl>()5051const DEFAULT_COLOR = "#000000"52const DEFAULT_SIZE = 2053const DEFAULT_STEP_SPACING = 4854const DEFAULT_STAGGER_DELAY = 20055const DEFAULT_DURATION = 40056const METERS_PER_DEGREE_LATITUDE = 11132057const LATERAL_OFFSET = 0.45859const approximateDistance = (from: MapCoordinates, to: MapCoordinates) => {60 const latitudeRadians = (from[1] * Math.PI) / 18061 const deltaX = (to[0] - from[0]) * Math.cos(latitudeRadians) * METERS_PER_DEGREE_LATITUDE62 const deltaY = (to[1] - from[1]) * METERS_PER_DEGREE_LATITUDE6364 return Math.sqrt(deltaX ** 2 + deltaY ** 2)65}6667const approximateBearing = (from: MapCoordinates, to: MapCoordinates) => {68 const latitudeRadians = (from[1] * Math.PI) / 18069 const deltaX = (to[0] - from[0]) * Math.cos(latitudeRadians)70 const deltaY = to[1] - from[1]7172 return ((Math.atan2(deltaX, deltaY) * 180) / Math.PI + 360) % 36073}7475const interpolateCoordinate = (from: MapCoordinates, to: MapCoordinates, fraction: number): MapCoordinates => {76 return [from[0] + (to[0] - from[0]) * fraction, from[1] + (to[1] - from[1]) * fraction]77}7879const generateSteps = (path: MapPath, stepSpacing: number): FootprintStep[] => {80 if (path.length < 2) {81 return []82 }8384 const steps: FootprintStep[] = []85 let distanceAccumulated = 086 let stepIndex = 08788 for (let segmentIndex = 0; segmentIndex < path.length - 1; segmentIndex++) {89 const fromCoordinate = path[segmentIndex]90 const toCoordinate = path[segmentIndex + 1]91// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from terrae
All 40 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Map Animated Circleanimated-circle | terrae | Components | Free | 1 dep | |
| Map Animated Polygonanimated-polygon | terrae | Components | Free | 1 dep | |
| Map Animated Pulseanimated-pulse | terrae | Components | Free | 1 dep | |
| Map Arc Animatedarc-animated | terrae | Components | Free | 1 dep | |
| Map Blur Areablur-area | terrae | Components | Free | 1 dep | |
| Map Camera Followcamera-follow | terrae | Components | Free | 1 dep | |
| Map Choroplethchoropleth | terrae | Components | Free | 1 dep | |
| Map Circlecircle | terrae | Components | Free | 1 dep |
