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

Hooks

React hooks for controlling map components and accessing the Mapbox GL instance.

Available Hooks

useMap

Access the Mapbox GL map instance and loading state. Must be used within a Map component.

import { useMap } from "@/registry/map";

const MyComponent = () => {
  const { map, isLoaded } = useMap();

  const flyToLocation = () => {
    if (!map) return;

    map.flyTo({
      center: [-74.006, 40.7128],
      zoom: 14,
    });
  };

  return (
    <button onClick={flyToLocation} disabled={!isLoaded}>
      Fly to NYC
    </button>
  );
};
Return ValueTypeDescription
mapmapboxgl.Map | nullThe Mapbox GL map instance
isLoadedbooleanWhether the map has finished loading

useRasterVideoControl

Control video layer playback. Pass the layer ID to control a specific MapRasterVideo component.

import { useRasterVideoControl } from "@/registry/map";

const VideoControls = () => {
  const { play, pause, toggle, isPlaying } = useRasterVideoControl("my-video-layer");

  return (
    <div className="flex gap-2">
      <button onClick={play}>Play</button>
      <button onClick={pause}>Pause</button>
      <button onClick={toggle}>
        {isPlaying ? "Pause" : "Play"}
      </button>
    </div>
  );
};
ParameterTypeDescription
layerIdstringThe ID of the video layer to control
Return ValueTypeDescription
play() => voidStart video playback
pause() => voidPause video playback
toggle() => voidToggle between play and pause
isPlayingbooleanCurrent playback state

useLineAnimatedControl

Control animated line playback state. Use with MapLineAnimated component.

import { useLineAnimatedControl, MapLineAnimated } from "@/registry/map";

const AnimatedRoute = () => {
  const { isPlaying, start, stop, toggle } = useLineAnimatedControl();

  return (
    <>
      <MapLineAnimated
        id="route"
        path={routePath}
        autoStart={isPlaying}
      />
      <button onClick={toggle}>
        {isPlaying ? "Stop" : "Start"} Animation
      </button>
    </>
  );
};
Return ValueTypeDescription
start() => voidStart the animation
stop() => voidStop the animation
toggle() => voidToggle animation state
isPlayingbooleanCurrent animation state

useMarkerAnimatedControl

Control animated marker playback state. Use with MapMarkerAnimated component.

import { useMarkerAnimatedControl, MapMarkerAnimated } from "@/registry/map";

const AnimatedMarker = () => {
  const { isPlaying, start, stop, toggle } = useMarkerAnimatedControl();

  return (
    <>
      <MapMarkerAnimated
        id="marker"
        coordinates={pathCoordinates}
        autoStart={isPlaying}
      />
      <button onClick={toggle}>
        {isPlaying ? "Stop" : "Start"} Marker
      </button>
    </>
  );
};
Return ValueTypeDescription
start() => voidStart the animation
stop() => voidStop the animation
toggle() => voidToggle animation state
isPlayingbooleanCurrent animation state

useCameraFollowControl

Control camera follow animation playback. Use with MapCameraFollow component.

import { useCameraFollowControl, MapCameraFollow, MapLine } from "@/registry/map";

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

  return (
    <>
      <MapLine coordinates={route} color="#3b82f6" width={4} />
      <MapCameraFollow
        path={route}
        autoStart={isPlaying}
        onComplete={stop}
        marker
      />
      <button onClick={toggle}>
        {isPlaying ? "Pause" : "Fly Along Route"}
      </button>
    </>
  );
};
Return ValueTypeDescription
start() => voidStart the camera animation
stop() => voidStop the camera animation
toggle() => voidToggle animation state
isPlayingbooleanCurrent animation state

useArcAnimatedControl

Control animated arc playback state. Use with MapArcAnimated component.

import { useArcAnimatedControl, MapArcAnimated } from "@/registry/map";

