Beautiful map components. 100% Free, Zero config, one command setup.
TypeScript
"use client";
import { useEffect, useState } from "react";
import { Map, useMap } from "@/registry/map";
import { Button } from "@/components/ui/button";
import { RotateCcw, Mountain } from "lucide-react";
function MapController() {
const { map, isLoaded } = useMap();
const [pitch, setPitch] = useState(0);
const [bearing, setBearing] = useState(0);
useEffect(() => {
if (!map || !isLoaded) return;
const handleMove = () => {
setPitch(Math.round(map.getPitch()));
setBearing(Math.round(map.getBearing()));
};
map.on("move", handleMove);
return () => {
map.off("move", handleMove);
};
}, [map, isLoaded]);
const handle3DView = () => {
map?.easeTo({
pitch: 60,
bearing: -20,
duration: 1000,
});
};
const handleReset = () => {
map?.easeTo({
pitch: 0,
bearing: 0,
duration: 1000,
});
};
if (!isLoaded) return null;
return (
<div className="absolute top-3 left-3 z-10 flex flex-col gap-2">
<div className="flex gap-2">
<Button size="sm" variant="secondary" onClick={handle3DView}>
<Mountain className="mr-1.5 size-4" />
3D View
</Button>
<Button size="sm" variant="secondary" onClick={handleReset}>
<RotateCcw className="mr-1.5 size-4" />
Reset
</Button>
</div>
<div className="bg-background/90 rounded-md border px-3 py-2 font-mono text-xs backdrop-blur">
<div>Pitch: {pitch}°</div>
<div>Bearing: {bearing}°</div>
</div>
</div>
);
}
export function AdvancedUsageExample() {
return (
<div className="h-[420px] w-full">
<Map center={[-73.9857, 40.7484]} zoom={15}>
<MapController />
</Map>
</div>
);
}