Skip to content

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

Measure Distance Map Block for Ark UI

Click a live map to lay a ruler of legs with their lengths and a running total. Close the loop for the area, undo any step, or measure by keyboard.

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

Measure anything on a map, with this measure distance map for React with Ark UI. Chainrule, a map measuring app, opens on a live Map of Central Park in New York that follows your theme, light or dark, with an open path already laid: six numbered points on a walk from Columbus Circle up to Belvedere Castle and back down to Gapstow Bridge. The path is drawn as a ruler, with a tick every 100 metres and a long one each kilometre, and each leg's length sits in a pill at its middle. Click the map to add a point to the end: each leg is measured along the earth's curve, and the card lists the legs with their lengths and the running total, and adds them up in kilometres and miles. Close loop (or a click on point 1, which says so when you hover it) joins the last point back to the first, and only then does the area appear: the shape fills, its area sits at its centre, and the card gives it in hectares and acres beside the distance round. Press Close loop again to open the path. Undo steps back through the last forty changes, Clear empties the map and Undo brings it back, and a click after the loop is closed starts a new path. For the keyboard, a crosshair button beside the zoom buttons adds a point at the map's centre: pan with the arrow keys, then press it. On wide screens the card floats over the map; on a phone it sits under it. Built from Map, Button and Guides. For running and cycling apps, real estate and land tools, event planning and any app that needs a ruler on a map.

FAQ

How are the distances and the area worked out?

Each leg is the great-circle distance between its two points on a sphere the size of the earth (the haversine formula), so a leg across a city is as right as one across a park. The running total adds the legs in order, and the leg back to point 1 joins them once the loop is closed. The area is the spherical polygon formula mapping tools use, in square metres, shown in hectares (square metres under one) and acres; it appears only on a closed loop, because an open path has none.

Why does the walk read 3.32 km when the paths are longer?

The six starting points are joined by straight legs, and a straight leg is always shorter than the path it skips. Walked on the park's own paths, round the Lake and the rocks, the same six stops come to about 4.2 km. Add points where the paths bend and the total climbs toward it: more points, closer answer. Closed, the loop comes to 3.99 km round and holds 65.43 hectares.

What do the ticks on the line mean?

They are the ruler's marks, counted from point 1 along the whole path: a short tick every 100 metres and a long one each kilometre, so you can read a distance off the line itself. On a line over 10 kilometres they spread to every kilometre, with a long one each 10. The ticks are drawn in metres on the ground, so they grow and shrink as you zoom, like marks on a real map.

Can I measure without a mouse?

Yes. Focus the map and pan it with the arrow keys (plus and minus zoom); a crosshair appears at its centre. Tab to the crosshair button beside the zoom buttons and press it to drop a point there. Undo, Close loop and Clear are ordinary buttons, Close loop says whether the loop is closed, and a polite message gives the new total after each change.

How does it work on a phone?

Tap the map to drop points; drag with two fingers to pan without dropping one. The card moves under the map with the totals, the legs and their running total (in a table that scrolls on its own) and the buttons; the leg lengths stay on the map in their pills.

Is anything saved or sent?

No. The points live in the block's state and go when you leave the page; only the map's tiles are fetched. To keep a measurement, save the shape's points (longitude and latitude pairs) to your own store and pass them back in as the starting shape.