← All components

Viewport legend

A live legend of what is on screen, with percentage bars and click-to-filter.

Previews run on MapScale's public Thailand archive.

Install

npx shadcn@latest add https://mapscale.io/r/viewport-legend.json

Usage

import { ViewportLegend } from "@/components/mapscale/viewport-legend"

<Map>
	<GeoJSONLayer id="places" type="circle" data={places} />
	<ViewportLegend
		layerIds={["places"]}
		property="kind"
		categories={[
			{ value: "cafe", label: "Cafe", color: "#c2410c" },
			{ value: "park", label: "Park", color: "#15803d" },
		]}
	/>
</Map>

Props

PropTypeDefaultDescription
layerIdsstring[]-Map layers to query for features in view.
propertystring-Feature property that holds the category value.
categoriesLegendCategory[]-Rows of { value, label, color, icon }.
weightPropertystring-Sum this numeric property instead of counting features.
maxRowsnumber6Rows shown before the +N more link.
titlestring"In view"Heading of the legend.

Keys

Maps, autocomplete and place details use a publishable pk_ key that is safe in the browser. Routing and isochrones need a secret sk_ key, so they go through the proxy route your app serves.