← All components

Layer panel

A switch and an opacity slider for every layer group.

Previews run on MapScale's public Thailand archive.

Install

npx shadcn@latest add https://mapscale.io/r/layer-panel.json

Usage

import { LayerPanel, type LayerPanelLayer } from "@/components/mapscale/layer-panel"

const [layers, setLayers] = useState<LayerPanelLayer[]>([
	{ id: "stations", label: "Stations", layerIds: ["stations"], visible: true, opacity: 1, swatch: "#e11d48" },
])

<Map>
	<GeoJSONLayer id="stations" type="circle" data={stations} paint={{ "circle-radius": 6 }} />
	<LayerPanel layers={layers} onChange={setLayers} />
</Map>

Props

PropTypeDefaultDescription
layersLayerPanelLayer[]-Rows of { id, label, layerIds, visible, opacity, swatch }.
onChange(layers) => void-Receives the next array of rows. Keep it in state.
applyToMapbooleantrueSet false to drive the map yourself from onChange.
titlestring"Layers"Heading of the panel.

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.