This library is not production-ready yet. Developers should use it with caution and expect breaking changes.

Camera Follow

Animate the camera along a path for immersive fly-through experiences.

Installation

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

npx shadcn@latest add https://www.terrae.dev/map.json

Then install the camera follow component:

npx shadcn@latest add https://www.terrae.dev/camera-follow.json

With Navigation Marker

Add a navigation marker that follows the camera position. Use marker for the default arrow, or pass a custom React element.

Control Hook

Use the useCameraFollowControl hook to control the animation externally. This provides isPlaying, start, stop, and toggle functions.

const { isPlaying, start, stop, toggle } = useCameraFollowControl()

<MapCameraFollow
  path={route}
  autoStart={isPlaying}
  onComplete={stop}
/>

Properties

PropertyTypeDefaultDescription
path[number, number][]requiredArray of coordinates for the camera to follow
durationnumber20000Animation duration in milliseconds
zoomnumber14Camera zoom level during flight
pitchnumber60Camera tilt angle (0-85 degrees)
autoStartbooleantrueStart animation automatically on mount
loopbooleanfalseLoop the animation continuously
loopDelaynumber1000Delay before restarting loop in milliseconds
onComplete() => void-Callback when animation completes
markerboolean | ReactNode-Navigation marker (true for default arrow, or custom element)
markerSizenumber48Size of the default navigation marker in pixels

Notes

  • The camera bearing is calculated automatically based on the path direction
  • Combine with MapLine to show the route the camera is following
  • Works best with the standard map style for 3D building context
  • Path requires at least 2 coordinates