map-canvas
remotionui/map-canvasFreeComponent
Deterministic MapLibre map mount
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-canvas.jsonSource
1import { useEffect, useRef, useState } from "react";2import {3 AbsoluteFill,4 useDelayRender,5 useVideoConfig,6} from "remotion";7import type { Map } from "maplibre-gl";8import "maplibre-gl/dist/maplibre-gl.css";9import {10 createMapInstance,11 isMapStyleReady,12 mapVignetteStyle,13 MAP_THEME,14 type LngLat,15} from "@/remotion/lib/map-utils";1617export type MapCanvasProps = {18 center: LngLat;19 zoom?: number;20 style?: string;21 onMapReady?: (map: Map) => void;22 backgroundColor?: string;23 showVignette?: boolean;24};2526export const MapCanvas: React.FC<MapCanvasProps> = ({27 center,28 zoom = 7,29 style,30 onMapReady,31 backgroundColor = MAP_THEME.background,32 showVignette = true,33}) => {34 const containerRef = useRef<HTMLDivElement>(null);35 const mapRef = useRef<Map | null>(null);36 const onMapReadyRef = useRef(onMapReady);37 const { delayRender, continueRender } = useDelayRender();38 const { width, height } = useVideoConfig();39 const [loadingHandle] = useState(() => delayRender("Loading map"));4041 onMapReadyRef.current = onMapReady;4243 useEffect(() => {44 if (!containerRef.current) {45 return;46 }4748 const mapInstance = createMapInstance(containerRef.current, width, height, {49 center,50 zoom,51 style,52 });53 mapRef.current = mapInstance;5455 const notifyReady = () => {56 if (!isMapStyleReady(mapInstance)) {57 return;58 }5960 mapInstance.jumpTo({ center, zoom });61 mapInstance.once("idle", () => {62 onMapReadyRef.current?.(mapInstance);63 continueRender(loadingHandle);64 });65 };6667 if (mapInstance.loaded()) {68 notifyReady();69 } else {70 mapInstance.on("load", notifyReady);71 }72 }, [continueRender, height, loadingHandle, style, width, zoom]);7374 useEffect(() => {75 const mapInstance = mapRef.current;76 if (!isMapStyleReady(mapInstance) || !mapInstance.loaded()) {77 return;78 }7980 mapInstance.jumpTo({ center, zoom });81 mapInstance.triggerRepaint();82 }, [center, zoom]);8384 return (85 <AbsoluteFill style={{ backgroundColor }}>86 <div87 ref={containerRef}88 style={{89 width,90 height,91 position: "absolute",92 }}93 />94 {showVignette ? <div style={mapVignetteStyle} /> : null}95 </AbsoluteFill>96 );97};
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 |
