← 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.jsonUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| layerIds | string[] | - | Map layers to query for features in view. |
| property | string | - | Feature property that holds the category value. |
| categories | LegendCategory[] | - | Rows of { value, label, color, icon }. |
| weightProperty | string | - | Sum this numeric property instead of counting features. |
| maxRows | number | 6 | Rows shown before the +N more link. |
| title | string | "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.