Skip to content

shadcn.io is an independent project built on shadcn/ui

Components

Free

Map for React Aria

A MapLibre map for React with React Aria: your own markers and popups, routes, GeoJSON and clusters, on a basemap that follows your theme.

On this page9 sections

The Map is an interactive MapLibre GL (opens in a new tab) map that people pan, zoom and turn, with your own markers and popups placed on it and routes, shapes, arcs, clusters and heat drawn into it. Reach for it when where things are is the point: the stores near someone, a delivery on its way, where your customers are.

The basemap is CARTO's, needs no API key and is drawn in your theme's colors. For numbers with no place attached, use a Chart. The parts follow mapcn (opens in a new tab) by Anmoldeep Singh (MIT), redesigned.

Preview width

Installation

Sign in to get your install command
Free with an account. It carries your token, so the CLI installs everything in one go.

Anatomy

Map anatomy: view, marker, marker label, marker popup, route, controls

Usage

import {
  MapControls, MapMarker, MapMarkerContent, MapMarkerPopup,
  MapMarkerTooltip, MapView,
} from "@/components/ui/map";

MapView is h-96 until a class gives it another height. Each marker takes its place in degrees, and its label names it for screen readers.

const stores = [
  {
    hours: "Open until 9 pm",
    id: "soho",
    latitude: 40.7246,
    longitude: -73.9981,
    name: "SoHo",
  },
  {
    hours: "Open until 8 pm",
    id: "williamsburg",
    latitude: 40.7144,
    longitude: -73.9614,
    name: "Williamsburg",
  },
];

const StoreMap = () => (
  <MapView
    className="h-96 rounded-lg border"
    defaultViewport={{ center: [-73.98, 40.72], zoom: 12 }}
  >
    {stores.map((store) => (
      <MapMarker
        key={store.id}
        label={store.name}
        latitude={store.latitude}
        longitude={store.longitude}
      >
        <MapMarkerContent />
        <MapMarkerTooltip>{store.name}</MapMarkerTooltip>
        <MapMarkerPopup closeButton>
          <p className="font-medium">{store.name}</p>
          <p className="text-muted-foreground">{store.hours}</p>
        </MapMarkerPopup>
      </MapMarker>
    ))}
    <MapControls />
  </MapView>
);

Accessibility

MapLibre makes the map's canvas a focusable region named Map, which a locale in options can rename, and the keys below move its camera. A marker that's draggable, has a popup, or has a click handler on its MapMarkerContent is a button. Give every marker a label: it names that button, or the marker as an image when it's none of these. A MapMarkerTooltip becomes the marker's description for screen readers, but it shows only on hover or keyboard focus, which only a marker that's a button gets. The controls are labeled buttons. Routes, shapes, arcs, clusters and heat are drawn in the canvas and aren't read out, so list what they show beside the map.

Tab
Moves focus to the map, then to the markers that are buttons and to the controls, in the order they're written.
Arrow Up
On the map, pans the view 100 pixels up. On a draggable marker, moves the marker 10 pixels up.
Arrow Down
On the map, pans the view 100 pixels down. On a draggable marker, moves the marker 10 pixels down.
Arrow Left
On the map, pans the view 100 pixels left. On a draggable marker, moves the marker 10 pixels left.
Arrow Right
On the map, pans the view 100 pixels right. On a draggable marker, moves the marker 10 pixels right.
Shift+Arrow Left
On the map, turns it 15 degrees, the other way from Shift + ArrowRight. On a draggable marker, moves the marker 40 pixels left.
Shift+Arrow Right
On the map, turns it 15 degrees. On a draggable marker, moves the marker 40 pixels right.
Shift+Arrow Up
On the map, tilts it 10 degrees further. On a draggable marker, moves the marker 40 pixels up.
Shift+Arrow Down
On the map, tilts it 10 degrees back toward looking straight down. On a draggable marker, moves the marker 40 pixels down.
=
On the map, zooms in one level, or two with Shift held, which is the + key on a US keyboard.
-
On the map, zooms out one level, or two with Shift held.
Enter
On a marker with a popup, opens or closes the popup. Opening it moves focus into the popup. On any other marker whose content has a click handler, runs it.
Space
On a marker with a popup, opens or closes the popup. Opening it moves focus into the popup. On any other marker whose content has a click handler, runs it.
Escape
Closes a marker's popup while focus is on that marker or in its popup, and hands focus back to the marker. Closes a MapPopup from anywhere in the map, and hands focus to the map if the popup held it.

