mapcn-react-native
Core

Controls

MapControls -- zoom and locate-me buttons rendered through Map's overlay mechanism, identical on both renderers.

Renderer support: MapLibre ✓  ·  Mapbox ✓

npx mapcn-rn add controls
import { MapControls } from "@/components/ui/mapcn";

Overview

MapControls renders through Map's overlay mechanism (the same one that makes MapPopup, MapLegend, and MapStyleSwitcher byte-identical across renderers), so this file needs no renderer branching even though only Mapbox strictly requires the portal.

Zoom buttons call useMap().zoomBy(...), so displayed zoom never drifts from the actual camera the way a component tracking its own zoom counter could. The locate button requests foreground location permission via expo-location, then flies the camera to the resulting position.

Props

PropTypeDefaultDescription
position"top-left" | "top-right" | "bottom-left" | "bottom-right""bottom-right"Overlay corner.
showZoombooleantrueShows the +/- zoom buttons.
showLocatebooleanfalseShows the locate-me button.
classNamestringUniwind/NativeWind classes on the outer container.
onLocate(coords: { longitude: number; latitude: number }) => voidFires with the resolved coordinates after a successful locate.

Example

import { Map } from "@/components/ui/mapcn";
import { MapControls } from "@/components/ui/mapcn";

export function MapWithControls() {
  return (
    <Map defaultViewport={{ center: [-122.4194, 37.7749], zoom: 12 }} className="flex-1">
      <MapControls showZoom showLocate position="bottom-right" onLocate={(c) => console.log(c)} />
    </Map>
  );
}

Live example

map-controls example screenshot

Permissions

showLocate requires foreground location permission (NSLocationWhenInUseUsageDescription on iOS, ACCESS_FINE_LOCATION/ACCESS_COARSE_LOCATION on Android). See Permissions.

Map · Location tracking · Style switcher

On this page