Map

New

High-performance interactive vector map and geospatial visualization component powered by MapLibre GL with dark/light themes, custom HTML markers, popups, controls, routes, arcs, GeoJSON layers, and clustering.

$ pnpm dlx shadcn@latest add @byphongphan/map
Requires @byphongphan in components.json
data-display
Loading preview...

Installation

$ pnpm dlx shadcn@latest add @byphongphan/map
Requires @byphongphan in components.json

Anatomy

Map├── MapControls (Zoom, Compass, Locate, Fullscreen)├── MapMarker│   ├── MarkerContent (Custom HTML pin / beacon icon)│   ├── MarkerLabel (Anchored text label)│   ├── MarkerTooltip (Hover tooltip)│   └── MarkerPopup (Rich interactive popup card)├── MapPopup (Standalone coordinates-based popup)├── MapRoute│   ├── RouteProgress (Animated polyline progress)│   └── RouteMarker (Start / End / Progress anchored markers)├── MapArc (Great-circle curved arcs between coordinates)├── MapGeoJSON (Vector polygon, line, point layers)└── MapClusterLayer (Supercluster point clustering)

Usage

import {  Map,  MapControls,  MapMarker,  MarkerContent,  MarkerPopup,  MarkerTooltip,} from "@/components/ui/map"
export function MyMap() {  return (    <div className="h-[400px] w-full overflow-hidden rounded-xl">      <Map center={[-122.4194, 37.7749]} zoom={12}>        <MapControls position="top-right" showZoom showCompass />        <MapMarker longitude={-122.4194} latitude={37.7749}>          <MarkerContent>            <div className="size-4 rounded-full border-2 border-white bg-primary shadow-md" />          </MarkerContent>          <MarkerTooltip>San Francisco HQ</MarkerTooltip>          <MarkerPopup closeButton>            <div className="p-2">              <h4 className="text-xs font-semibold">San Francisco</h4>              <p className="text-[11px] text-muted-foreground">                Market Street Office              </p>            </div>          </MarkerPopup>        </MapMarker>      </Map>    </div>  )}

Features

  • Theme Synchronization: Seamlessly listens to system color schemes and next-themes document class or data-theme changes, automatically hot-swapping between Carto dark and light matter vector tiles.
  • Blank Canvas Mode: Use blank={true} for tile-less data visualization (arcs, flight routes, choropleths) without rendering street basemaps.
  • Declarative HTML Markers: Render rich React elements directly on the map using React portals with tooltips, labels, and popups.
  • Built-in Navigation Controls: Single-component MapControls handling zoom, compass bearing reset, device geolocation, and full-screen toggling.
  • Geodesic Flight Arcs: Render smooth quadratic Bézier great-circle curved arcs (MapArc) between coordinate pairs with interactive hover highlighting.
  • Polylines & Routes: Draw paths (MapRoute) with customizable colors, line widths, dash arrays, and anchored markers (RouteMarker).
  • GeoJSON & Clustering: Native GeoJSON layer rendering and supercluster point clustering with custom cluster colors and zoom steps.

Examples

Map with Custom Markers & Popups

Render custom HTML markers with hover tooltips and interactive popup cards.

Configure zoom buttons, compass rotation indicator, geolocation locator, and fullscreen mode.

Vector Route

Visualize routing pathways, delivery trails, or journeys between endpoints with custom line styles and anchor pins.

Curved Great-Circle Arcs

Display curved connection lines between global cities for flight tracking, global data transfer, or networking visualization.


API Reference

Map

The root map container that initializes MapLibre GL and provides the map context.

PropTypeDefaultDescription
center[number, number]undefinedInitial center coordinates [longitude, latitude].
zoomnumberundefinedInitial zoom level.
theme"light" | "dark"System/DocExplicit theme override. If omitted, automatically detects document class or system preference.
styles{ light?: string; dark?: string }Carto Positron / Dark MatterCustom style URLs or StyleSpecification objects.
blankbooleanfalseRenders a transparent, tile-less basemap for clean data visualizations.
projectionProjectionSpecificationundefinedMap projection. Set { type: "globe" } for 3D globe mode.
viewportPartial<MapViewport>undefinedControlled viewport object { center, zoom, bearing, pitch }.
onViewportChange(viewport: MapViewport) => voidundefinedCallback fired continuously as viewport pans, zooms, or rotates.
loadingbooleanfalseDisplays a pulsing loader overlay while loading.

MapMarker

Declarative HTML marker pinned to geographic coordinates.

PropTypeDefaultDescription
longitudenumber—Target longitude coordinate.
latitudenumber—Target latitude coordinate.
draggablebooleanfalseWhether the marker can be dragged across the map.
onClick(e: MouseEvent) => voidundefinedClick event handler.
onDragEnd(lngLat: { lng: number; lat: number }) => voidundefinedCallback fired when drag operation ends.

MapControls

Floating navigation and utility control group.

PropTypeDefaultDescription
position"top-left" | "top-right" | "bottom-left" | "bottom-right""bottom-right"Corner alignment on map.
showZoombooleantrueShow zoom-in and zoom-out buttons.
showCompassbooleanfalseShow 3D compass needle to reset bearing to north.
showLocatebooleanfalseShow geolocation locator button.
showFullscreenbooleanfalseShow fullscreen toggle button.
onLocate(coords: { longitude: number; latitude: number }) => voidundefinedCallback with coordinates when user is located.

MapRoute

Polyline vector route layer rendered from coordinate arrays.

PropTypeDefaultDescription
coordinates[number, number][]—Array of [longitude, latitude] pairs defining the route path.
colorstring"#4285F4"Line color CSS value.
widthnumber3Line width in pixels.
opacitynumber0.8Line opacity from 0 to 1.
dashArray[number, number]undefinedStroke dash pattern [dash, gap].
progressnumberundefinedFraction of route completed (0 to 1).
activebooleanfalseMoves route to top of z-index and applies active styles.

MapArc

Quadratic Bézier great-circle curved arcs between coordinates.

PropTypeDefaultDescription
dataMapArcDatum[]—Array of arcs { id, from: [lng, lat], to: [lng, lat] }.
curvaturenumber0.2Curvature factor bowing away from straight line.
samplesnumber64Interpolation resolution along the curve.
paintLinePaint—MapLibre paint properties for line layer.
hoverPaintLinePaint—Paint properties applied to hovered arc.
onClick(e: MapArcEvent) => voidundefinedArc click callback.
onHover(e: MapArcEvent | null) => voidundefinedArc hover enter/leave callback.

Command Palette

Quick search and commands navigation