API Reference

PreviousNext

What components are available in shadcn Map and how to use them.

Map Container and Core

Map

The Map component is the main map container. It wraps react-leaflet’s MapContainer and provides default styles.

PropTypeDescription
centerLatLngExpressionRequired. The initial center of the map [lat, lng].
...other propsMapContainerPropsAll other props from React Leaflet MapContainer.

MapTileLayer

The MapTileLayer component adds a tile layer to the map. It is required for the map to be rendered. It automatically switches between light and dark map styles based on the current theme from next-themes. You can provide custom URLs and attributions for both light and dark modes using the url, darkUrl, attribution, and darkAttribution props.

PropTypeDescription
urlstringOptional. URL of the tile server for light mode. Defaults to Carto’s light tiles.
attributionstringOptional. HTML string for map attribution in light mode. Defaults to OpenStreetMap and CARTO attribution.
darkUrlstringOptional. URL of the tile server for dark mode. Defaults to Carto’s dark tiles.
darkAttributionstringOptional. HTML string for map attribution in dark mode. Defaults to OpenStreetMap and CARTO attribution.
namestringOptional. Name of the layer, only required when using multiple tile layers with MapLayers. Defaults to Default.
...other propsTileLayerPropsAll other props from React Leaflet TileLayer.

MapLayerGroup

The MapLayerGroup component is for grouping multiple map layers, which is useful when you want to control their visibility by group. It has little effect if you only have one layer group or don’t need to toggle visibility.

PropTypeDescription
namestringRequired. A unique name for the layer group.
disabledbooleanOptional. If true, the layer group’s checkbox in the layer control will be disabled, preventing users from toggling it.
...other propsLayerGroupPropsAll other props from React Leaflet LayerGroup.

MapFeatureGroup

The MapFeatureGroup component is similar to MapLayerGroup, but with a few extra capabilities. You can bind popups or tooltips to all child layers at once, and events on the group will automatically propagate to its child layers.

PropTypeDescription
namestringRequired. A unique name for the layer group.
disabledbooleanOptional. If true, the layer group’s checkbox in the layer control will be disabled, preventing users from toggling it.
...other propsFeatureGroupPropsAll other props from React Leaflet FeatureGroup.

MapLayers

The MapLayers component provides a context for managing multiple tile layers and layer groups on the map.
It is required when you want to use multiple tile layers or multiple layer groups together.
Tile layers and layer groups can still be used on their own, but MapLayers is needed if you want to control visibility via the MapLayersControl component.

PropTypeDescription
defaultTileLayerstringOptional. The name of the tile layer to select by default. Must match the name prop of a MapTileLayer.
defaultLayerGroupsstring[]Optional. Names of the layer groups to activate by default. Must match the name prop of a MapLayerGroup.
...propsOmit<ProviderProps, "value">All props from the context provider, except value.

MapLayersControl

The MapLayersControl component renders a UI for selecting the active tile layer and toggling layer groups.
It must be used inside a MapLayers component and is only visible if there are multiple tile layers or layer groups registered.

The control is only visible if there are multiple tile layers or layer groups registered.

PropTypeDescription
tileLayersLabelstringOptional. Custom label for the tile layers section in the dropdown menu. Defaults to Map Type.
layerGroupsLabelstringOptional. Custom label for the layer groups section in the dropdown menu. Defaults to Layers.
...propsReact.ComponentProps<"button">All props for the control button element.

Marker and Popup

MapMarker

The MapMarker component renders a marker on the map. By default, it uses the MapPinIcon from lucide-react, but you can provide a custom React node as the icon to override it. It supports customization of the icon’s position, popups, and tooltips using standard Leaflet DivIcon options.

PropTypeDescription
iconReactNodeOptional. Custom icon to display instead of the default marker. Defaults to MapDefaultMarkerIcon.
iconAnchor[number, number]Optional. The point of the icon which will correspond to marker’s location. Defaults to [12, 12].
bgPos[number, number]Optional. Background position offset for the icon.
popupAnchor[number, number]Optional. Point from which the popup should open relative to the icon.
tooltipAnchor[number, number]Optional. Point from which the tooltip should open relative to the icon.
...other propsOmit<MarkerProps, "icon">All other props from React Leaflet Marker, except icon.

