Skip to content
ProLifetime access for $199, paid once, every future release included
Truffle UI

Map

ProNew

A map with custom markers, an info card and a searchable location list. The street surface is drawn in the browser, so it needs no key and makes no requests; supply your own tiles or surface for real cartography.

Installation

pnpm dlx shadcn@latest add @viewport/map

First time? Add the @viewport registry to components.json. Setup takes one minute.

Usage

The code behind the preview above comes with Truffle Pro.

Props

<MapView>

PropTypeDefault
locations*MapLocation[]—
selectedIdstring | null

The open location. Leave it out to let the map manage it.

—
onSelect(id: string | null) => void—
centerLatLng

Starting center. Without it the map fits every location.

—
zoomnumber

Starting zoom, 2 (world) to 19 (building).

—
minZoomnumber2
maxZoomnumber19
focusZoomnumber

Zoom used when a location is opened; the map never zooms out to reach it.

13
mapStyleMapStyle

`auto` follows the page theme.

"auto"
markerStyleMarkerStyle"pin"
accentstring

Marker and highlight color, any CSS color.

"#e5484d"
accentForegroundstring

Text and glyph color on top of the accent.

"#fff"
routeboolean | LatLng[]

Join the locations in order with a line, or pass the points of your own path.

—
userLocationLatLng

A pulsing dot for the visitor's position.

—
controlsboolean

Zoom and reset buttons.

true
scrollZoomboolean

Zoom with the wheel alone. Off by default so the page keeps scrolling; Ctrl or ⌘ + wheel always zooms.

false
tilesstring

A raster tile URL with `{z}`, `{x}` and `{y}`, for example your own tile server. Leave it out for the built-in street surface.

—
attributionReact.ReactNode

Credit line for the tiles, bottom right.

—
renderSurface(context: MapSurfaceContext) => React.ReactNode

Draw the surface yourself: a static image, canvas, or another map library kept in step with `center` and `zoom`.

—
paddingInsets

Space covered by your own overlays; fitting and focusing keep markers out of it.

—
renderPopup(location: MapLocation, close: () => void) => React.ReactNode

Content of the card above the open marker. Return null for none.

—
labelstring

Accessible name of the map.

"Locations"
loadingboolean—
classNamestring—
childrenReact.ReactNode

Overlays drawn above the map.

—

<Map>

PropTypeDefault
locations*MapLocation[]—
labelstring

Accessible name of the widget and its map.

"Locations"
list"left" | "right" | "none"

Where the location list sits. On narrow containers it becomes a drawer under the map.

"left"
searchableboolean

A search field above the list, filtering by name, address and category.

true
searchPlaceholderstring"Search locations"
defaultListOpenboolean

Start with the list open. Defaults to open when there is room beside the map.

—
selectedIdstring | null

The open location, for controlled use.

—
defaultSelectedIdstring

A location to open on first render.

—
onSelect(id: string | null) => void—
heightnumber | string

Height in pixels, or any CSS length.

520
getDirectionsUrl(location: MapLocation) => string

Where the Directions button goes. Defaults to a Google Maps directions link.

directionsUrl
classNamestring—

Accessibility

  • The map is a focusable region: arrow keys pan, plus and minus zoom, zero fits every location.
  • Every marker is a button named after its place; its card follows it in the tab order and Escape closes it.
  • The list is real buttons and links, and a status line reports how many places match a search.
  • Supplied website addresses become links only when they resolve to HTTP(S); unsafe schemes remain plain text.
  • Under 640px the list becomes a drawer under the map. Panning and zooming jump instead of gliding under reduced motion.