Demos

Markers

Lisbon in four kinds of marker: landmark pins standing on their tips with anchor at bottom, a market and a café as icons in circles, price pills with a MapMarkerTooltip for each stay, and friends' avatars. MapMarkerContent holds any element, or draws a primary dot when it's empty. MapMarkerLabel writes a name under a marker, or above it with position at top, haloed so it reads on any basemap.

Preview width

Popups

Three Roman sights whose markers open a MapMarkerPopup with a description, opening hours, a price and a Save button, the Pantheon's open from the start with defaultOpen. A click on the map itself drops a pin through onMapClick and opens a MapPopup there with the point's coordinates. That popup is held open from state, with closeOnClick off so the next click moves it instead of closing it.

Preview width

Controls

Midtown Manhattan, turned and tilted, with a compass and a fullscreen button in the top corner and zoom and locate in the bottom one, each MapControlGroup reading as one stack. MapCompass follows the camera, and a click turns the map back to north and looks straight down. MapLocate flies to the device's position and hands it to onLocate, which drops the You are here marker.

Preview width

Draggable marker

A pickup pin in Union Square with draggable set: drag it, or focus it and press the arrow keys, 10 pixels a press or 40 with Shift. onPositionChange keeps the card's latitude and longitude in step, and the reset button moves the pin back by changing latitude and longitude. While a pointer drags it, the marker has data-dragging, which this pin uses to lift itself.

Preview width

Controlled viewport

Buttons for Tokyo, New York, London and Sydney fly the camera with MapLibre's flyTo, reached through useMap. Meanwhile viewport and onViewportChange keep the camera in state, so the latitude, longitude and zoom under the map follow every frame. Hold the viewport yourself when other parts of the page read or set it, and use defaultViewport when you only need a starting point.

Preview width

Camera

Six Lisbon viewpoints, framed together by MapCamera with bounds, or one at a time with center and zoom once a row in the list or a marker is picked. Each new aim flies the camera there over duration, 1200 milliseconds by default, and jumps where reduced motion is set. padding keeps 136 pixels clear at the bottom for the list, and maxZoom caps how close bounds bring the camera.

Preview width

Route

A bike courier's delivery across London, from Hoxton Kitchen to 31 Drury Lane, drawn by MapRoute as a dotted line. progress says how much is done: MapRouteProgress draws that part in the primary color, and a MapRouteMarker at progress rides at its tip while two others mark the start and the end. The demo moves progress every frame, and holds it still when reduced motion is set.

Preview width

Alternative routes

Three drives from Berlin Hauptbahnhof to Ostbahnhof, one of them active: it's drawn with activeColor, activeWidth and activeOpacity and raised over the others. With interactive set, a click on a line calls onRouteClick, which makes that route the active one. A line on the map answers only the pointer, so the rows in the card pick a route from the keyboard as well.

Preview width

GeoJSON

Natural Earth's countries, fetched from the URL in data, on a blank map with no tiles under them. fillPaint takes a MapLibre step expression that shades each country by GDP per person, from var(--chart-1) to var(--chart-5). fillHoverPaint lights the country under the pointer, which needs the feature ids promoteId names, and onFeatureHover feeds the card.

Preview width

Arcs

Eight flights out of Dubai as curved lines, each arc in data with an id, a from and a to. curvature is 0.2 by default, and this demo's negative value bows the arcs the other way. hoverPaint thickens the arc under the pointer, and onArcHover reports it, or null once the pointer leaves, so the card and the destination's marker follow.

Preview width

Clusters

A month of earthquakes, 6,107 of them, fetched by MapLibre from a URL and grouped by MapClusterLayer into counted circles that split as you zoom in. A click on a cluster zooms into it. clusterThresholds turns a cluster medium at 50 and large at 300, clusterColors mixes three shades of the primary color, and onPointClick opens a MapPopup with one quake's magnitude and time.