MapPopup

The MapPopup component renders a popup. It provides default styling and animations that match the shadcn/ui design system.

PropTypeDescription
...propsPopupPropsAll props from React Leaflet Popup.

MapTooltip

The MapTooltip component renders a tooltip. It provides default styling and animations that match the shadcn/ui design system.

PropTypeDescription
side"top" | "right" | "bottom" | "left"Optional. Controls the position of the tooltip relative to the target element. Defaults to "top".
sideOffsetnumberOptional. The distance between the tooltip and the target element. Defaults to 15.
...propsTooltipPropsAll props from React Leaflet Tooltip.

Shapes

MapCircle

The MapCircle component renders a circle on the map.

PropTypeDescription
...propsCirclePropsAll props from React Leaflet Circle.

MapCircleMarker

The MapCircleMarker component renders a circle marker on the map.

PropTypeDescription
...propsCircleMarkerPropsAll props from React Leaflet CircleMarker.

MapPolyline

The MapPolyline component renders a polyline on the map.

PropTypeDescription
...propsPolylinePropsAll props from React Leaflet Polyline.

MapPolygon

The MapPolygon component renders a polygon on the map.

PropTypeDescription
...propsPolygonPropsAll props from React Leaflet Polygon.

MapRectangle

The MapRectangle component renders a rectangle on the map.

PropTypeDescription
...propsRectanglePropsAll props from React Leaflet Rectangle.

Controls

MapZoomControl

The MapZoomControl component provides custom zoom buttons for the map.

PropTypeDescription
...propsReact.ComponentProps<"div">All props for the container div.

MapLocateControl

The MapLocateControl component provides a button to locate the user on the map.

PropTypeDescription
watchbooleanOptional. Whether to continuously watch the user’s location. Defaults to false.
onLocationFound(location: LocationEvent) => voidOptional. Callback fired when the user’s location is found. Receives the Leaflet LocationEvent.
onLocationError(error: ErrorEvent) => voidOptional. Callback fired when there is an error locating the user. Receives the Leaflet ErrorEvent.
...propsReact.ComponentProps<"button">All props for the button element.

Drawing

MapDrawControl

The MapDrawControl component is required when you want to add drawing tools to the map.

Place any draw controls (e.g. MapDrawMarker, MapDrawPolyline, MapDrawPolygon) inside it.

PropTypeDescription
onLayersChange(layers: L.FeatureGroup) => voidOptional. Callback fired whenever layers are created, edited, or deleted. Receives the current Leaflet FeatureGroup.
...propsReact.ComponentProps<"div">All props for the container div.

MapDrawMarker

The MapDrawMarker component adds a button to the draw control for drawing markers on the map.

PropTypeDescription
...propsDrawOptions.MarkerOptionsAll props from Leaflet Draw Marker options.

MapDrawPolyline

The MapDrawPolyline component adds a button to the draw control for drawing polylines on the map.

PropTypeDescription
...propsDrawOptions.PolylineOptionsAll props from Leaflet Draw Polyline options.

MapDrawCircle

The MapDrawCircle component adds a button to the draw control for drawing circles on the map.

PropTypeDescription
...propsDrawOptions.CircleOptionsAll props from Leaflet Draw Circle options.

MapDrawRectangle

The MapDrawRectangle component adds a button to the draw control for drawing rectangles on the map.

PropTypeDescription
...propsDrawOptions.RectangleOptionsAll props from Leaflet Draw Rectangle options.

MapDrawPolygon

The MapDrawPolygon component adds a button to the draw control for drawing polygons on the map.

PropTypeDescription
...propsDrawOptions.PolygonOptionsAll props from Leaflet Draw Polygon options.

MapDrawEdit

The MapDrawEdit component adds a button to the draw control for editing existing shapes on the map. When active, you can drag handles or markers to modify shapes, and an undo button appears to revert changes.

PropTypeDescription
...propsOmit<EditToolbar.EditHandlerOptions, "featureGroup">All props from Leaflet Draw EditHandlerOptions.

MapDrawDelete

The MapDrawDelete component adds a button to the draw control for deleting existing shapes on the map. When active, clicking on a shape removes it. An undo button is available to revert deletions.

PropTypeDescription
...propsReact.ComponentProps<"button">All props for the button element.