# Spinning Globe

A globe rotating around its vertical axis, with editable speed, longitude, and shading.

Element page: [https://www.remotion.dev/elements/maps/spinning-globe/](https://www.remotion.dev/elements/maps/spinning-globe/)

## Installation

Install this Element into a composition of your Remotion project:

```sh
npx remotion elements use https://www.remotion.dev/elements/maps/spinning-globe/ --composition <composition-id> --yes
```

Replace `<composition-id>` with the ID of the composition to add the Element to. The command installs the dependencies, downloads the assets, writes the source file and adds the Element to the composition. See [`npx remotion elements use`](https://www.remotion.dev/docs/cli/elements/use.md).

## Manual installation

To install the Element manually instead, save the source below as `spinning-globe.element.tsx` in your Remotion project and import its exported component.

## Source

```tsx
import {sphere} from '@remotion/effects/sphere';
import React from 'react';
import {
	CanvasImage,
	Interactive,
	useCurrentFrame,
	useVideoConfig,
	type InteractiveTransformProps,
	type InteractivitySchema,
} from 'remotion';

type SpinningGlobeProps = InteractiveTransformProps & {
	readonly src: string;
	readonly speed?: number;
	readonly longitude?: number;
	readonly shading?: number;
};

const spinningGlobeSchema = {
	src: {
		type: 'asset',
		assetType: 'image',
		default: 'https://remotion.media/earth.jpg',
		description: 'Globe texture',
		keyframable: false,
	},
	speed: {
		type: 'number',
		min: -1,
		max: 1,
		step: 0.01,
		default: 1 / 8,
		description: 'Revolutions per second',
		hiddenFromList: false,
	},
	longitude: {
		type: 'rotation-degrees',
		default: 0,
		description: 'Starting longitude',
	},
	shading: {
		type: 'number',
		min: 0,
		max: 1,
		step: 0.01,
		default: 0.35,
		description: 'Shading',
		hiddenFromList: false,
	},
} as const satisfies InteractivitySchema;

const SpinningGlobeInner: React.FC<SpinningGlobeProps> = ({
	src,
	speed = 1 / 8,
	longitude = 0,
	shading = 0.35,
	style,
}) => {
	const frame = useCurrentFrame();
	const {fps} = useVideoConfig();

	return (
		<div style={{width: 840, height: 840, ...style}}>
			<CanvasImage
				src={src}
				pauseWhenLoading
				width={840}
				height={840}
				fit="fill"
				effects={[
					sphere({
						radius: 420,
						rotationY: longitude + (frame / fps) * speed * 360,
						shading,
					}),
				]}
			/>
		</div>
	);
};

export const SpinningGlobe = Interactive.create({
	Component: SpinningGlobeInner,
	componentName: '<SpinningGlobe>',
	schema: spinningGlobeSchema,
});
```

