🎥 Make videos programmatically with React
`@remotion/maptiler`: Add package with MapTiler components (#10627)
Jonny Burger7fbefd41f1a3
diff --git a/bun.lock b/bun.lockindex 48f6ecefd8..a549653039 100644--- a/bun.lock+++ b/bun.lock@@ -749,7 +749,6 @@"name": "@remotion/example","version": "4.0.513","dependencies": {- "@maptiler/sdk": "4.0.2","@mdx-js/loader": "2.3.0","@mdx-js/react": "2.3.0","@mediabunny/ac3": "catalog:",@@ -776,6 +775,7 @@"@remotion/light-leaks": "workspace:*","@remotion/lottie": "workspace:*","@remotion/mac-cursors": "workspace:*",+ "@remotion/maptiler": "workspace:*","@remotion/media": "workspace:*","@remotion/media-parser": "workspace:*","@remotion/media-utils": "workspace:*",@@ -804,7 +804,6 @@"@remotion/zod-types": "workspace:*","@remotion/zod-types-v3": "workspace:*","@shopify/react-native-skia": "2.0.0",- "@turf/turf": "7.3.2","@types/express": "4.17.23","@types/hls.js": "0.13.3","@types/opentype.js": "1.3.4",@@ -1166,6 +1165,26 @@"react-dom": ">=16.8.0",},},+ "packages/maptiler": {+ "name": "@remotion/maptiler",+ "version": "4.0.513",+ "dependencies": {+ "@maptiler/sdk": "4.0.2",+ "@turf/turf": "7.3.2",+ "remotion": "workspace:*",+ },+ "devDependencies": {+ "@remotion/eslint-config-internal": "workspace:*",+ "@typescript/native-preview": "catalog:",+ "eslint": "catalog:",+ "react": "catalog:",+ "react-dom": "catalog:",+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0",+ },+ },"packages/mcp": {"name": "@remotion/mcp","version": "4.0.513",@@ -4221,6 +4240,8 @@"@remotion/mac-cursors": ["@remotion/mac-cursors@workspace:packages/mac-cursors"],+ "@remotion/maptiler": ["@remotion/maptiler@workspace:packages/maptiler"],+"@remotion/mcp": ["@remotion/mcp@workspace:packages/mcp"],"@remotion/media": ["@remotion/media@workspace:packages/media"],@@ -10183,6 +10204,10 @@"@remotion/mac-cursors/react-dom": ["[email protected]", "", { "dependencies": { "scheduler": "^0.27.0" }, "peerDependencies": { "react": "^19.2.3" } }, "sha512-yELu4WmLPw5Mr/lmeEpox5rw3RETacE++JgHqQzd2dg+YbJuat3jH4ingc+WPZhxaoFzdv9y33G+F7Nl5O0GBg=="],+ "@remotion/maptiler/react": ["[email protected]", "", {}, "sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA=="],++ "@remotion/maptiler/react-dom": ["[email protected]", "", { "dependencies": { "scheduler": "^0.27.0" }, "peerDependencies": { "react": "^19.2.3" } }, "sha512-yELu4WmLPw5Mr/lmeEpox5rw3RETacE++JgHqQzd2dg+YbJuat3jH4ingc+WPZhxaoFzdv9y33G+F7Nl5O0GBg=="],+"@remotion/mcp/zod": ["[email protected]", "", {}, "sha512-AvvthqfqrAhNH9dnfmrfKzX5upOdjUVJYFqNSlkmGf64gRaTzlPwz99IHYnVs28qYAybvAlBV+H7pn0saFY4Ig=="],"@remotion/media/react": ["[email protected]", "", {}, "sha512-Ku/hhYbVjOQnXDZFv2+RibmLFGwFdeeKHFcOTlrt7xplBnya5OGn/hIRDsqDiSUcfORsDC7MPxwork8jBwsIWA=="],diff --git a/packages/cli/src/list-of-remotion-packages.ts b/packages/cli/src/list-of-remotion-packages.tsindex bd59798a33..4e81f5e2b3 100644--- a/packages/cli/src/list-of-remotion-packages.ts+++ b/packages/cli/src/list-of-remotion-packages.ts@@ -96,6 +96,7 @@ export const listOfRemotionPackages = ['@remotion/design','@remotion/studio-protocol','@remotion/light-leaks',+ '@remotion/maptiler','@remotion/mac-cursors','@remotion/rough-notation','@remotion/starburst',diff --git a/packages/create-video/src/list-of-remotion-packages.ts b/packages/create-video/src/list-of-remotion-packages.tsindex bd59798a33..4e81f5e2b3 100644--- a/packages/create-video/src/list-of-remotion-packages.ts+++ b/packages/create-video/src/list-of-remotion-packages.ts@@ -96,6 +96,7 @@ export const listOfRemotionPackages = ['@remotion/design','@remotion/studio-protocol','@remotion/light-leaks',+ '@remotion/maptiler','@remotion/mac-cursors','@remotion/rough-notation','@remotion/starburst',diff --git a/packages/example/package.json b/packages/example/package.jsonindex 80f5b0fa04..eefd18871b 100644--- a/packages/example/package.json+++ b/packages/example/package.json@@ -31,7 +31,6 @@"render-transparent": "remotion render --image-format=png --pixel-format=yuva420p --codec=vp8 react-svg out/video.webm"},"dependencies": {- "@maptiler/sdk": "4.0.2","@remotion/studio-protocol": "workspace:*","@mdx-js/loader": "2.3.0","@mdx-js/react": "2.3.0",@@ -57,6 +56,7 @@"@remotion/lambda-client": "workspace:*","@remotion/layout-utils": "workspace:*","@remotion/light-leaks": "workspace:*",+ "@remotion/maptiler": "workspace:*","@remotion/mac-cursors": "workspace:*","@remotion/rough-notation": "workspace:*","@remotion/starburst": "workspace:*",@@ -86,7 +86,6 @@"@remotion/zod-types": "workspace:*","@remotion/zod-types-v3": "workspace:*","@shopify/react-native-skia": "2.0.0",- "@turf/turf": "7.3.2","@types/express": "4.17.23","@types/hls.js": "0.13.3","@types/opentype.js": "1.3.4",diff --git a/packages/example/src/SwitzerlandMap/MapViewport.tsx b/packages/example/src/SwitzerlandMap/MapViewport.tsxdeleted file mode 100644index 344bbd7a99..0000000000--- a/packages/example/src/SwitzerlandMap/MapViewport.tsx+++ /dev/null@@ -1,301 +0,0 @@-import {- config as mapTilerConfig,- Map as MapTilerMap,- MapStyle,-} from '@maptiler/sdk';-import '@maptiler/sdk/dist/maptiler-sdk.css';-import {- forwardRef,- useEffect,- useImperativeHandle,- useMemo,- useRef,- useState,- type ReactNode,-} from 'react';-import {- Interactive,- Sequence,- type InteractiveBaseProps,- type InteractivitySchema,- type SequenceControls,- useDelayRender,-} from 'remotion';-import {MapTilerContext} from './MapTilerContext';--type MapViewportProps = InteractiveBaseProps & {- readonly backgroundColor?: string;- readonly bearing?: number;- readonly centerLatitude?: number;- readonly centerLongitude?: number;- readonly children?: ReactNode;- readonly controls?: SequenceControls;- readonly zoom?: number;-};--const mapViewportSchema = {- ...Interactive.baseSchema,- centerLongitude: {- type: 'number',- min: -180,- max: 180,- step: 0.0001,- default: 0,- description: 'Center longitude',- hiddenFromList: false,- keyframable: true,- },- centerLatitude: {- type: 'number',- min: -90,- max: 90,- step: 0.0001,- default: 0,- description: 'Center latitude',- hiddenFromList: false,- keyframable: true,- },- zoom: {- type: 'number',- min: 0,- max: 22,- step: 0.01,- default: 4,- description: 'Zoom',- hiddenFromList: false,- keyframable: true,- },- bearing: {- type: 'number',- min: -360,- max: 360,- step: 1,- default: 0,- description: 'Bearing',- hiddenFromList: false,- keyframable: true,- },- backgroundColor: {- type: 'color',- default: '#dfe7e2',- description: 'Background color',- },-} as const satisfies InteractivitySchema;--const MissingApiKey = () => {- return (- <div- style={{- alignItems: 'center',- color: '#171a1f',- display: 'flex',- flexDirection: 'column',- fontFamily: 'Arial, sans-serif',- inset: 0,- justifyContent: 'center',- padding: 100,- position: 'absolute',- textAlign: 'center',- }}- >- <div style={{fontSize: 64, fontWeight: 700}}>MapTiler key needed</div>- <div style={{fontSize: 32, lineHeight: 1.4, marginTop: 24}}>- Add REMOTION_MAPTILER_KEY to a .env file in packages/example.- </div>- </div>- );-};--const MapViewportInner = forwardRef<HTMLDivElement, MapViewportProps>(- (- {- backgroundColor = '#dfe7e2',- bearing = 0,- centerLatitude = 0,- centerLongitude = 0,- children,- durationInFrames,- from,- trimBefore,- freeze,- hidden,- name,- showInTimeline,- zoom = 4,- controls,- },- ref,- ) => {- const mapContainerRef = useRef<HTMLDivElement>(null);- const mapRef = useRef<MapTilerMap | null>(null);- const viewportRef = useRef<HTMLDivElement>(null);- const initialCameraRef = useRef({- bearing,- centerLatitude,- centerLongitude,- zoom,- });- const {continueRender, delayRender} = useDelayRender();- const [map, setMap] = useState<MapTilerMap | null>(null);- const [cameraRevision, setCameraRevision] = useState(0);- const [loadingHandle] = useState(() => delayRender('Loading MapTiler map'));- const apiKey = process.env.REMOTION_MAPTILER_KEY;- const contextValue = useMemo(- () => ({cameraRevision, map}),- [cameraRevision, map],- );-- useImperativeHandle(ref, () => viewportRef.current as HTMLDivElement, []);-- useEffect(() => {- if (!apiKey) {- continueRender(loadingHandle);- return;- }-- if (!mapContainerRef.current || mapRef.current) {- return;- }-- const initialCamera = initialCameraRef.current;- mapTilerConfig.apiKey = apiKey;- // Keep MapTiler's logo and attribution visible:- // https://docs.maptiler.com/guides/map-design/attribution/remove-attribution/- const mapInstance = new MapTilerMap({- bearing: initialCamera.bearing,- canvasContextAttributes: {preserveDrawingBuffer: true},- center: [initialCamera.centerLongitude, initialCamera.centerLatitude],- container: mapContainerRef.current,- fadeDuration: 0,- fullscreenControl: false,- geolocateControl: false,- interactive: false,- navigationControl: false,- scaleControl: false,- style: MapStyle.BASIC,- terrainControl: false,- zoom: initialCamera.zoom,- });- mapRef.current = mapInstance;-- mapInstance.on('load', () => {- for (const layer of [...(mapInstance.getStyle().layers ?? [])]) {- if (layer.type === 'symbol' || /other border/i.test(layer.id)) {- mapInstance.removeLayer(layer.id);- }- }-- mapInstance.once('idle', () => {- setMap(mapInstance);- continueRender(loadingHandle);- });- mapInstance.triggerRepaint();- });-- return () => {- mapInstance.remove();- mapRef.current = null;- };- }, [apiKey, continueRender, loadingHandle]);-- useEffect(() => {- if (!map) {- return;- }-- const currentCenter = map.getCenter();- const cameraIsCurrent =- Math.abs(currentCenter.lng - centerLongitude) < 0.0000001 &&- Math.abs(currentCenter.lat - centerLatitude) < 0.0000001 &&- Math.abs(map.getZoom() - zoom) < 0.0000001 &&- Math.abs(map.getBearing() - bearing) < 0.0000001;-- if (cameraIsCurrent) {- return;- }-- const cameraHandle = delayRender('Updating MapTiler camera');- let hasFinished = false;- const finish = () => {- if (hasFinished) {- return;- }-- hasFinished = true;- continueRender(cameraHandle);- };- const onIdle = () => finish();-- map.once('idle', onIdle);- map.jumpTo({- bearing,- center: [centerLongitude, centerLatitude],- zoom,- });- setCameraRevision((revision) => revision + 1);- map.triggerRepaint();-- return () => {- map.off('idle', onIdle);- finish();- };- }, [- bearing,- centerLatitude,- centerLongitude,- continueRender,- delayRender,- map,- zoom,- ]);-- return (- <Sequence- layout="none"- from={from ?? 0}- trimBefore={trimBefore}- durationInFrames={durationInFrames ?? Infinity}- freeze={freeze}- hidden={hidden}- name={name ?? '<MapViewport>'}- showInTimeline={showInTimeline ?? true}- controls={controls}- >- <div- ref={viewportRef}- style={{- backgroundColor,- inset: 0,- overflow: 'hidden',- position: 'absolute',- }}- >- {apiKey ? (- <>- <div- ref={mapContainerRef}- style={{- inset: 0,- position: 'absolute',- }}- />- <MapTilerContext.Provider value={contextValue}>- {children}- </MapTilerContext.Provider>- </>- ) : (- <MissingApiKey />- )}- </div>- </Sequence>- );- },-);--export const MapViewport = Interactive.withSchema({- Component: MapViewportInner,- componentName: '<MapViewport>',- componentIdentity: null,- schema: mapViewportSchema,- supportsEffects: false,-});diff --git a/packages/example/src/SwitzerlandMap/SwitzerlandMap.tsx b/packages/example/src/SwitzerlandMap/SwitzerlandMap.tsxindex 4b238161d8..41af3a3533 100644--- a/packages/example/src/SwitzerlandMap/SwitzerlandMap.tsx+++ b/packages/example/src/SwitzerlandMap/SwitzerlandMap.tsx@@ -1,7 +1,10 @@+import {+ MapRegion,+ MapViewport,+ type MapRegionFeature,+} from '@remotion/maptiler';import {Easing, interpolate, useCurrentFrame} from 'remotion';import austriaData from './austria-10m.json';-import {MapRegion, type MapRegionFeature} from './MapRegion';-import {MapViewport} from './MapViewport';import switzerlandData from './switzerland-10m.json';const switzerland = switzerlandData as MapRegionFeature;@@ -14,6 +17,7 @@ export const SwitzerlandMap = () => {<MapViewportname="Map camera"from={0}+ apiKey={process.env.REMOTION_MAPTILER_KEY ?? null}centerLongitude={interpolate(frame, [124, 164], [8.2275, 13.3347], {easing: [Easing.bezier(0.65, 0, 0.35, 1)],extrapolateLeft: 'clamp',diff --git a/packages/example/src/SwitzerlandMap/ZurichToStuttgartMap.tsx b/packages/example/src/SwitzerlandMap/ZurichToStuttgartMap.tsxindex 5f875709b8..1cd2aa894c 100644--- a/packages/example/src/SwitzerlandMap/ZurichToStuttgartMap.tsx+++ b/packages/example/src/SwitzerlandMap/ZurichToStuttgartMap.tsx@@ -1,8 +1,11 @@+import {+ MapOverlay,+ MapRoute,+ MapViewport,+ type MapRouteFeature,+} from '@remotion/maptiler';import {Easing, interpolate, staticFile, useCurrentFrame} from 'remotion';-import {MapOverlay} from './MapOverlay';import {MapPin} from './MapPin';-import {MapRoute, type MapRouteFeature} from './MapRoute';-import {MapViewport} from './MapViewport';const zurichToStuttgart = {type: 'Feature',@@ -30,6 +33,7 @@ export const ZurichToStuttgartMap = () => {<MapViewportname="Map camera"from={0}+ apiKey={process.env.REMOTION_MAPTILER_KEY ?? null}centerLongitude={interpolate(frame,[106, 179],diff --git a/packages/example/tsconfig.json b/packages/example/tsconfig.jsonindex 316ad24814..5b32c272c3 100644--- a/packages/example/tsconfig.json+++ b/packages/example/tsconfig.json@@ -44,6 +44,7 @@{"path": "../studio-protocol"},{"path": "../light-leaks"},{"path": "../mac-cursors"},+ {"path": "../maptiler"},{"path": "../starburst"},{"path": "../sfx"},{"path": "../layout-utils"},diff --git a/packages/maptiler/.npmignore b/packages/maptiler/.npmignorenew file mode 100644index 0000000000..eb76a5ae81--- /dev/null+++ b/packages/maptiler/.npmignore@@ -0,0 +1,10 @@+dist/test/**+src+eslint.config.mjs+tsconfig.tsbuildinfo+*.tgz+.turbo+tsconfig.json+.prettierrc.js+bundle.ts+dist/cjs/testdiff --git a/packages/maptiler/README.md b/packages/maptiler/README.mdnew file mode 100644index 0000000000..56564d3016--- /dev/null+++ b/packages/maptiler/README.md@@ -0,0 +1,18 @@+# @remotion/maptiler++MapTiler components for Remotion++[](https://npmcharts.com/compare/@remotion/maptiler?minimal=true)++## Installation++```bash+npm install @remotion/maptiler --save-exact+```++When installing a Remotion package, make sure to align the version of all `remotion` and `@remotion/*` packages to the same version.+Remove the `^` character from the version number to use the exact version.++## Usage++This package is currently internal and has no public documentation yet.diff --git a/packages/maptiler/bundle.ts b/packages/maptiler/bundle.tsnew file mode 100644index 0000000000..3f04e4b1b7--- /dev/null+++ b/packages/maptiler/bundle.ts@@ -0,0 +1,37 @@+import path from 'path';+import {build} from 'bun';++if (process.env.NODE_ENV !== 'production') {+ throw new Error('This script must be run using NODE_ENV=production');+}++console.time('Generated.');+const output = await build({+ entrypoints: ['src/index.ts'],+ naming: '[name].mjs',+ external: [+ '@maptiler/sdk',+ '@maptiler/sdk/style.css',+ '@turf/turf',+ 'remotion',+ 'remotion/no-react',+ 'react',+ 'react/jsx-runtime',+ 'react/jsx-dev-runtime',+ 'react-dom',+ ],+});++if (!output.success) {+ console.log(output.logs.join('\n'));+ process.exit(1);+}++for (const file of output.outputs) {+ const str = await file.text();+ const out = path.join('dist', 'esm', file.path);++ await Bun.write(out, str);+}++console.timeEnd('Generated.');diff --git a/packages/maptiler/eslint.config.mjs b/packages/maptiler/eslint.config.mjsnew file mode 100644index 0000000000..ab29acaba0--- /dev/null+++ b/packages/maptiler/eslint.config.mjs@@ -0,0 +1,7 @@+import {remotionFlatConfig} from '@remotion/eslint-config-internal';++const config = remotionFlatConfig({react: true});++export default {+ ...config,+};diff --git a/packages/maptiler/package.json b/packages/maptiler/package.jsonnew file mode 100644index 0000000000..7a2be8166c--- /dev/null+++ b/packages/maptiler/package.json@@ -0,0 +1,57 @@+{+ "name": "@remotion/maptiler",+ "version": "4.0.513",+ "description": "MapTiler components for Remotion",+ "main": "dist/index.js",+ "types": "dist/index.d.ts",+ "module": "dist/esm/index.mjs",+ "repository": {+ "url": "https://github.com/remotion-dev/remotion/tree/main/packages/maptiler"+ },+ "type": "module",+ "scripts": {+ "formatting": "oxfmt src --check",+ "format": "oxfmt src",+ "lint": "eslint src",+ "watch": "tsgo -w",+ "make": "tsgo && bun --env-file=../.env.bundle bundle.ts"+ },+ "author": "Jonny Burger <[email protected]>",+ "contributors": [],+ "license": "Remotion License",+ "bugs": {+ "url": "https://github.com/remotion-dev/remotion/issues"+ },+ "dependencies": {+ "@maptiler/sdk": "4.0.2",+ "@turf/turf": "7.3.2",+ "remotion": "workspace:*"+ },+ "peerDependencies": {+ "react": ">=16.8.0",+ "react-dom": ">=16.8.0"+ },+ "exports": {+ ".": {+ "types": "./dist/index.d.ts",+ "module": "./dist/esm/index.mjs",+ "import": "./dist/esm/index.mjs"+ },+ "./package.json": "./package.json"+ },+ "devDependencies": {+ "react": "catalog:",+ "react-dom": "catalog:",+ "@remotion/eslint-config-internal": "workspace:*",+ "eslint": "catalog:",+ "@typescript/native-preview": "catalog:"+ },+ "keywords": [+ "remotion",+ "maptiler"+ ],+ "publishConfig": {+ "access": "public"+ },+ "homepage": "https://github.com/remotion-dev/remotion/tree/main/packages/maptiler"+}diff --git a/packages/example/src/SwitzerlandMap/MapOverlay.tsx b/packages/maptiler/src/MapOverlay.tsxsimilarity index 50%rename from packages/example/src/SwitzerlandMap/MapOverlay.tsxrename to packages/maptiler/src/MapOverlay.tsxindex 0355caaf4c..6d42b57e82 100644--- a/packages/example/src/SwitzerlandMap/MapOverlay.tsx+++ b/packages/maptiler/src/MapOverlay.tsx@@ -3,6 +3,7 @@ import {useContext,useImperativeHandle,useRef,+ type ForwardRefRenderFunction,type ReactNode,} from 'react';import {@@ -46,60 +47,63 @@ const mapOverlaySchema = {...Interactive.transformSchema,} as const satisfies InteractivitySchema;-const MapOverlayInner = forwardRef<HTMLDivElement, MapOverlayProps>(- (- {- children,- latitude,- longitude,- style,- durationInFrames,- from,- trimBefore,- freeze,- hidden,- name,- showInTimeline,- controls,- },- ref,- ) => {- const {map} = useContext(MapTilerContext);- const refForOutline = useRef<HTMLDivElement>(null);- const point = map?.project([longitude, latitude]);+const MapOverlayRefForwardingFunction: ForwardRefRenderFunction<+ HTMLDivElement,+ MapOverlayProps+> = (+ {+ children,+ latitude,+ longitude,+ style,+ durationInFrames,+ from,+ trimBefore,+ freeze,+ hidden,+ name,+ showInTimeline,+ controls,+ },+ ref,+) => {+ const {map} = useContext(MapTilerContext);+ const refForOutline = useRef<HTMLDivElement>(null);+ const point = map?.project([longitude, latitude]);- useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);+ useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);- return (- <Sequence- layout="none"- from={from ?? 0}- trimBefore={trimBefore}- durationInFrames={durationInFrames ?? Infinity}- freeze={freeze}- hidden={hidden}- name={name ?? '<MapOverlay>'}- showInTimeline={showInTimeline ?? true}- controls={controls}- outlineRef={refForOutline}+ return (+ <Sequence+ layout="none"+ from={from ?? 0}+ trimBefore={trimBefore}+ durationInFrames={durationInFrames ?? Infinity}+ freeze={freeze}+ hidden={hidden}+ name={name ?? '<MapOverlay>'}+ showInTimeline={showInTimeline ?? true}+ controls={controls}+ outlineRef={refForOutline}+ >+ <div+ ref={refForOutline}+ style={{+ left: point?.x ?? 0,+ pointerEvents: 'none',+ position: 'absolute',+ top: point?.y ?? 0,+ zIndex: 1,+ ...style,+ }}>- <div- ref={refForOutline}- style={{- left: point?.x ?? 0,- pointerEvents: 'none',- position: 'absolute',- top: point?.y ?? 0,- zIndex: 1,- ...style,- }}- >- {children}- </div>- </Sequence>- );- },-);+ {children}+ </div>+ </Sequence>+ );+};++const MapOverlayInner = forwardRef(MapOverlayRefForwardingFunction);export const MapOverlay = Interactive.withSchema({Component: MapOverlayInner,diff --git a/packages/example/src/SwitzerlandMap/MapRegion.tsx b/packages/maptiler/src/MapRegion.tsxsimilarity index 85%rename from packages/example/src/SwitzerlandMap/MapRegion.tsxrename to packages/maptiler/src/MapRegion.tsxindex 86ae0e88e3..94203ce96f 100644--- a/packages/example/src/SwitzerlandMap/MapRegion.tsx+++ b/packages/maptiler/src/MapRegion.tsx@@ -1,4 +1,4 @@-import {GeoJSONSource} from '@maptiler/sdk';+import type {GeoJSONSource} from '@maptiler/sdk';import {length as getLineLength, lineSliceAlong, lineString} from '@turf/turf';import {forwardRef,@@ -8,6 +8,7 @@ import {useMemo,useRef,useState,+ type ForwardRefRenderFunction,type RefObject,} from 'react';import {@@ -152,6 +153,7 @@ const MapRegionDrawing = ({type: 'fill',});}+map.setPaintProperty(fillSourceId, 'fill-color', fillColor);if (!map.getSource(outlineSourceId)) {@@ -176,6 +178,7 @@ const MapRegionDrawing = ({type: 'line',});}+map.setPaintProperty(outlineGlowLayerId,'line-opacity',@@ -197,6 +200,7 @@ const MapRegionDrawing = ({type: 'line',});}+map.setPaintProperty(outlineSourceId, 'line-color', strokeColor);map.setPaintProperty(outlineSourceId, 'line-width', strokeWidth);@@ -326,60 +330,63 @@ const MapRegionBounds = ({);};-const MapRegionInner = forwardRef<HTMLDivElement, MapRegionProps>(- (- {- feature,- fill = 0,- fillColor,- glow = 0.72,- id,- progress = 1,- strokeColor = '#8f1712',- strokeWidth = 9,- durationInFrames,- from,- trimBefore,- freeze,- hidden,- name,- showInTimeline,- controls,- },- ref,- ) => {- const refForOutline = useRef<HTMLDivElement>(null);-- useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);-- return (- <Sequence- layout="none"- from={from ?? 0}- trimBefore={trimBefore}- durationInFrames={durationInFrames ?? Infinity}- freeze={freeze}- hidden={hidden}- name={name ?? `<${feature.properties.name}>`}- showInTimeline={showInTimeline ?? true}- controls={controls}- outlineRef={refForOutline}- >- <MapRegionDrawing- feature={feature}- fill={fill}- fillColor={fillColor}- glow={glow}- id={id}- progress={progress}- strokeColor={strokeColor}- strokeWidth={strokeWidth}- />- <MapRegionBounds feature={feature} refForOutline={refForOutline} />- </Sequence>- );+const MapRegionRefForwardingFunction: ForwardRefRenderFunction<+ HTMLDivElement,+ MapRegionProps+> = (+ {+ feature,+ fill = 0,+ fillColor,+ glow = 0.72,+ id,+ progress = 1,+ strokeColor = '#8f1712',+ strokeWidth = 9,+ durationInFrames,+ from,+ trimBefore,+ freeze,+ hidden,+ name,+ showInTimeline,+ controls,},-);+ ref,+) => {+ const refForOutline = useRef<HTMLDivElement>(null);++ useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);++ return (+ <Sequence+ layout="none"+ from={from ?? 0}+ trimBefore={trimBefore}+ durationInFrames={durationInFrames ?? Infinity}+ freeze={freeze}+ hidden={hidden}+ name={name ?? `<${feature.properties.name}>`}+ showInTimeline={showInTimeline ?? true}+ controls={controls}+ outlineRef={refForOutline}+ >+ <MapRegionDrawing+ feature={feature}+ fill={fill}+ fillColor={fillColor}+ glow={glow}+ id={id}+ progress={progress}+ strokeColor={strokeColor}+ strokeWidth={strokeWidth}+ />+ <MapRegionBounds feature={feature} refForOutline={refForOutline} />+ </Sequence>+ );+};++const MapRegionInner = forwardRef(MapRegionRefForwardingFunction);export const MapRegion = Interactive.withSchema({Component: MapRegionInner,diff --git a/packages/example/src/SwitzerlandMap/MapRoute.tsx b/packages/maptiler/src/MapRoute.tsxsimilarity index 82%rename from packages/example/src/SwitzerlandMap/MapRoute.tsxrename to packages/maptiler/src/MapRoute.tsxindex 99ebaab2cd..3866842f1e 100644--- a/packages/example/src/SwitzerlandMap/MapRoute.tsx+++ b/packages/maptiler/src/MapRoute.tsx@@ -1,4 +1,4 @@-import {GeoJSONSource} from '@maptiler/sdk';+import type {GeoJSONSource} from '@maptiler/sdk';import {length as getLineLength, lineSliceAlong, lineString} from '@turf/turf';import {forwardRef,@@ -8,6 +8,7 @@ import {useMemo,useRef,useState,+ type ForwardRefRenderFunction,type RefObject,} from 'react';import {@@ -127,6 +128,7 @@ const MapRouteDrawing = ({type: 'line',});}+map.setPaintProperty(glowLayerId,'line-opacity',@@ -148,6 +150,7 @@ const MapRouteDrawing = ({type: 'line',});}+map.setPaintProperty(sourceId, 'line-color', strokeColor);map.setPaintProperty(sourceId, 'line-width', strokeWidth);@@ -259,56 +262,59 @@ const MapRouteBounds = ({);};-const MapRouteInner = forwardRef<HTMLDivElement, MapRouteProps>(- (- {- feature,- glow = 0.72,- id,- progress = 1,- strokeColor = '#006cff',- strokeWidth = 9,- durationInFrames,- from,- trimBefore,- freeze,- hidden,- name,- showInTimeline,- controls,- },- ref,- ) => {- const refForOutline = useRef<HTMLDivElement>(null);+const MapRouteRefForwardingFunction: ForwardRefRenderFunction<+ HTMLDivElement,+ MapRouteProps+> = (+ {+ feature,+ glow = 0.72,+ id,+ progress = 1,+ strokeColor = '#006cff',+ strokeWidth = 9,+ durationInFrames,+ from,+ trimBefore,+ freeze,+ hidden,+ name,+ showInTimeline,+ controls,+ },+ ref,+) => {+ const refForOutline = useRef<HTMLDivElement>(null);- useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);+ useImperativeHandle(ref, () => refForOutline.current as HTMLDivElement, []);- return (- <Sequence- layout="none"- from={from ?? 0}- trimBefore={trimBefore}- durationInFrames={durationInFrames ?? Infinity}- freeze={freeze}- hidden={hidden}- name={name ?? `<${feature.properties.name}>`}- showInTimeline={showInTimeline ?? true}- controls={controls}- outlineRef={refForOutline}- >- <MapRouteDrawing- feature={feature}- glow={glow}- id={id}- progress={progress}- strokeColor={strokeColor}- strokeWidth={strokeWidth}- />- <MapRouteBounds feature={feature} refForOutline={refForOutline} />- </Sequence>- );- },-);+ return (+ <Sequence+ layout="none"+ from={from ?? 0}+ trimBefore={trimBefore}+ durationInFrames={durationInFrames ?? Infinity}+ freeze={freeze}+ hidden={hidden}+ name={name ?? `<${feature.properties.name}>`}+ showInTimeline={showInTimeline ?? true}+ controls={controls}+ outlineRef={refForOutline}+ >+ <MapRouteDrawing+ feature={feature}+ glow={glow}+ id={id}+ progress={progress}+ strokeColor={strokeColor}+ strokeWidth={strokeWidth}+ />+ <MapRouteBounds feature={feature} refForOutline={refForOutline} />+ </Sequence>+ );+};++const MapRouteInner = forwardRef(MapRouteRefForwardingFunction);export const MapRoute = Interactive.withSchema({Component: MapRouteInner,diff --git a/packages/example/src/SwitzerlandMap/MapTilerContext.ts b/packages/maptiler/src/MapTilerContext.tssimilarity index 100%rename from packages/example/src/SwitzerlandMap/MapTilerContext.tsrename to packages/maptiler/src/MapTilerContext.tsdiff --git a/packages/maptiler/src/MapViewport.tsx b/packages/maptiler/src/MapViewport.tsxnew file mode 100644index 0000000000..9e431d76d3--- /dev/null+++ b/packages/maptiler/src/MapViewport.tsx@@ -0,0 +1,302 @@+import {Map as MapTilerMap, MapStyle} from '@maptiler/sdk';+import '@maptiler/sdk/style.css';+import type {ForwardRefRenderFunction, ReactNode} from 'react';+import {+ forwardRef,+ useEffect,+ useImperativeHandle,+ useMemo,+ useRef,+ useState,+} from 'react';+import {+ Interactive,+ Sequence,+ type InteractiveBaseProps,+ type InteractivitySchema,+ type SequenceControls,+ useDelayRender,+} from 'remotion';+import {MapTilerContext} from './MapTilerContext';++type MapViewportProps = InteractiveBaseProps & {+ readonly apiKey: string | null;+ readonly backgroundColor?: string;+ readonly bearing?: number;+ readonly centerLatitude?: number;+ readonly centerLongitude?: number;+ readonly children?: ReactNode;+ readonly controls?: SequenceControls;+ readonly zoom?: number;+};++const mapViewportSchema = {+ ...Interactive.baseSchema,+ centerLongitude: {+ type: 'number',+ min: -180,+ max: 180,+ step: 0.0001,+ default: 0,+ description: 'Center longitude',+ hiddenFromList: false,+ keyframable: true,+ },+ centerLatitude: {+ type: 'number',+ min: -90,+ max: 90,+ step: 0.0001,+ default: 0,+ description: 'Center latitude',+ hiddenFromList: false,+ keyframable: true,+ },+ zoom: {+ type: 'number',+ min: 0,+ max: 22,+ step: 0.01,+ default: 4,+ description: 'Zoom',+ hiddenFromList: false,+ keyframable: true,+ },+ bearing: {+ type: 'number',+ min: -360,+ max: 360,+ step: 1,+ default: 0,+ description: 'Bearing',+ hiddenFromList: false,+ keyframable: true,+ },+ backgroundColor: {+ type: 'color',+ default: '#dfe7e2',+ description: 'Background color',+ },+} as const satisfies InteractivitySchema;++const MissingApiKey = () => {+ return (+ <div+ style={{+ alignItems: 'center',+ color: '#171a1f',+ display: 'flex',+ flexDirection: 'column',+ fontFamily: 'Arial, sans-serif',+ inset: 0,+ justifyContent: 'center',+ padding: 100,+ position: 'absolute',+ textAlign: 'center',+ }}+ >+ <div style={{fontSize: 64, fontWeight: 700}}>MapTiler key needed</div>+ <div style={{fontSize: 32, lineHeight: 1.4, marginTop: 24}}>+ Pass an apiKey prop to <MapViewport>.+ </div>+ </div>+ );+};++const MapViewportRefForwardingFunction: ForwardRefRenderFunction<+ HTMLDivElement,+ MapViewportProps+> = (+ {+ apiKey,+ backgroundColor = '#dfe7e2',+ bearing = 0,+ centerLatitude = 0,+ centerLongitude = 0,+ children,+ durationInFrames,+ from,+ trimBefore,+ freeze,+ hidden,+ name,+ showInTimeline,+ zoom = 4,+ controls,+ },+ ref,+) => {+ const mapContainerRef = useRef<HTMLDivElement>(null);+ const mapRef = useRef<MapTilerMap | null>(null);+ const viewportRef = useRef<HTMLDivElement>(null);+ const initialCameraRef = useRef({+ bearing,+ centerLatitude,+ centerLongitude,+ zoom,+ });+ const {continueRender, delayRender} = useDelayRender();+ const [map, setMap] = useState<MapTilerMap | null>(null);+ const [cameraRevision, setCameraRevision] = useState(0);+ const [loadingHandle] = useState(() => delayRender('Loading MapTiler map'));+ const contextValue = useMemo(+ () => ({cameraRevision, map}),+ [cameraRevision, map],+ );++ useImperativeHandle(ref, () => viewportRef.current as HTMLDivElement, []);++ useEffect(() => {+ if (!apiKey) {+ continueRender(loadingHandle);+ return;+ }++ if (!mapContainerRef.current || mapRef.current) {+ return;+ }++ const initialCamera = initialCameraRef.current;+ // Keep MapTiler's logo and attribution visible:+ // https://docs.maptiler.com/guides/map-design/attribution/remove-attribution/+ const mapInstance = new MapTilerMap({+ apiKey,+ bearing: initialCamera.bearing,+ canvasContextAttributes: {preserveDrawingBuffer: true},+ center: [initialCamera.centerLongitude, initialCamera.centerLatitude],+ container: mapContainerRef.current,+ fadeDuration: 0,+ fullscreenControl: false,+ geolocateControl: false,+ interactive: false,+ navigationControl: false,+ scaleControl: false,+ style: MapStyle.BASIC,+ terrainControl: false,+ zoom: initialCamera.zoom,+ });+ mapRef.current = mapInstance;++ mapInstance.on('load', () => {+ for (const layer of [...(mapInstance.getStyle().layers ?? [])]) {+ if (layer.type === 'symbol' || /other border/i.test(layer.id)) {+ mapInstance.removeLayer(layer.id);+ }+ }++ mapInstance.once('idle', () => {+ setMap(mapInstance);+ continueRender(loadingHandle);+ });+ mapInstance.triggerRepaint();+ });++ return () => {+ mapInstance.remove();+ mapRef.current = null;+ };+ }, [apiKey, continueRender, loadingHandle]);++ useEffect(() => {+ if (!map) {+ return;+ }++ const currentCenter = map.getCenter();+ const cameraIsCurrent =+ Math.abs(currentCenter.lng - centerLongitude) < 0.0000001 &&+ Math.abs(currentCenter.lat - centerLatitude) < 0.0000001 &&+ Math.abs(map.getZoom() - zoom) < 0.0000001 &&+ Math.abs(map.getBearing() - bearing) < 0.0000001;++ if (cameraIsCurrent) {+ return;+ }++ const cameraHandle = delayRender('Updating MapTiler camera');+ let hasFinished = false;+ const finish = () => {+ if (hasFinished) {+ return;+ }++ hasFinished = true;+ continueRender(cameraHandle);+ };++ const onIdle = () => finish();++ map.once('idle', onIdle);+ map.jumpTo({+ bearing,+ center: [centerLongitude, centerLatitude],+ zoom,+ });+ setCameraRevision((revision) => revision + 1);+ map.triggerRepaint();++ return () => {+ map.off('idle', onIdle);+ finish();+ };+ }, [+ bearing,+ centerLatitude,+ centerLongitude,+ continueRender,+ delayRender,+ map,+ zoom,+ ]);++ return (+ <Sequence+ layout="none"+ from={from ?? 0}+ trimBefore={trimBefore}+ durationInFrames={durationInFrames ?? Infinity}+ freeze={freeze}+ hidden={hidden}+ name={name ?? '<MapViewport>'}+ showInTimeline={showInTimeline ?? true}+ controls={controls}+ >+ <div+ ref={viewportRef}+ style={{+ backgroundColor,+ inset: 0,+ overflow: 'hidden',+ position: 'absolute',+ }}+ >+ {apiKey ? (+ <>+ <div+ ref={mapContainerRef}+ style={{+ inset: 0,+ position: 'absolute',+ }}+ />+ <MapTilerContext.Provider value={contextValue}>+ {children}+ </MapTilerContext.Provider>+ </>+ ) : (+ <MissingApiKey />+ )}+ </div>+ </Sequence>+ );+};++const MapViewportInner = forwardRef(MapViewportRefForwardingFunction);++export const MapViewport = Interactive.withSchema({+ Component: MapViewportInner,+ componentName: '<MapViewport>',+ componentIdentity: null,+ schema: mapViewportSchema,+ supportsEffects: false,+});diff --git a/packages/maptiler/src/css.d.ts b/packages/maptiler/src/css.d.tsnew file mode 100644index 0000000000..35306c6fc9--- /dev/null+++ b/packages/maptiler/src/css.d.ts@@ -0,0 +1 @@+declare module '*.css';diff --git a/packages/maptiler/src/index.ts b/packages/maptiler/src/index.tsnew file mode 100644index 0000000000..5609c9b88b--- /dev/null+++ b/packages/maptiler/src/index.ts@@ -0,0 +1,4 @@+export {MapOverlay} from './MapOverlay';+export {MapRegion, type MapRegionFeature} from './MapRegion';+export {MapRoute, type MapRouteFeature} from './MapRoute';+export {MapViewport} from './MapViewport';diff --git a/packages/maptiler/tsconfig.json b/packages/maptiler/tsconfig.jsonnew file mode 100644index 0000000000..22b60bbe95--- /dev/null+++ b/packages/maptiler/tsconfig.json@@ -0,0 +1,16 @@+{+ "extends": "../tsconfig.settings.json",+ "compilerOptions": {+ "rootDir": "src",+ "outDir": "dist",+ "jsx": "react-jsx",+ "skipLibCheck": true,+ "target": "ES2022",+ "module": "es2020",+ "moduleResolution": "bundler",+ "declaration": true,+ "emitDeclarationOnly": true+ },+ "include": ["src"],+ "references": [{"path": "../core"}]+}diff --git a/packages/studio-shared/src/package-info.ts b/packages/studio-shared/src/package-info.tsindex 190f500bca..24e83aedc1 100644--- a/packages/studio-shared/src/package-info.ts+++ b/packages/studio-shared/src/package-info.ts@@ -99,6 +99,7 @@ const allPackages = ['studio-protocol','light-leaks','mac-cursors',+ 'maptiler','rough-notation','starburst','vercel',@@ -258,6 +259,7 @@ export const descriptions: {[key in Pkgs]: string | null} = {'Create Element payloads and request installation into Remotion Studio','light-leaks': 'Light leak effects for Remotion','mac-cursors': 'macOS cursor components for Remotion',+ maptiler: 'MapTiler components for Remotion','rough-notation': 'Rough annotation primitives for Remotion','player-a11y': 'Internal accessibility wrapper around @remotion/player',starburst: 'Starburst ray effect for Remotion',@@ -375,6 +377,7 @@ export const installableMap: {[key in Pkgs]: boolean} = {packageName: '@remotion/mac-cursors',releaseVersion: VERSION,}),+ maptiler: false,'rough-notation': true,starburst: shouldReleasePackage({packageName: '@remotion/starburst',@@ -486,6 +489,7 @@ export const apiDocs: {[key in Pkgs]: string | null} = {'studio-protocol': 'https://www.remotion.dev/docs/studio-protocol','light-leaks': 'https://www.remotion.dev/docs/light-leaks','mac-cursors': 'https://www.remotion.dev/docs/mac-cursors',+ maptiler: null,'rough-notation': 'https://www.remotion.dev/docs/rough-notation',starburst: 'https://www.remotion.dev/docs/starburst',vercel: 'https://www.remotion.dev/docs/vercel/api',diff --git a/tsconfig.json b/tsconfig.jsonindex 94935f531e..81aeabe508 100644--- a/tsconfig.json+++ b/tsconfig.json@@ -270,6 +270,9 @@{"path": "./packages/light-leaks"},+ {+ "path": "./packages/maptiler"+ },{"path": "./packages/mac-cursors"},