const AnimatedArc = () => {
  const { isPlaying, start, stop, toggle } = useArcAnimatedControl();

  return (
    <>
      <MapArcAnimated
        id="arc"
        origin={[-74.006, 40.7128]}
        destination={[2.3522, 48.8566]}
      />
      <button onClick={toggle}>
        {isPlaying ? "Stop" : "Start"} Arc
      </button>
    </>
  );
};
Return ValueTypeDescription
start() => voidStart the animation
stop() => voidStop the animation
toggle() => voidToggle animation state
isPlayingbooleanCurrent animation state

useFootprintControl

Control animated footprint start and reset. Returns null until the component with the matching ID mounts.

import { useFootprintControl, MapAnimatedFootprint } from "@/registry/map";

const FootprintControls = () => {
  const control = useFootprintControl("my-footprint");

  return (
    <>
      <MapAnimatedFootprint
        id="my-footprint"
        path={walkingPath}
        autoStart={false}
      />
      <button onClick={control?.start} disabled={control?.isActive}>
        Start Walking
      </button>
      <button onClick={control?.reset} disabled={!control?.isActive}>
        Reset
      </button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the footprint component to control
Return ValueTypeDescription
start() => voidStart the footprint animation
reset() => voidReset and hide all footprint steps
isActivebooleanWhether the animation is currently active

useCycloneControl

Control cyclone animation, intensity, scale, and rotation speed. Returns null until the component with the matching ID mounts.

import { useCycloneControl, MapCyclone } from "@/registry/map";

const Cyclone = () => {
  const control = useCycloneControl("my-cyclone");

  return (
    <>
      <MapCyclone id="my-cyclone" coordinates={[139.6917, 35.6895]} />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Stop" : "Start"} Cyclone
      </button>
      <button onClick={() => control?.setIntensity(1.5)}>
        High Intensity
      </button>
      <button onClick={() => control?.setRotationSpeed(3)}>
        Fast Spin
      </button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the cyclone component to control
Return ValueTypeDescription
start() => voidStart the cyclone animation
stop() => voidStop the cyclone animation
setIntensity(intensity: number) => voidSet the cyclone intensity
setScale(scale: number, instant?: boolean) => voidSet the cyclone scale with optional instant transition
setRotationSpeed(speed: number) => voidSet the cyclone rotation speed (0-4)
isActivebooleanWhether the cyclone is animating
isMovingbooleanWhether the cyclone is moving along a path
progressnumberAnimation progress from 0 to 1
scalenumberCurrent cyclone scale
rotationSpeednumberCurrent rotation speed

useExplosionControl

Trigger and reset explosion effects. Returns null until the component with the matching ID mounts.

import { useExplosionControl, MapExplosion } from "@/registry/map";

const Explosion = () => {
  const control = useExplosionControl("my-explosion");

  return (
    <>
      <MapExplosion id="my-explosion" coordinates={[-74.006, 40.7128]} />
      <button onClick={control?.trigger}>Trigger Explosion</button>
      <button onClick={control?.reset}>Reset</button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the explosion component to control
Return ValueTypeDescription
trigger() => voidTrigger the explosion
reset() => voidReset the explosion state
isExplodingbooleanWhether the explosion is active

useFireControl

Control fire animation and intensity. Returns null until the component with the matching ID mounts.

import { useFireControl, MapFire } from "@/registry/map";

const Fire = () => {
  const control = useFireControl("my-fire");

  return (
    <>
      <MapFire id="my-fire" coordinates={[-122.4194, 37.7749]} />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Extinguish" : "Ignite"}
      </button>
      <button onClick={() => control?.setIntensity(0.9)}>
        Max Intensity
      </button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the fire component to control
Return ValueTypeDescription
start() => voidStart the fire animation
stop() => voidStop the fire animation
setIntensity(intensity: number) => voidSet the fire intensity
isActivebooleanWhether the fire is burning
spreadProgressnumberFire spread progress from 0 to 1

useLightningControl

Trigger lightning strike effects. Returns null until the component with the matching ID mounts.

import { useLightningControl, MapLightning } from "@/registry/map";

const Lightning = () => {
  const control = useLightningControl("my-lightning");

  return (
    <>
      <MapLightning id="my-lightning" coordinates={[-87.6298, 41.8781]} />
      <button onClick={control?.strike}>Strike!</button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the lightning component to control
Return ValueTypeDescription
strike() => voidTrigger a lightning strike
isActivebooleanWhether a strike is in progress

useMeteorControl

Control meteor animation and track impact phases. Returns null until the component with the matching ID mounts.

import { useMeteorControl, MapMeteor } from "@/registry/map";

const Meteor = () => {
  const control = useMeteorControl("my-meteor");

  return (
    <>
      <MapMeteor id="my-meteor" target={[37.6173, 55.7558]} />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Stop" : "Launch"} Meteor
      </button>
      <p>Phase: {control?.phase}</p>
      <p>Progress: {Math.round((control?.progress ?? 0) * 100)}%</p>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the meteor component to control
Return ValueTypeDescription
start() => voidStart the meteor animation
stop() => voidStop the meteor animation
reset() => voidReset the meteor to initial state
isActivebooleanWhether the meteor is animating
progressnumberAnimation progress from 0 to 1
phase"falling" | "impact" | "fading" | "idle"Current meteor phase

useSandstormControl

Control sandstorm animation and intensity. Returns null until the component with the matching ID mounts.

import { useSandstormControl, MapSandstorm } from "@/registry/map";

const Sandstorm = () => {
  const control = useSandstormControl("my-sandstorm");

  return (
    <>
      <MapSandstorm id="my-sandstorm" />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Stop" : "Start"} Sandstorm
      </button>
      <button onClick={() => control?.setIntensity(0.7)}>
        Increase Intensity
      </button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the sandstorm component to control
Return ValueTypeDescription
start() => voidStart the sandstorm animation
stop() => voidStop the sandstorm animation
setIntensity(intensity: number) => voidSet the sandstorm intensity
isActivebooleanWhether the sandstorm is active

useSnowControl

Control snow animation and intensity. Returns null until the component with the matching ID mounts.

import { useSnowControl, MapSnow } from "@/registry/map";

const Snow = () => {
  const control = useSnowControl("my-snow");

  return (
    <>
      <MapSnow id="my-snow" />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Stop" : "Start"} Snow
      </button>
      <button onClick={() => control?.setIntensity(0.5)}>
        Light Snow
      </button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the snow component to control
Return ValueTypeDescription
start() => voidStart the snow animation
stop() => voidStop the snow animation
setIntensity(intensity: number) => voidSet the snow intensity
isActivebooleanWhether the snow is falling

useSteamControl

Control steam animation and intensity. Returns null until the component with the matching ID mounts.

import { useSteamControl, MapSteam } from "@/registry/map";

const Steam = () => {
  const control = useSteamControl("my-steam");

  return (
    <>
      <MapSteam id="my-steam" coordinates={[-155.2833, 19.4069]} />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Stop" : "Start"} Steam
      </button>
      <button onClick={() => control?.setIntensity(0.6)}>
        Medium Steam
      </button>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the steam component to control
Return ValueTypeDescription
start() => voidStart the steam animation
stop() => voidStop the steam animation
setIntensity(intensity: number) => voidSet the steam intensity
isActivebooleanWhether the steam is active

useTsunamiControl

Control tsunami animation and track wave phases. Returns null until the component with the matching ID mounts.

import { useTsunamiControl, MapTsunami } from "@/registry/map";

const Tsunami = () => {
  const control = useTsunamiControl("my-tsunami");

  return (
    <>
      <MapTsunami id="my-tsunami" origin={[142.3728, 38.3215]} target={[141.0, 37.0]} />
      <button onClick={control?.isActive ? control.stop : control?.start}>
        {control?.isActive ? "Stop" : "Start"} Tsunami
      </button>
      <p>Phase: {control?.phase}</p>
      <p>Progress: {Math.round((control?.progress ?? 0) * 100)}%</p>
    </>
  );
};
ParameterTypeDescription
idstringThe ID of the tsunami component to control
Return ValueTypeDescription
start() => voidStart the tsunami animation
stop() => voidStop the tsunami animation
reset() => voidReset the tsunami to initial state
isActivebooleanWhether the tsunami is animating
progressnumberAnimation progress from 0 to 1
phase"approaching" | "crashing" | "receding" | "idle"Current tsunami phase