Map Animated Polygon
terrae/animated-polygonFreeComponent
Animated polygon with draw, fill, and draw-then-fill effects.
Install it
npx shadcn@latest add https://www.terrae.dev/animated-polygon.jsonSource
1"use client"23import { useEffect, useRef, useState } from "react"4import type mapboxgl from "mapbox-gl"56import { useMap } from "./hooks"7import type { MapCoordinates } from "./types"89type AnimationMode = "draw" | "fill" | "draw-then-fill"1011type MapAnimatedPolygonProps = {12 id: string13 coordinates: MapCoordinates[]14 strokeColor?: string15 strokeWidth?: number16 strokeOpacity?: number17 fillColor?: string18 fillOpacity?: number19 duration?: number20 fillDuration?: number21 autoStart?: boolean22 loop?: boolean23 loopDelay?: number24 animationMode?: AnimationMode25 onDrawComplete?: () => void26 onFillComplete?: () => void27 onComplete?: () => void28}2930const DEFAULT_STROKE_COLOR = "#3b82f6"31const DEFAULT_STROKE_WIDTH = 232const DEFAULT_STROKE_OPACITY = 133const DEFAULT_FILL_COLOR = "#3b82f6"34const DEFAULT_FILL_OPACITY = 0.335const DEFAULT_DURATION = 200036const DEFAULT_FILL_DURATION = 100037const DEFAULT_AUTO_START = true38const DEFAULT_LOOP = false39const DEFAULT_LOOP_DELAY = 100040const DEFAULT_ANIMATION_MODE: AnimationMode = "draw-then-fill"4142export const MapAnimatedPolygon = ({43 id,44 coordinates,45 strokeColor = DEFAULT_STROKE_COLOR,46 strokeWidth = DEFAULT_STROKE_WIDTH,47 strokeOpacity = DEFAULT_STROKE_OPACITY,48 fillColor = DEFAULT_FILL_COLOR,49 fillOpacity = DEFAULT_FILL_OPACITY,50 duration = DEFAULT_DURATION,51 fillDuration = DEFAULT_FILL_DURATION,52 autoStart = DEFAULT_AUTO_START,53 loop = DEFAULT_LOOP,54 loopDelay = DEFAULT_LOOP_DELAY,55 animationMode = DEFAULT_ANIMATION_MODE,56 onDrawComplete,57 onFillComplete,58 onComplete,59}: MapAnimatedPolygonProps) => {60 const { map, isLoaded } = useMap()6162 const initializedRef = useRef(false)63 const styleLoadedRef = useRef(false)64 const animationFrameRef = useRef<number | undefined>(undefined)65 const loopTimeoutRef = useRef<ReturnType<typeof setTimeout> | undefined>(undefined)66 const startTimeRef = useRef<number>(0)6768 const coordinatesRef = useRef(coordinates)69 const durationRef = useRef(duration)70 const fillDurationRef = useRef(fillDuration)71 const onDrawCompleteRef = useRef(onDrawComplete)72 const onFillCompleteRef = useRef(onFillComplete)73 const onCompleteRef = useRef(onComplete)7475 coordinatesRef.current = coordinates76 durationRef.current = duration77 fillDurationRef.current = fillDuration78 onDrawCompleteRef.current = onDrawComplete79 onFillCompleteRef.current = onFillComplete80 onCompleteRef.current = onComplete8182 const [isAnimating, setIsAnimating] = useState(false)83// … 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 Footprintanimated-footprint | terrae | Components | Free | 2 deps | |
| 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 |