Preview width

Heatmap

Bike-share stations round Barcelona as heat that runs hotter where they crowd. With Rides pressed, weightProperty weighs each station by its rides, up to a weightMax of 500, and with Stations every point counts the same. The colors run through the theme's --chart-1 to --chart-5, and past maxZoom the heat fades into single dots.

Preview width

Globe

An edge network's ten regions on a globe, set with projection at globe, which flattens into the usual map as you zoom in close. Markers on the far side hide and come back as the globe turns them into view. The demo spins it through MapLibre's map from onReady until someone presses, scrolls or touches it, and leaves it still when reduced motion is set.

Preview width

Themed basemap

Amsterdam with a Theme and an Original button. With basemap at theme, the default, CARTO's basemap is redrawn in four of your tokens: the land from --background and --muted, the labels from --muted-foreground and --foreground, and roads, buildings and water in shades of the same four, the water keeping a trace of its own hue. original keeps CARTO's own colors. Switch here, then change your theme, and the map follows.

Preview width

Custom layer

Midtown Manhattan with its buildings raised in 3D by a component that calls useMap() and, once ready is true, adds a MapLibre fill-extrusion layer reading each building's height from CARTO's tiles. A theme change loads the other basemap, which drops the layer, and the same effect adds it back. Its toggle is an ordinary Button in a MapControlGroup, beside zoom and the compass.

Preview width

FAQ

Which basemap does the Map use, and how do I change it?

CARTO's Positron in light mode and Dark Matter in dark: vector tiles built on OpenStreetMap data, with no API key. They're free under CARTO's basemap terms, which set usage limits and ask for the credit the map shows in its bottom corner.

For a busy app in production or another look, pass styles a MapLibre style URL or style object for each theme, from OpenFreeMap, MapTiler, Stadia Maps, Protomaps or your own server. A theme you leave out stays on CARTO's, and blank draws no tiles at all.

Whichever basemap you use is redrawn in your theme's colors unless basemap is original. To lift the credit above a panel of your own, set --map-credits-bottom on the map.

How tall is the Map, and does it render on the server in React?

MapView is h-96 and as wide as its container until a class says otherwise, such as h-[480px], or h-full inside a parent with a height. On the server, and until the map first draws, it renders that box with a spinner, so the page doesn't shift when the map arrives.

MapLibre loads with the first map on the page, and the markers, popups, controls and layers render once the map exists. It needs WebGL2: where MapLibre can't start, the box says the map couldn't load instead of staying blank.

How does the Map follow dark mode and my theme's colors?

It reads the --background of the map's own box: a dark color draws Dark Matter, a light one Positron. So a .dark class or a data-theme anywhere above the map works, and so does the system setting, and a change to any of them is followed. Set theme to light or dark to choose yourself.

Every color a part takes can be a CSS variable, such as var(--chart-2) on a route or var(--primary) inside a paint expression. The parts read them on the map's box and again when the theme changes, and the Map's own routes and layers come back after the basemap swap.

How many markers can a Map show?

Each MapMarker is a DOM element the map moves on every frame of a camera move, which suits the tens of places a person picks between: stores, stops, friends.

For hundreds or thousands of points, draw them inside the map. MapClusterLayer groups them into counted circles, MapGeoJSON draws them as dots styled by circlePaint, and MapHeatmap shows where they crowd. All three take a URL in data, so MapLibre fetches a large file and your state never holds it.

To show one point's details, open a MapPopup where it was clicked, as the Clusters demo does.

Can people use the Map with a keyboard and a screen reader?

Mostly. The map is a focusable region that the arrow keys pan, the zoom keys zoom and Shift with an arrow turns or tilts. A marker with a popup, a drag or a click handler is a button, its popup opens on Enter and closes on Escape, and the Accessibility section lists every key.

What MapLibre draws in the canvas isn't read out: routes, shapes, arcs, clusters and heat. List what they show beside the map, as the route demos' cards do, and give each marker a label. A tooltip reaches screen readers as the marker's description but shows only on hover or keyboard focus, so put what people need in text beside the map too.

How do I fit the Map to show all my markers?

