A MapLibre-powered map surface for custom styles, markers, popups, routes, arcs, clusters, and controls.
Map is a subpath-only import (@heroui-pro/react/map) because it depends on the optional maplibre-gl peer. It is not exported from the package root, so SSR apps that don't use it never need maplibre-gl installed.import {Map} from "@heroui-pro/react/map";
const styles = {
dark: "https://tiles.openfreemap.org/styles/dark",
light: "https://tiles.openfreemap.org/styles/positron",
};
<Map center={[-122.3927, 37.7816]} styles={styles} zoom={13.25}>
<Map.Route coordinates={route} /> {/* Optional */}
<Map.Arc data={arcs} /> {/* Optional */}
<Map.ClusterLayer data={points} /> {/* Optional */}
<Map.Marker latitude={37.79519} longitude={-122.39385}> {/* Optional */}
<Map.MarkerContent>
<Map.MarkerDot />
<Map.MarkerLabel>Start</Map.MarkerLabel> {/* Optional */}
</Map.MarkerContent>
<Map.MarkerTooltip>Ferry Building</Map.MarkerTooltip> {/* Optional */}
<Map.MarkerPopup>{/* ... */}</Map.MarkerPopup> {/* Optional */}
</Map.Marker>
<Map.Popup latitude={37.79519} longitude={-122.39385}> {/* Optional */}
Pickup ready
</Map.Popup>
<Map.Controls> {/* Optional */}
<Map.ZoomControl />
<Map.CompassControl />
<Map.LocateControl />
<Map.FullscreenControl />
</Map.Controls>
</Map>;Map uses MapLibre GL internally, but it does not ship a tile provider or basemap style. Pass mapStyle for a single MapLibre-compatible style URL/object, or styles for separate light and dark styles. With styles, the map follows data-theme (dark, light, or a *-dark/*-light theme) or a dark/light class on <html>, then the system color scheme. Pass theme to override.
The snippets on this page pass OpenFreeMap Positron (light) and Dark (dark) through styles. Its public instance requires no API key or registration, so they run as-is.
Any MapLibre-compatible provider works, such as MapTiler, Stadia Maps, Protomaps, or CARTO. Check each provider's terms before shipping. Most require an API key on their style URLs and watermark tiles with text like "API KEY REQUIRED" when it is missing. That watermark comes from the tile provider and is unrelated to your HeroUI Pro registry tokens.
HeroUI follows the BEM methodology to ensure component variants and states are reusable and easy to customize.
The Map component uses these CSS classes:
.map: MapLibre container and positioning root..map__loader: Loading veil shown until the map and style are ready..map__loader-spinner: Loader spinner..map__marker: Marker host element..map__marker-content: React-rendered marker content..map__default-marker: Default marker dot..map__marker-label: Marker label..map__marker-label--top / .map__marker-label--bottom: Label placement above or below the marker..map__tooltip: Marker tooltip..map__popup-content: Popup content wrapper..map__popup-close-button: Popup close button..map__controls: Controls container..map__controls--top-left / .map__controls--top-right / .map__controls--bottom-left / .map__controls--bottom-right: Controls position, from position..map__control-group: Grouped control surface..map__control-button: Single control button..map__control-separator: Divider between grouped control buttons, rendered as the first child of the later button..map__control-icon: Icon inside a built-in control button..map__control-spinner: Locate control spinner..map__compass-icon: Compass needle that rotates with bearing and pitch.--map-control-size: Control button size.--map-control-offset: Controls offset from map edges.--map-popup-max-width: Popup and tooltip max width.--map-marker-color: Default marker fill color.--map-marker-ring-color: Default marker ring color.--map-route-color: Default route stroke color.--map-route-width: Default route stroke width.--map-route-opacity: Default route stroke opacity.The root map container. Renders a MapLibre map with HeroUI themed controls and overlays.
| Prop | Type | Default | Description |
|---|---|---|---|
center | [number, number] | - | Initial center as [longitude, latitude]. |
zoom | number | - | Initial zoom level. |
mapStyle | string | StyleSpecification | - | Single MapLibre-compatible style URL/object. Overrides styles. |
styles | { light?: MapStyleOption; dark?: MapStyleOption } | - | Theme-aware style URLs or objects. |
theme | "light" | "dark" | detected | Force the map style theme. |
viewport | Partial<MapViewport> | - | Controlled viewport state. |
onViewportChange | (viewport: MapViewport) => void | - | Fired as the map moves. |
isLoading | boolean | false | Shows the loading veil over the map. |
workerUrl | string | - | Explicit MapLibre worker URL for bundlers that cannot resolve it. |
Also supports MapLibre MapOptions except container and style.
Adds a React-rendered marker at a longitude/latitude.
| Prop | Type | Default | Description |
|---|---|---|---|
latitude | number | - | Marker latitude. |
longitude | number | - | Marker longitude. |
aria-label | string | - | Accessible name of the marker. |
draggable | boolean | false | Allows dragging the marker. |
onClick | (event: MouseEvent) => void | - | Fired when the marker is clicked. |
onDragEnd | ({ lat, lng }) => void | - | Fired after a draggable marker moves. |
A marker with a Map.MarkerPopup is a focusable role="button" with aria-expanded; Enter or Space toggles the popup. Give it a name with aria-label when its content has no text.
Map.MarkerContent: Renders marker content into the MapLibre marker element.Map.MarkerDot: Renders the default marker dot. Customize with className, style, color, or ringColor.Map.MarkerLabel: Adds a marker label with position="top" | "bottom".Map.MarkerTooltip: Shows a lightweight tooltip on hover.Map.MarkerPopup: Attaches a MapLibre popup to a marker. Accepts closeButton and closeButtonLabel.Renders the default marker visual. Use it inside Map.MarkerContent when you want the built-in marker style plus labels or other custom content.
| Prop | Type | Default | Description |
|---|---|---|---|
color | string | - | Overrides --map-marker-color. |
ringColor | string | - | Overrides --map-marker-ring-color. |
Renders a standalone popup at a longitude/latitude.
| Prop | Type | Default | Description |
|---|---|---|---|
latitude | number | - | Popup latitude. |
longitude | number | - | Popup longitude. |
closeButton | boolean | false | Shows the HeroUI close button. |
closeButtonLabel | string | "Close popup" | Accessible name of the close button. |
onClose | () => void | - | Fired when the popup closes. |
Positions map controls in a corner.
| Prop | Type | Default | Description |
|---|---|---|---|
position | "top-left" | "top-right" | "bottom-left" | "bottom-right" | "bottom-right" | Controls placement. |
Use Map.ZoomControl, Map.CompassControl, Map.LocateControl, Map.FullscreenControl, Map.ControlGroup, Map.ControlButton, and Map.ControlSeparator inside Map.Controls. Each built-in control's accessible name is set with a label prop, listed under Localization.
Draws a GeoJSON line layer from coordinates.
Map.Route does not calculate navigation paths or snap points to roads. Pass the route geometry from your routing provider, such as Google Routes, Mapbox Directions, OSRM, Valhalla, or your own routing service.
| Prop | Type | Default | Description |
|---|---|---|---|
coordinates | [number, number][] | - | Route coordinates as [longitude, latitude]. |
color | string | CSS var | Route stroke color. |
width | number | CSS var | Route stroke width. |
opacity | number | CSS var | Route stroke opacity. |
dashArray | [number, number] | - | Optional dashed route pattern. |
Draws curved connection lines between points. Each datum needs id, from, and to.
Draws clustered points from a GeoJSON point collection or GeoJSON URL.
| Default text | Where | Override |
|---|---|---|
"Zoom in" / "Zoom out" | Map.ZoomControl buttons | zoomInLabel / zoomOutLabel |
"Reset bearing to north" | Map.CompassControl | label |
"Find my location" | Map.LocateControl | label |
"Toggle fullscreen" | Map.FullscreenControl | label |
"Close popup" | Map.Popup and Map.MarkerPopup close button | closeButtonLabel |
Labels you don't pass keep their English default.
Resources