Skip to content

Controls ​

Add interactive controls to your map for zoom, compass, location, and fullscreen.

The MapControls component provides a set of interactive controls that can be positioned on any corner of the map.

tsx
import { Map, MapControls } from "@/registry/map";

export function MapControlsExample() {
  return (
    <div className="h-[420px] w-full">
      <Map center={[2.3522, 48.8566]} zoom={10}>
        <MapControls
          position="top-right"
          showZoom
          showCompass
          showLocate
          showFullscreen
        />
      </Map>
    </div>
  );
}

Props ​

PropTypeDefaultDescription
position"top-left" | "top-right" | "bottom-left" | "bottom-right""bottom-right"Position of the controls on the map.
showZoombooleantrueShow zoom in/out buttons.
showCompassbooleanfalseShow compass button to reset bearing.
showLocatebooleanfalseShow locate button to find user's location.
showFullscreenbooleanfalseShow fullscreen toggle button.
classNamestring—Additional CSS classes for the controls container.
onLocate(coords: { longitude: number; latitude: number }) => void—Callback with user coordinates when located.

基于 mapcn 官方文档整理 · AI 辅助编撰