Game Map

A world map and a HUD minimap that share one set of data, laid out like a maps app: small pins whose labels make room for each other, numbered clusters when zoomed out, a place panel (side panel on wide maps, bottom sheet on phones), filter chips, search, "find me", zoom and a scale bar. Regions can sit under clouds until discovered. Everything is in your game's own units, so markers come straight from game state.

View as Markdown

Click a pin to open its place panel with your own buttons (Travel moves the player). Labels that would overlap hide and show on hover; pins close together become a numbered cluster. Right-click or long-press drops a waypoint; Explore lifts the clouds off a region.

VillageRice paddiesRiver bend??????
Drag, scroll or pinch. Double-click to zoom in, right-click (or long-press) to drop a waypoint.

Installation

npx shadcn@latest add @cozy/game-map

Usage

import { GameMap, MiniMap } from "@/components/ui/game-map"

const world = {
  mapWidth: 1200, mapHeight: 800, background: "/maps/village.png",
  markers: [{ id: "market", x: 746, y: 466, label: "Market", kind: "shop", tracked: true }],
  regions: [{ id: "hill", name: "Temple hill", points: [[880, 0], [1200, 0], [1200, 280]], discovered: false }],
  kinds: { shop: { label: "Shops", icon: <CoinIcon />, color: "#7FC4E0" } },
  player: { x: 520, y: 300, heading: 90 },
}

<MiniMap {...world} onOpen={() => setOpen(true)} />
<GameMap {...world} search height={480} onMarkerSelect={(m) => console.log(m)} />

Examples

MiniMap

The minimap follows the player. Tracked places out of range show as arrows on the rim. rotate turns the map so the player faces up; click a minimap to open the full map.

Village
Village6:40 am

API

Everything else is passed through to the underlying element or Radix primitive.

PropTypeDefaultDescription
mapWidth / mapHeightnumber–Map size in your units. x runs 0..mapWidth to the right, y 0..mapHeight down.
backgroundReactNode | string–An image URL, or an SVG, canvas or tile grid drawn at mapWidth × mapHeight.
markersMapMarker<T>[]–{ id, x, y, label, kind?, icon?, color?, subtitle?, description?, image?, priority?, tracked?, alert?, hidden?, data? }. Higher priority wins label space. Markers inside regions under clouds are hidden.
regionsMapRegion[]–{ id, name, points, color?, discovered?, labelAt? }. `discovered: false` covers the region with clouds.
paths / player / waypoint / kindsMapPath[] / MapPlayer / [x, y] / Record<string, MapKind>–Routes { points, color?, dashed?, width? }, the player { x, y, heading?, icon?, label? }, a waypoint flag, and marker kinds { label, icon?, color? } for the filter chips.
GameMap: heightnumber | string460Box height; width fills the container.
GameMap: view / defaultView / onViewChange{ x, y, zoom }player, fillControl the centre and zoom. Zoom 1 = one map unit per px.
GameMap: minZoom / maxZoom / labelZoom / focusZoomnumberfill / 4 / always / 1.8×fillZoom limits (by default the map just fills the box), when labels appear, and the zoom used when flying to a place.
GameMap: selectedId / onMarkerSelectstring | null / (marker | null) => void–The open place. The map moves so it is never under the panel; Escape, the close button, a click on the map or pulling the sheet down closes it.
GameMap: renderMarker / renderDetails / markerActionsfn–Your own pin, place panel body, or buttons in the default panel.
GameMap: clusternumber34Pins closer than this many px merge into a numbered bubble; clicking it zooms in. 0 turns it off.
GameMap: onWaypointChange(point | null) => void–Right-click or long-press on the map gives you a point to store as `waypoint`.
GameMap: scale{ perUnit, unit }–Scale bar: one map unit is perUnit of unit, e.g. { perUnit: 0.5, unit: "m" }.
GameMap: search / legend / controls / followPlayerbooleanfalse / true / true / falsePlace search, filter chips, zoom and find-me buttons, and keeping the player centred.
GameMap: hiddenKinds / onHiddenKindsChangestring[][]Control the legend filter.
MiniMap: size / shapenumber / "circle" | "square"168 / "circle"Box size in px and shape.
MiniMap: zoom / defaultZoom / onZoomChangenumber1Zoom level, with + and − buttons (zoomControls).
MiniMap: rotate / compass / showRegionbooleanfalse / true / trueHeading-up map, the north marker, and the name of the region you are in.
MiniMap: center / onOpen / children[x, y] / () => void / ReactNodeplayerCentre (defaults to the player), click to open the full map, and overlays like a clock.
regionAt / useRegionChangefunction / hook–The region that contains a point, and a hook that calls you when the player moves into another region (e.g. to show "Entering the Rice paddies").