Skip to content

shadcn.io is an independent project built on shadcn/ui

Layer Switcher Map Block for Ark UI

A layers panel beside a live map of Copenhagen: show or hide noise monitors, bike routes, bus lines and parks, set each one's opacity, and read its legend.

On this page5 sections

Preview

Preview width

Installation

Part of Pro
Pro unlocks the code and one-line install of every Pro button and text effect, plus the MCP for your AI editor.
Have Pro already? Sign in to open it.Opens here as soon as you're Pro.

Overview

Let people choose what the map shows, with this layer switcher map for React with Ark UI. Citysheaf, a city open-data map, stacks four overlays on a live Map of central Copenhagen that follows your theme, light or dark, and each is a different kind of layer: twelve noise monitors as points sized and shaded by their reading, four bike routes as solid lines, two bus lines as dashed and dotted lines with a letter tile at each end, and seven parks as filled outlines. The panel beside the map lists them in the order they are drawn, the top one first. Each layer has a Switch that shows or hides it, an opacity Slider that turns off while the layer is hidden, a line on what it holds (routes and kilometres, parks and hectares) and its own legend: the four noise bands with their counts, the line styles, the park swatch. Hovering a park or a monitor names it in a popup with its reading or its area. Reset brings every layer back at its first opacity. Built from Map, Switch, Slider, Button and Guides. For city data portals, planning tools, transit and real estate maps, and any map with more than one thing to show.

FAQ

How does hiding a layer work?

Every layer stays on the map from the start, in the same order, and its switch only sets its opacity to nothing and stops it answering the pointer. Turning a layer back on brings it back where it was, at the opacity its slider still holds, so the stacking never changes: parks at the bottom, then the bus lines, the bike routes and the noise monitors on top.

What does the opacity slider change?

Each layer's paint is multiplied by its slider, from 0 to 100 percent in steps of five: the parks' fill and outline, the lines' strokes, the monitors' dots and their rings, and the letter tiles at the bus lines' ends. The parks start at 70 percent and the bus lines at 80, so the routes read first; Reset restores those and shows every layer again.

Where does the data come from, and what stays local?

The bike routes and bus lines were traced once along the streets with OSRM (bike and car profiles) and the parks are OpenStreetMap's outlines, simplified and typed into the file; nothing is fetched but the map's tiles. Citysheaf, the line letters and the noise readings are invented. Switches and sliders only change what this page shows; nothing is saved.

Can I use it without a mouse?

Yes. Each switch is named for its layer and toggles with Space; each slider is named for its layer's opacity, moves with the arrow keys, Page Up and Page Down, Home and End, and reads its value as a percentage. Reset and the map's zoom buttons are in the tab order, and a polite message says which layer was shown, hidden or changed. The popups only name one park or monitor under the pointer; the panel's lines and legends carry every layer's bands, counts and totals.

How do the legends tell the layers apart?

By shape and size, never colour alone: bike routes are solid, bus line A dashed and line B dotted, each with its letter; parks are a filled swatch; the noise monitors grow with their band (under 55, 55 to 64, 65 to 69, 70 dB and over) and step along the theme's chart ramp, darker on a light map and lighter on a dark one, with how many monitors are in each band beside it.

How does it look on a phone?

The map comes first, then the layers panel under it, one layer to a row with its switch, legend and slider. Scrolling over the map scrolls the page; two fingers pan it.