⚠️ Early Stage Project: This library is not production-ready yet. Developers should use it with caution and expect breaking changes.

Animated Polygon

Animated polygons that draw their outline and fill with smooth transitions.

Installation

First, make sure you have the base map component installed:

npx shadcn@latest add https://terrae.vercel.app/maps/map.json

Then install the animated polygon component:

npx shadcn@latest add https://terrae.vercel.app/maps/map-animated-polygon.json

With Fill

Use animationMode="draw-then-fill" to first draw the outline, then animate the fill opacity. Set fillColor and fillOpacity to customize the fill appearance.

Animation Modes

The component supports three animation modes:

  • draw - Only animate the polygon outline (no fill)
  • fill - Show complete outline immediately and animate fill opacity
  • draw-then-fill - Draw outline first, then animate fill (default)

Properties

PropertyTypeDefaultDescription
idstringrequiredUnique identifier for the polygon
coordinates[number, number][]requiredArray of coordinates defining polygon vertices
strokeColorstring"#3b82f6"Color of the polygon outline
strokeWidthnumber2Width of the polygon outline in pixels
strokeOpacitynumber1Opacity of the polygon outline (0-1)
fillColorstring"#3b82f6"Color of the polygon fill
fillOpacitynumber0.3Target opacity of the polygon fill (0-1)
durationnumber2000Duration of outline drawing animation in ms
fillDurationnumber1000Duration of fill animation in ms
animationMode"draw" | "fill" | "draw-then-fill""draw-then-fill"Animation sequence mode
autoStartbooleantrueStart animation automatically on mount
loopbooleanfalseLoop the animation continuously
loopDelaynumber1000Delay before restarting loop in ms
onDrawComplete() => voidundefinedCallback when outline drawing completes
onFillComplete() => voidundefinedCallback when fill animation completes
onComplete() => voidundefinedCallback when entire animation completes

Use Cases

Emergency Zones

Visualize wildfire, hurricane, or evacuation boundaries

Risk Assessment

Display flood zones, seismic risk, or hazard areas

Service Coverage

Show delivery zones, network coverage, or service areas

Property Boundaries

Highlight parcels, districts, or administrative regions

Conservation Areas

Display protected zones, parks, or wildlife reserves

Urban Planning

Visualize zoning districts or development boundaries

Performance Tips

  • Keep polygon vertices under 100 points for smooth animation
  • Use animationMode="fill" for simpler animations with less CPU usage
  • Increase loopDelay to reduce continuous animation overhead
  • Use autoStart=false and trigger manually for user-initiated animations
  • Simplify complex polygon shapes using tools like Mapshaper before importing