Render MapCamera inside MapView with bounds set to the corners round your markers, [[west, south], [east, north]], taken from the smallest and largest longitude and latitude among them. padding keeps room at the edges, 48 pixels by default, or one value per side when a panel covers part of the map.

maxZoom stops the camera from coming too close when the markers sit near each other or there's only one. When the bounds change, the camera flies to the new frame, as the Camera demo does with its All viewpoints row.

How do I use MapLibre directly inside the Map?

Call useMap() in a component inside MapView. It returns map, MapLibre's map once it exists, ready, true once the basemap has drawn, theme, and controller, whose resolveColor turns a theme variable into a color MapLibre can paint.

With map you can do anything MapLibre does, flyTo and map.on included. Add your own sources and layers in an effect that runs when ready turns true. A theme change loads the other basemap, which drops them and turns ready false until it has drawn, so the same effect puts them back, as the Custom layer demo does.

I used mapcn. What changed?

The root is MapView, since Map would hide JavaScript's own Map. The camera starts from defaultViewport or follows viewport with onViewportChange, MapLibre's other options go in options, and onReady or useMap() hands you MapLibre's map in place of a ref.

Every part's name starts with Map, such as MapMarkerContent and MapRouteProgress. MapControls takes its buttons as children, in a MapControlGroup, instead of props, and its position follows the line: bottom-end where mapcn says bottom-right. Popups open and close with open, defaultOpen and onOpenChange.

A globe needs only projection set to globe, and a drag reports its latitude and longitude. MapCamera, MapHeatmap, onMapClick and the themed basemap are new.

API Reference

MapView

PropType
viewport?Partial<MapViewport>

The camera, held where you say (with onViewportChange).

Type
Partial<MapViewport>
defaultViewport?Partial<MapViewport>

Where the camera starts, when viewport isn't given.

Type
Partial<MapViewport>
onViewportChange?(viewport: MapViewport) → void

Called on every frame the camera moves.

Parameters

viewport – MapViewport

Returns
void
basemap?MapBasemap

theme draws the basemap in your theme's colors (land, water, roads and labels from its background, muted and foreground tokens), through dark mode and preset changes; original keeps the style's own colors. @default "theme".

Default
"theme"
blank?boolean

A clear basemap with no tiles, for your own layers on the page's ground. @default false.

Default
false
loading?boolean

Shows the loading indicator over the map, as while it first draws. @default false.

Default
false
onMapClick?(position: MapLngLat) → void

Called on a click on the map itself (not on a marker or a popup), with where.

Parameters

position – MapLngLat

Returns
void
onReady?(map: MapInstance) → void

Called once the map has drawn, with MapLibre's map.

Parameters

map – MapInstance

Returns
void
onViewportChangeEnd?(viewport: MapViewport) → void

Called when the camera comes to rest.

Parameters

viewport – MapViewport

Returns
void
options?MapEngineOptions

MapLibre's own options, such as minZoom, maxBounds or cooperativeGestures.

projection?MapProjection

mercator (flat) or globe. @default "mercator".

styles?MapStyles

The basemap for each theme, a style URL or object. CARTO Positron and Dark Matter by default.

theme?MapTheme

The basemap's theme; followed from the page when not given.

className?string

Merged with the part's classes.

MapMarker

PropType
open?boolean

Whether its popup is open.

defaultOpen?boolean

Whether its popup starts open. @default false.

Default
false
onOpenChange?(open: boolean) → void

Called when its popup opens or closes.

Parameters

open – boolean

Returns
void
latitudenumber

Where it stands: degrees north (negative for south).

longitudenumber

Where it stands: degrees east (negative for west).

anchor?MapAnchor

Which point of the marker sits on its coordinate. @default "center".

Default
"center"
draggable?boolean

Drag it with a pointer, or move it with the arrow keys once focused. @default false.

Default
false
label?string

Its name for assistive tech, such as the place it marks.

offset?[number, number]

Pixels from the anchor, [x, y].

onPositionChange?(position: MapLngLat) → void

Called as a drag moves it.

Parameters

position – MapLngLat

Returns
void
onPositionChangeEnd?(position: MapLngLat) → void

