map-route
remotionui/map-routeFreeComponent
Animated GeoJSON route line on a map
Live preview
live · rendered by the registry
Rendered by remotionui on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://remotionui.com/r/map-route.jsonSource
1import type { Feature, LineString } from "geojson";2import { useEffect } from "react";3import {4 Easing,5 interpolate,6 useCurrentFrame,7 useDelayRender,8 useVideoConfig,9} from "remotion";10import type { GeoJSONSource, Map } from "maplibre-gl";11import * as turf from "@turf/turf";12import {13 clampProgress,14 hasMapLayer,15 hasMapSource,16 isMapStyleReady,17 MAP_THEME,18 pointAlongRoute,19 removeMapLayer,20 removeMapSource,21 sliceRouteByProgress,22} from "@/remotion/lib/map-utils";23import { EASING } from "@/remotion/lib/motion-tokens";2425export type MapRouteProps = {26 map: Map | null;27 route: Feature<LineString>;28 progress?: number;29 lineColor?: string;30 glowColor?: string;31 lineWidth?: number;32 sourceId?: string;33 layerId?: string;34 showHead?: boolean;35};3637export const MapRoute: React.FC<MapRouteProps> = ({38 map,39 route,40 progress: progressProp,41 lineColor = MAP_THEME.route,42 glowColor = MAP_THEME.routeGlow,43 lineWidth = 5,44 sourceId = "trace",45 layerId = "trace-line",46 showHead = true,47}) => {48 const frame = useCurrentFrame();49 const { durationInFrames } = useVideoConfig();50 const { delayRender, continueRender } = useDelayRender();5152 const progress =53 progressProp ??54 clampProgress(55 interpolate(frame, [8, durationInFrames - 12], [0, 1], {56 extrapolateLeft: "clamp",57 extrapolateRight: "clamp",58 easing: EASING.enter,59 }),60 );6162 useEffect(() => {63 if (!isMapStyleReady(map)) {64 return;65 }6667 const partialRoute = sliceRouteByProgress(route, 0);68 const headSourceId = `${sourceId}-head`;6970 if (!hasMapSource(map, sourceId)) {71 map.addSource(sourceId, {72 type: "geojson",73 data: partialRoute,74 });7576 map.addLayer({77 id: `${layerId}-glow`,78 type: "line",79 source: sourceId,80 layout: {81 "line-cap": "round",82 "line-join": "round",83 },84 paint: {85 "line-color": glowColor,86 "line-width": lineWidth * 2.8,87 "line-blur": 1.2,88 "line-opacity": 0.72,89 },90 });9192 map.addLayer({93 id: layerId,94 type: "line",95 source: sourceId,96 layout: {97 "line-cap": "round",98 "line-join": "round",99 },100 paint: {101 "line-color": lineColor,102 "line-width": lineWidth,103 "line-opacity": 0.96,104 },105 });106107 if (showHead) {108 map.addSource(headSourceId, {109// … truncated
More from remotionui
All 127 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| audio-pulseaudio-pulse | remotionui | Components | Free | no deps | |
| audiogram-barsaudiogram-bars | remotionui | Components | Free | no deps | |
| blur-focus-inblur-focus-in | remotionui | Components | Free | no deps | |
| blur-inblur-in | remotionui | Components | Free | no deps | |
| blur-revealblur-reveal | remotionui | Components | Free | no deps | |
| caption-highlightcaption-highlight | remotionui | Components | Free | no deps | |
| chromatic-aberration-wipechromatic-aberration-wipe | remotionui | Components | Free | no deps | |
| confetti-burstconfetti-burst | remotionui | Components | Free | no deps |
