← 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.jsonUsage
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
| Prop | Type | Default | Description |
|---|---|---|---|
| layers | LayerPanelLayer[] | - | Rows of { id, label, layerIds, visible, opacity, swatch }. |
| onChange | (layers) => void | - | Receives the next array of rows. Keep it in state. |
| applyToMap | boolean | true | Set false to drive the map yourself from onChange. |
| title | string | "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.