Called where a drag (or an arrow key) leaves it.

Parameters

position – MapLngLat

Returns
void
rotation?number

Turns its content, in degrees clockwise, round its anchor: a heading, the way a vehicle faces.

rotationAlignment?"map" | "viewport"

map turns it with the map, as a heading on the ground does; viewport keeps it as it is on the screen. @default "viewport".

Type
"map" | "viewport"
Default
"viewport"
className?string

Merged with the part's classes.

MapMarkerContent

<div> data-slot="map-marker-content"

PropType
className?string

Merged with the part's classes.

CSS variableType
--map-marker-originstring
--map-marker-rotationstring
--map-offsetstring

MapMarkerTooltip

<div> data-slot="map-marker-tooltip"

PropType
side?MapSide

The side of the marker it shows on. @default "top".

Default
"top"
sideOffset?number

Pixels between the marker and the tooltip. @default 8.

Default
8
className?string

Merged with the part's classes.

AttributeType
data-side?string

Mirrors side.

MapMarkerLabel

<div> data-slot="map-marker-label"

PropType
position?"bottom" | "top"

Under the marker or over it. @default "bottom".

Type
"bottom" | "top"
Default
"bottom"
className?string

Merged with the part's classes.

AttributeType
data-position?string

Mirrors position.

MapMarkerPopup

<span> data-slot="map-marker"

PropType
closeButton?boolean

Shows a close button in the corner. @default false.

Default
false
side?MapSide

The side it opens on when there's room; it flips when there isn't. @default "top".

Default
"top"
sideOffset?number

Pixels between the marker and the popup. @default 12.

Default
12
className?string

Merged with the part's classes.

AttributeType
data-open""
Default
""
data-side?string

Mirrors side.

data-state"closed"
Default
"closed"

MapPopup

<div> data-slot="map-popup-anchor"

PropType
open?boolean

Whether it's open.

defaultOpen?boolean

Whether it starts open. @default true.

Default
true
onOpenChange?(open: boolean) → void

Called when it opens or closes.

Parameters

open – boolean

Returns
void
latitudenumber

Where it points: degrees north (negative for south).

longitudenumber

Where it points: degrees east (negative for west).

closeButton?boolean

Shows a close button in the corner. @default false.

Default
false
closeOnClick?boolean

Closes on a click on the map. @default true.

Default
true
label?string

Its name for assistive tech.

side?MapSide

The side it opens on when there's room; it flips when there isn't. @default "top".

Default
"top"
sideOffset?number

Pixels between the point and the popup. @default 8.

Default
8
className?string

Merged with the part's classes.

AttributeType
data-open""
Default
""
data-side?string

Mirrors side.

data-state"open"
Default
"open"

MapControls

<div> data-slot="map-controls"

PropType
position?keyof typeof CONTROLS_POSITION

The corner, at the end of the line or its start. @default "bottom-end".

Default
"bottom-end"
className?string

Merged with the part's classes.

AttributeType
data-position?string

Mirrors position.

MapControlGroup

data-slot="map-control-group"

PropType
orientation?"horizontal" | "vertical"

Lays the buttons out in a row (horizontal) or a column (vertical), their touching corners squared and borders shared. Ark default: horizontal.

Type
"horizontal" | "vertical"
Default
vertical
className?string

Merged with the part's classes.

MapZoomIn

PropType
children?ReactNode

The content to display in the button.

clickEffect?boolean

Apply a click effect to the button.

Default
true
download?LinkPrimitiveProps["download"]

With href, downloads the linked file instead of opening it.

href?string

When set, the button renders as a link.

isDisabled?boolean

Whether the button is disabled.

isLoading?boolean

Show a loading indicator.

Default
false
pill?boolean

Fully rounded corners.

Default
false
rel?string

With href, the link's relationship to the page (noreferrer, …).

size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

The size.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
"md"
target?string

With href, where the linked page opens (_blank, …).

variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

The visual style.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"default"
className?string

Merged with the part's classes.

MapZoomOut

PropType
children?ReactNode

The content to display in the button.

clickEffect?boolean

Apply a click effect to the button.

Default
true
download?LinkPrimitiveProps["download"]

