Skip to content

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

Route Planner Map Block for React

A delivery round across Dublin as an app window: reorder, remove and add stops, watch road distance and arrivals re-derive, and optimise the order.

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

Plan a delivery round and see what each change costs, with this route planner map for React with Base UI, shown as a small app window. Pathwright, a delivery-round planner, lists a Thursday round beside a live Map of Dublin that follows your theme: a depot in North Wall and five shops in real neighbourhoods, from Smithfield to Ranelagh. The round is drawn leg by leg along the roads; each stop after the depot has Move up, Move down and Remove buttons, and the road distance, the drive and the arrival time at every stop re-derive on every change. The top bar's one primary, a Shine Button, optimises the order: it keeps the depot first, visits the nearest unvisited stop by road each time and says what it saves, with an Undo. Two suggested stops wait on the map as dashed rings; a ring, or its button under the list, adds it at the end. Pressing a stop, in the list or on the map, brings its leg forward and fades the others. A short status line at the foot of the window says what changed. Built from Map, Shine Button, Button and Guides. For logistics, field-service and last-mile apps.

FAQ

Where do the roads and distances come from, and what is sent?

Every leg between every pair of the eight places was traced once with OSRM's driving profile, thinned and stored in LEG_LINES with its length in metres; the other way round reads the same road backwards. Nothing is fetched at run time except the map tiles, nothing is sent to a driver, and the order lives in this tab. The neighbourhoods are real; the shops, the depot and the round are invented sample data.

What does Optimise order do?

nearestOrder keeps the depot first and then always drives to the nearest stop not yet visited, by road metres, and the block compares the two totals. If the new order is shorter it applies it, shows how much it saves and offers Undo; if not, the status line says it's already the nearest-first order. Nearest neighbour is a quick rule, not the best possible route, so use a solver in your app.

How are the times worked out?

The drive is the road distance at SPEED_KMH (22 km/h, a van in town), plus DWELL minutes (8) at every stop after the depot, and the arrivals count from START_MINUTES (08:30). Moving, removing and adding a stop recompute every arrival, the total and the legs on the map.

Can I reorder without dragging?

Yes: each stop has Move up, Move down and Remove buttons named with the stop, and focus stays on the button you used after the list changes (on the list's heading after a removal). The suggested stops are buttons under the list, and the map's zoom buttons and the map itself work from the keyboard. The markers and rings on the map are a pointer shortcut to the same actions.

Why doesn't the map move when the round changes?

The camera frames the depot, the five stops and the two suggestions once, with MapCamera, and stays there, so you can compare orders on the same view. Pan and zoom freely; picking a stop draws its leg wider and fades the rest rather than flying away.

How does it look on a phone?

The top bar keeps the title and the optimise button; the map comes next at a fixed height with the caption under it, then the totals, the stops and the suggestions, and the status line at the foot. From a tablet up the stop list sits beside the map in a window of fixed height and scrolls inside it.