shadcn.io is an independent project built on shadcn/ui
On this page5 sections
Installation
Overview
Compare two versions of one place with a divider, with this swipe compare map for React with Base UI. Spokeplan, a cycling network planner, puts Lyon's protected bike lanes today on one live Map and its 2030 plan on a second map laid exactly over it, both following your theme, light or dark. A divider cuts the pair: today's map shows on its start side, the plan's on the other, so dragging the round handle (or the line itself) wipes one network into the other. Focused, the handle is a slider: the arrow keys move it a step, Shift or Page Up and Page Down ten, Home and End all the way, and a polite message says where it rests. The two maps share one view, so a pan or a zoom on either moves both, and the side tags fade when their half gets too thin to label. Today's three lanes are solid on both maps and the plan's five new lanes are dashed; the band under the map compares the halves (lanes, kilometres summed from the drawn lines, and the share of homes near a lane) and lists each one's lanes. Built from Map and Guides. For city planning, before and after studies, scenario reviews and any change you want people to see at a glance.
FAQ
How does the swipe work?
Two MapViews fill the same box. The plan's map sits on top with a see-through box, and only its drawing (the map canvas) is cut by a CSS clip-path at the divider, read from one --swipe variable. Where the plan's drawing is cut, the pointer goes through to today's map, so either map can be dragged; the zoom buttons belong to the plan's map and stay on top. No map is redrawn when the divider moves.
How do the two maps stay in step?
Both maps take one viewport state and report every frame of their own moves through onViewportChange. The map being moved keeps its own motion; the other jumps to the same centre and zoom on each frame. A MapCamera on the plan's map frames every lane at the start, and today's map follows it.
Can I use it without a mouse?
Yes. The handle is in the tab order with the slider role: Left and Right Arrow (or Up and Down) move it 1%, Shift with an arrow, Page Up or Page Down move it 10%, Home shows the plan everywhere and End shows today everywhere. In a right-to-left page the arrows follow the reading direction. Each map also takes the arrow keys and plus and minus once focused, and the zoom buttons work from the keyboard.
Where do the lanes come from, and what stays local?
Each lane was routed once along Lyon's real streets with OpenStreetMap's bike routing (OSRM), simplified and typed into LINES at the top of the file; the kilometres are summed from those points. Spokeplan, the plan and the shares of homes are invented. Nothing is fetched or saved but the map tiles.
How does it look on a phone?
The map comes first, as tall as on a small tablet, and the handle is a 44-pixel target that a finger drags without moving the map. One finger scrolls the page and two fingers pan the maps. The two halves of the band stack under the map, today first.
Can it compare something else?
Yes. Each map is a full MapView, so any layer works on either side: two survey years, a flood extent before and after, two scenarios, or the same data in two styles. Keep what differs in map layers (routes, GeoJSON, heatmaps), which the cut applies to; markers sit above both maps, so keep them to the places both sides share.