With href, downloads the linked file instead of opening it.

href?string

When set, the button renders as a link.

isDisabled?boolean

Whether the button is disabled.

isLoading?boolean

Show a loading indicator.

Default
false
pill?boolean

Fully rounded corners.

Default
false
rel?string

With href, the link's relationship to the page (noreferrer, …).

size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

The size.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
"md"
target?string

With href, where the linked page opens (_blank, …).

variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

The visual style.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"default"
className?string

Merged with the part's classes.

MapCompass

data-slot="map-compass"

PropType
children?ReactNode

The content to display in the button.

clickEffect?boolean

Apply a click effect to the button.

Default
true
download?LinkPrimitiveProps["download"]

With href, downloads the linked file instead of opening it.

href?string

When set, the button renders as a link.

isDisabled?boolean

Whether the button is disabled.

isLoading?boolean

Show a loading indicator.

Default
false
pill?boolean

Fully rounded corners.

Default
false
rel?string

With href, the link's relationship to the page (noreferrer, …).

size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

The size.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
"md"
target?string

With href, where the linked page opens (_blank, …).

variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

The visual style.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"default"
className?string

Merged with the part's classes.

MapLocate

data-slot="map-locate"

PropType
children?ReactNode

The content to display in the button.

clickEffect?boolean

Apply a click effect to the button.

Default
true
download?LinkPrimitiveProps["download"]

With href, downloads the linked file instead of opening it.

href?string

When set, the button renders as a link.

isDisabled?boolean

Whether the button is disabled.

isLoading?boolean

Show a loading indicator.

Default
false
onLocate?(position: MapLngLat) → void

Called with the device's position once the map flies there.

Parameters

position – MapLngLat

Returns
void
onLocateError?(error: unknown) → void

Called when there's no position: permission refused, or no fix in 10 seconds.

Parameters

error – unknown

Returns
void
pill?boolean

Fully rounded corners.

Default
false
rel?string

With href, the link's relationship to the page (noreferrer, …).

size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

Ark default: md.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
icon-md
target?string

With href, where the linked page opens (_blank, …).

variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

Ark default: default.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
outline
zoom?number

The zoom it flies to, unless the map is closer already. @default 14.

Default
14
className?string

Merged with the part's classes.

MapFullscreen

data-slot="map-fullscreen"

PropType
children?ReactNode

The content to display in the button.

clickEffect?boolean

Apply a click effect to the button.

Default
true
download?LinkPrimitiveProps["download"]

With href, downloads the linked file instead of opening it.

href?string

When set, the button renders as a link.

isDisabled?boolean

Whether the button is disabled.

isLoading?boolean

Show a loading indicator.

Default
false
pill?boolean

Fully rounded corners.

Default
false
rel?string

With href, the link's relationship to the page (noreferrer, …).

size?"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"

The size.

Type
"default" | "icon" | "icon-lg" | "icon-md" | "icon-sm" | "icon-xl" | "icon-xs" | "lg" | "md" | "sm" | "xl" | "xs"
Default
"md"
target?string

With href, where the linked page opens (_blank, …).

variant?"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"

The visual style.

Type
"default" | "destructive" | "ghost" | "link" | "outline" | "secondary"
Default
"default"
className?string

Merged with the part's classes.

MapRoute

PropType
coordinatesMapCoordinate[]

The route, as [longitude, latitude] pairs, from any routing service.

active?boolean

Raises the route over its siblings and draws it with the active* styles. @default false.

Default
false
activeColor?string

The color while active; color when not given.

activeDashArray?[number, number]

The dashes while active; dashArray when not given.

activeOpacity?number

The opacity while active; opacity when not given.

activeWidth?number

The width while active, in pixels; width when not given.

beforeId?string

A MapLibre layer to draw under, such as the basemap's labels.

children?ReactNode

Its progress line and markers.

color?string

Any CSS color, theme variables included. @default "var(--primary)".

Default
"var(--primary)"
dashArray?[number, number]

[dash, gap], in line widths.

interactive?boolean

Answers the pointer: a pointer cursor, onRouteClick and onHoverChange. @default false.

