Skip to content

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

Elevation Profile Map Block for Svelte

A ride to Cap de Formentor on a live map, shaded by grade. Run along the elevation profile to move a dot on the road and read its height and grade.

On this page5 sections
UI library: Ark UI

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

Read a ride by its hills, with this elevation profile map for Svelte with Ark UI. Spokeroll, a ride log, draws the road from Port de Pollença to the Cap de Formentor lighthouse in Mallorca on a live Map that follows your theme, light or dark: nineteen kilometres, two climbs and a long drop to the beach in between. The profile under the map is the control. Run the pointer or a finger along it, or focus it and use the arrow keys, and a dot rides the road on the map while the readout gives the distance, the height and the grade at that point; hover the road on the map and the profile's cursor follows you back. The road and the profile share four grade bands: thin and grey under 2 percent or downhill, then three steps of the theme's chart ramp up to 6 percent and over, named in the legend under the map. Four sections under the profile give each stretch's average grade, its length and the metres up and down; pressing one frames its stretch of road, fades the rest and moves the cursor to its start, and the route button frames the whole ride again. Built from Map, Button and Guides. For cycling and running apps, route builders, race guides and anything with a track and a hill.

FAQ

How do the profile and the map stay in step?

Both read one position: a distance along the road, in steps of 100 m. The profile is a native range input laid over the drawing, so a click, a drag or an arrow key moves it, and a mouse moves it by hovering. The dot on the map is a MapRouteMarker at that distance's share of the road. Going the other way, a small RoadWatcher inside the map listens to the pointer and, when it comes within 24 pixels of the road, finds the nearest point on it and hands that distance to the profile.

How are the grade bands worked out?

The heights sit at 97 even steps along the road, about 200 m apart. Each step's grade is its rise over its length; under 2 percent (or downhill) is the flat band, then 2 to 4, 4 to 6, and 6 percent and over. Neighbouring steps in the same band and the same section join into one run, drawn on the map as one line and on the profile as one filled area, so the two always agree. The sections' averages, the metres up and down and the ride's total climb all come from the same heights.

Where do the road and the heights come from, and what stays local?

The road was routed once along OpenStreetMap streets and baked into the file, simplified to 10 m. The heights blend two public terrain models, smoothed over about a kilometre and joined straight through the tunnel under El Fumat, where a terrain model would read the mountain above the road. Spokeroll and the ride are invented. Nothing is fetched but the map's tiles; to show your own ride, swap in its track and its heights.

Can I use it without a mouse?

Yes. Tab to the profile and use the arrow keys to move 100 m at a time, Home and End to jump to the start and the finish; screen readers hear the distance, height and grade with each step, and a polite message repeats it once you stop. The four sections and the map's buttons are ordinary buttons, and the map takes the arrow keys and plus and minus once focused.

How does it work on a phone?

Put a finger on the profile and slide it sideways to ride the road; sliding up or down still scrolls the page. The map pans with two fingers so the page never gets stuck on it. The four sections sit two by two under the profile.

Why does the steepest band change shade in dark mode?

The chart ramp runs from a light shade to a dark one in every preset. On a light map and card the darkest shade stands out most, and on a dark one the lightest does, so the steepest band takes whichever end contrasts with the ground. The flat band is always the thin grey line, so the bands never rest on colour alone.