API Reference
Complete reference for all map components and their props.
Component Anatomy
#All parts of the component that you can use and combine to build your map.
<Map>
<MapMarker longitude={...} latitude={...}>
<MarkerContent>
<MarkerLabel />
</MarkerContent>
<MarkerPopup />
<MarkerTooltip />
</MapMarker>
<MapPopup longitude={...} latitude={...} />
<MapControls />
<MapRoute coordinates={...} progress={...}>
<RouteProgress />
<RouteMarker at="progress">
<MarkerContent />
</RouteMarker>
</MapRoute>
<MapArc data={...} />
<MapGeoJSON data={...} />
<MapClusterLayer data={...} />
</Map>Map
#The root container component that initializes MapLibre GL and provides context to child components. Automatically handles theme switching between light and dark modes.
Extends MapOptions from MapLibre GL (excluding container and style).
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Child components (markers, popups, controls, routes). |
className | string | — | Additional CSS classes for the map container. |
theme | "light" | "dark" | — | Theme for the map. If not provided, automatically detects from document class or system preference. |
styles | { light?: string | StyleSpecification; dark?: string | StyleSpecification } | — | Custom map styles for light and dark themes. Overrides the default Carto base map tiles. |
blank | boolean | false | Use a transparent, tile-less basemap instead of the default Carto street basemap. This is a blank canvas — used alone it renders nothing, so you must add your own layers (e.g. MapGeoJSON, MapArc, markers) on top. Ideal for data visualizations (choropleths, arcs, dot maps). Ignored when an explicit styles prop is provided. |
projection | ProjectionSpecification | — | Map projection type. Use { type: "globe" } for 3D globe view. |
viewport | Partial<MapViewport> | — | Controlled viewport state. When used with onViewportChange, enables controlled mode. Can also be used alone for initial viewport. |
onViewportChange | (viewport: MapViewport) => void | — | Callback fired continuously as the viewport changes (during pan, zoom, rotate). Can be used alone to observe changes, or with viewport prop to enable controlled mode. |
loading | boolean | false | Show a loading indicator on the map. |
useMap
#A hook that provides access to the MapLibre map instance and loading state. Must be used within a Map component.
const { map, isLoaded } = useMap();Returns map (MapLibre.Map) and isLoaded (boolean) tells you if the map is loaded and ready to use.
MapControls
#Renders map control buttons (zoom, compass, locate, fullscreen). Must be used inside Map.
| Prop | Type | Default | Description |
|---|---|---|---|
position | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "bottom-right" | Position of the controls on the map. |
showZoom | boolean | true | Show zoom in/out buttons. |
showCompass | boolean | false | Show compass button to reset bearing. |
showLocate | boolean | false | Show locate button to find user's location. |
showFullscreen | boolean | false | Show fullscreen toggle button. |
className | string | — | Additional CSS classes for the controls container. |
onLocate | (coords: { longitude: number; latitude: number }) => void | — | Callback with user coordinates when located. |
MapMarker
#A container for marker-related components. Provides context for its children and handles marker positioning.
Extends MarkerOptions from MapLibre GL (excluding element).
| Prop | Type | Default | Description |
|---|---|---|---|
longitude | number | — | Longitude coordinate for marker position. |
latitude | number | — | Latitude coordinate for marker position. |
children | ReactNode | — | Marker subcomponents (MarkerContent, MarkerPopup, etc). |
onClick | (e: MouseEvent) => void | — | Callback when marker is clicked. |
onMouseEnter | (e: MouseEvent) => void | — | Callback when mouse enters marker. |
onMouseLeave | (e: MouseEvent) => void | — | Callback when mouse leaves marker. |
onDragStart | (lngLat: {lng, lat}) => void | — | Callback when marker drag starts (requires draggable: true). |
onDrag | (lngLat: {lng, lat}) => void | — | Callback during marker drag (requires draggable: true). |
onDragEnd | (lngLat: {lng, lat}) => void | — | Callback when marker drag ends (requires draggable: true). |
MarkerContent
#Renders the visual content of a marker. Must be used inside MapMarker. If no children provided, renders a default blue dot marker.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Custom marker content. Defaults to a blue dot. |
className | string | — | Additional CSS classes for the marker container. |
MarkerPopup
#Renders a popup attached to the marker that opens on click. Must be used inside MapMarker.
Extends PopupOptions from MapLibre GL (excluding className and closeButton).
className and closeButton options are excluded to prevent style conflicts. Use the component's props of the same name instead. MapLibre's default popup styles are reset via CSS.| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Popup content. |
className | string | — | Additional CSS classes for the popup container. |
closeButton | boolean | false | Show a close button in the popup. |
MarkerTooltip
#Renders a tooltip that appears on hover. Must be used inside MapMarker.
Extends PopupOptions from MapLibre GL (excluding className, closeButton, and closeOnClick as tooltips auto-dismiss on hover out).
className and closeButton options are excluded to prevent style conflicts. Use the component's className instead. MapLibre's default popup styles are reset via CSS.| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Tooltip content. |
className | string | — | Additional CSS classes for the tooltip container. |
MarkerLabel
#Renders a text label above or below the marker. Must be used inside MarkerContent.
| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | — | Label text content. |
className | string | — | Additional CSS classes for the label. |
position | "top" | "bottom" | "top" | Position of the label relative to the marker. |
MapPopup
#A standalone popup component that can be placed anywhere on the map without a marker. Must be used inside Map.
Extends PopupOptions from MapLibre GL (excluding className and closeButton).
className and closeButton options are excluded to prevent style conflicts. Use the component's props of the same name instead. MapLibre's default popup styles are reset via CSS.| Prop | Type | Default | Description |
|---|---|---|---|
longitude | number | — | Longitude coordinate for popup position. |
latitude | number | — | Latitude coordinate for popup position. |
onClose | () => void | — | Callback when popup is closed. |
children | ReactNode | — | Popup content. |
className | string | — | Additional CSS classes for the popup container. |
closeButton | boolean | false | Show a close button in the popup. |
MapRoute
#Renders a line/route on the map connecting coordinate points. Must be used inside Map. Supports click and hover interactions for building route selection UIs.
progress marks how far along the route you are; add a RouteProgress child to draw that portion. Mark one route active to raise it above its siblings with the active* styles.
| Prop | Type | Default | Description |
|---|---|---|---|
id | string | undefined (auto-generated) | Optional unique identifier for the route layer. Auto-generated if not provided. |
coordinates | [number, number][] | — | Array of [longitude, latitude] coordinate pairs. |
color | string | "#4285F4" | Line color (CSS color value). |
width | number | 3 | Line width in pixels. |
opacity | number | 0.8 | Line opacity (0 to 1). |
dashArray | [number, number] | — | Dash pattern [dash length, gap length] for dashed lines. |
progress | number | — | Fraction of the route already covered (0 to 1). Drives RouteProgress and the "progress" anchor on RouteMarker. |
active | boolean | false | Marks this route as the selected one: it moves above sibling routes and switches to the active* styles. |
activeColor | string | color | Line color while active. |
activeWidth | number | width | Line width while active. |
activeOpacity | number | opacity | Line opacity while active. |
activeDashArray | [number, number] | dashArray | Dash pattern while active. |
beforeId | string | — | MapLibre layer id to insert the route layers before (z-order control). |
onClick | () => void | — | Callback when the route line is clicked. |
onMouseEnter | () => void | — | Callback when mouse enters the route line. |
onMouseLeave | () => void | — | Callback when mouse leaves the route line. |
interactive | boolean | true | Respond to mouse events (hover, cursor, callbacks). |
children | ReactNode | — | Route subcomponents (RouteProgress, RouteMarker). |
RouteProgress
#Draws the covered portion of the parent MapRoute on top of the base line, ending exactly at its progress fraction. Must be used inside MapRoute, and renders nothing until the route has a progress value.
| Prop | Type | Default | Description |
|---|---|---|---|
color | string | the route's color | Line color for the covered portion. |
width | number | the route's width | Line width in pixels. |
opacity | number | the route's opacity | Line opacity (0 to 1). |
dashArray | [number, number] | — | Dash pattern [dash length, gap length] for dashed lines. |
RouteMarker
#A MapMarker pinned to a position along the parent MapRoute, so you never compute the coordinate yourself. Must be used inside MapRoute. Accepts every MapMarker prop except longitude and latitude, and the same children.
| Prop | Type | Default | Description |
|---|---|---|---|
at | "start" | "end" | "progress" | number | — | Where to pin the marker. A number is a fraction along the line (0 to 1); "progress" tracks the route's progress value. |
children | ReactNode | — | Marker subcomponents (MarkerContent, MarkerPopup, MarkerTooltip, MarkerLabel). |
...props | MapMarkerProps | — | Any other MapMarker prop (offset, onClick, draggable, rotation, ...). |
MapArc
#Renders curved lines between coordinate pairs using a quadratic Bézier in longitude/latitude space. Must be used inside Map. Supports click and hover interactions for building arc selection UIs.
Built on a MapLibre line layer, so paint and layout accept any field from LineLayerSpecification. Any paint value can be a MapLibre expression — reference datum fields with ["get", "fieldName"].
| Prop | Type | Default | Description |
|---|---|---|---|
data | MapArcDatum[] | — | Arcs to render. Each needs a unique id and from / to as [lng, lat]. Extra fields are forwarded to feature properties. |
id | string | auto | Id prefix for the underlying source/layers. |
curvature | number | 0.2 | How far the arc bows away from a straight line. 0 renders a straight line, higher values bend more, negative values bend to the opposite side. |
samples | number | 64 | Points per arc. Higher = smoother. |
paint | LineLayerSpecification['paint'] | { "line-color": "#4285F4", "line-width": 2, "line-opacity": 0.85 } | Paint props merged over defaults. Values may be MapLibre expressions for per-feature styling. |
layout | LineLayerSpecification['layout'] | { "line-join": "round", "line-cap": "round" } | Layout props merged over defaults. |
hoverPaint | LineLayerSpecification['paint'] | — | Paint overrides applied to the hovered arc via feature-state. |
onClick | (e: MapArcEvent) => void | — | Fired when an arc is clicked. |
onHover | (e: MapArcEvent | null) => void | — | Fired when the hovered arc changes, with the cursor's lng/lat at entry. Receives null when the cursor leaves all arcs. |
interactive | boolean | true | Respond to mouse events (hover, cursor, callbacks). |
beforeId | string | — | Insert the arc layers before this layer id. |
MapGeoJSON
#Renders arbitrary GeoJSON as fill + outline layers. Must be used inside Map — typically with the blank prop for choropleths and region/data maps. Supports a generic type parameter for typed feature properties: MapGeoJSON<MyProperties>.
Fill and outline default to a theme-aware monochrome tone, so shapes read clearly on light/dark out of the box. Any paint value can be a MapLibre expression for data-driven styling.
| Prop | Type | Default | Description |
|---|---|---|---|
data | FeatureCollection | Feature | Geometry | string | — | GeoJSON data (FeatureCollection, Feature, or Geometry) or a URL string to fetch it from. |
id | string | auto | Id prefix for the underlying source/layers. |
promoteId | string | — | Feature property to promote to the feature id. Required for hover feature-state (fillHoverPaint) and stable onHover / onClick payloads. |
fillPaint | FillLayerSpecification['paint'] | false | — | Paint for the polygon fill layer, merged over a theme-aware fill-color default. Pass false to omit the fill layer (e.g. outlines only). |
linePaint | LineLayerSpecification['paint'] | false | — | Paint for the outline layer, merged over a theme-aware hairline default. Pass false to omit the outline layer. |
fillHoverPaint | FillLayerSpecification['paint'] | — | Paint merged onto the fill layer for the hovered feature, applied via hover feature-state. Requires promoteId. |
onClick | (e: MapGeoJSONEvent) => void | — | Fired when a feature is clicked. |
onHover | (e: MapGeoJSONEvent | null) => void | — | Fired when the hovered feature changes. Receives null when the cursor leaves all features. |
interactive | boolean | false | Respond to mouse events (hover, cursor, callbacks). |
beforeId | string | — | Insert the layers before this layer id. |
MapClusterLayer
#Renders clustered point data using MapLibre GL's native clustering. Automatically groups nearby points into clusters that expand on click. Must be used inside Map. Supports a generic type parameter for typed feature properties: MapClusterLayer<MyProperties>.
| Prop | Type | Default | Description |
|---|---|---|---|
data | string | GeoJSON.FeatureCollection | — | GeoJSON FeatureCollection data or URL to fetch GeoJSON from. |
clusterMaxZoom | number | 14 | Maximum zoom level to cluster points on. |
clusterRadius | number | 50 | Radius of each cluster when clustering points (in pixels). |
clusterColors | [string, string, string] | ["#3b82f6", "#1d4ed8", "#1e3a8a"] | Colors for cluster circles: [small, medium, large] based on point count. |
clusterThresholds | [number, number] | [100, 750] | Point count thresholds for color/size steps: [medium, large]. |
pointColor | string | "#3b82f6" | Color for unclustered individual points. |
onPointClick | (feature: GeoJSON.Feature, coordinates: [number, number]) => void | — | Callback when an unclustered point is clicked. |
onClusterClick | (clusterId: number, coordinates: [number, number], pointCount: number) => void | — | Callback when a cluster is clicked. If not provided, zooms into the cluster. |