Default
false
onHoverChange?(hovered: boolean) → void

Called with true as the pointer comes onto the line, false as it leaves (with interactive).

Parameters

hovered – boolean

Returns
void
onRouteClick?() → void

Called on a click on the line (with interactive).

Returns
void
opacity?number

The line's opacity, from 0 to 1. @default 1.

Default
1
progress?number

How much of the route is done, from 0 to 1: drives MapRouteProgress and the progress marker.

width?number

In pixels. @default 4.

Default
4

MapRouteProgress

<span> data-slot="map-route-progress"

PropType
color?string

The covered part's color, any CSS color. @default the route's color.

dashArray?[number, number]

[dash, gap] for the covered part, in line widths; solid when not given.

opacity?number

The covered part's opacity, from 0 to 1. @default the route's opacity.

width?number

The covered part's width, in pixels. @default the route's width.

MapRouteMarker

PropType
open?boolean

Whether its popup is open.

defaultOpen?boolean

Whether its popup starts open. @default false.

onOpenChange?(open: boolean) → void

Called when its popup opens or closes.

Parameters

open – boolean

Returns
void
atMapRouteAnchor

Where on the route: start, end, progress, or a fraction from 0 to 1.

anchor?MapAnchor

Which point of the marker sits on its coordinate. @default "center".

draggable?boolean

Drag it with a pointer, or move it with the arrow keys once focused. @default false.

label?string

Its name for assistive tech, such as the place it marks.

offset?[number, number]

Pixels from the anchor, [x, y].

onPositionChange?(position: MapLngLat) → void

Called as a drag moves it.

Parameters

position – MapLngLat

Returns
void
onPositionChangeEnd?(position: MapLngLat) → void

Called where a drag (or an arrow key) leaves it.

Parameters

position – MapLngLat

Returns
void
rotation?number

Turns its content, in degrees clockwise, round its anchor: a heading, the way a vehicle faces.

rotationAlignment?"map" | "viewport"

map turns it with the map, as a heading on the ground does; viewport keeps it as it is on the screen. @default "viewport".

Type
"map" | "viewport"

MapGeoJSON

<span> data-slot="map-geojson"

PropType
dataMapGeoJSONData

A FeatureCollection, a Feature, a Geometry, or a URL to fetch one from.

beforeId?string

A MapLibre layer to draw under.

circleHoverPaint?MapCirclePaint

Paint for the point under the pointer (needs feature ids).

circlePaint?MapCirclePaint | false

Points' paint, merged over a primary dot; false draws no points.

Type
MapCirclePaint | false
fillHoverPaint?MapFillPaint

Paint for the polygon under the pointer (needs feature ids).

fillPaint?MapFillPaint | false

Polygons' paint, merged over a light primary tint; false draws no fill.

Type
MapFillPaint | false
interactive?boolean

Answers the pointer. @default true with onFeatureClick or onFeatureHover.

lineHoverPaint?MapLinePaint

Paint for the line or the outline under the pointer (needs feature ids).

linePaint?MapLinePaint | false

Lines' and outlines' paint, merged over a primary hairline; false draws none.

Type
MapLinePaint | false
onFeatureClick?(event: MapFeatureEvent) → void

Called with the feature clicked, and where.

Parameters

event – MapFeatureEvent

Returns
void
onFeatureHover?(event: MapFeatureEvent | null) → void

Called as the feature under the pointer changes; null when it leaves them.

Type
(event: MapFeatureEvent | null) → void
Parameters

event – MapFeatureEvent | null

Returns
void
promoteId?string

The property that is each feature's id, for hover and stable events.

MapArc

<span> data-slot="map-arc"

PropType
dataMapArcDatum[]

The arcs, each with a unique id, from and to.

beforeId?string

A MapLibre layer to draw under.

curvature?number

How far each arc bows: 0 is straight, negative bows the other way. @default 0.2.

Default
0.2
hoverPaint?MapLinePaint

Paint for the arc under the pointer.

interactive?boolean

Answers the pointer: hover, clicks and a pointer cursor. @default true.

Default
true
layout?MapLineLayout

MapLibre line layout, merged over round joins and caps.

onArcClick?(event: MapArcEvent) → void

Called with the arc clicked, and where.

Parameters

event – MapArcEvent

Returns
void
onArcHover?(event: MapArcEvent | null) → void

Called as the arc under the pointer changes; null when it leaves them.

Type
(event: MapArcEvent | null) → void
Parameters

event – MapArcEvent | null

Returns
void
paint?MapLinePaint

Paint merged over a primary line; expressions can read each arc's fields.

samples?number

Points along each curve. @default 64.

Default
64

MapClusterLayer

<span> data-slot="map-cluster-layer"

PropType
dataMapGeoJSONFeatureCollection<MapGeoJSONPoint> | string

Points, as a FeatureCollection or a URL to fetch one from.

Type
MapGeoJSONFeatureCollection<MapGeoJSONPoint> | string
clusterColors?[string, string, string]

Colors for small, medium and large clusters. @default the primary color for all three.

Default
["var(--primary)"
clusterMaxZoom?number

The zoom past which points stop clustering. @default 14.

Default
14
clusterRadius?number

How near points cluster, in pixels. @default 50.

Default
50
clusterThresholds?[number, number]

Point counts where a cluster turns medium, then large. @default [100, 750].

Default
[100
onClusterClick?( clusterId: number, coordinates: MapCoordinate, pointCount: number ) → void

Called on a cluster; without it, a click zooms into the cluster.

Type
( clusterId: number, coordinates: MapCoordinate, pointCount: number ) → void
Parameters

clusterId – number

coordinates – MapCoordinate

pointCount – number

Returns
void
onPointClick?( feature: MapGeoJSONFeature<MapGeoJSONPoint>, coordinates: MapCoordinate ) → void

Called on a single point.

Type
( feature: MapGeoJSONFeature<MapGeoJSONPoint>, coordinates: MapCoordinate ) → void
Parameters

feature – MapGeoJSONFeature<MapGeoJSONPoint>

coordinates – MapCoordinate

Returns
void
pointColor?string

The color of a point on its own, out of every cluster. @default "var(--primary)".

Default
"var(--primary)"
textColor?string

The counts' color. @default "var(--primary-foreground)".

Default
"var(--primary-foreground)"

MapHeatmap

<span> data-slot="map-heatmap"

PropType
dataMapGeoJSONFeatureCollection<MapGeoJSONPoint> | string

Points, as a FeatureCollection or a URL to fetch one from.

Type
MapGeoJSONFeatureCollection<MapGeoJSONPoint> | string
beforeId?string

A MapLibre layer to draw under, such as the basemap's labels.

colors?string[]

From the least density to the most, any CSS colors. @default the theme's chart colors, hottest away from the background.

intensity?number

How hot the heat runs: 2 is twice as hot. @default 1.

Default
1
maxZoom?number

Past this zoom the heat fades out and each point shows instead; heat at every zoom when not given.

opacity?number

The heat's opacity, from 0 to 1. @default 0.85.

Default
0.85
radius?number

Each point's reach in pixels at zoom 10; half at zoom 5, twice at 15. @default 24.

Default
24
weightMax?number

The highest weight: a point weighing this counts fully. @default 1.

Default
1
weightProperty?string

The property each point is weighted by, from 0 to weightMax; every point counts the same when not given.

MapCamera

<span> data-slot="map-camera"

PropType
bearing?number

Rotation, in degrees clockwise from north.

bounds?[MapCoordinate, MapCoordinate]

Frames these corners, [[west, south], [east, north]], instead of center and zoom.

center?MapCoordinate

Where it looks, as [longitude, latitude].

duration?number

How long a flight to a new aim takes, in ms; none where motion is reduced. @default 1200.

Default
1200
maxZoom?number

The closest it comes when framing bounds, and how close it looks at bounds round a single point.

padding?MapPadding

Room round what it frames, in pixels: a number, or one per side (for a panel over the map), with start and end following the direction (RTL) or left and right. @default 48.

Default
48
pitch?number

Tilt, in degrees from looking straight down.

revision?number | string

Change it to fly to the same aim again, as when the place already chosen is pressed after the map was moved.

Type
number | string
zoom?number

How close it is.

useMap