Active Sep 2026

Loops (Browser-Only Walking Loop Planner)

Role: Solo, end-to-end: routing engine, elevation pipeline, interactive map UI, and the test suite.
Tech Stack: Vanilla JavaScript (ES modules), MapLibre GL JS from a CDN, a Web Worker for routing, IndexedDB for storage, Node’s built-in test runner.
Live: spskelly.github.io/loops
Repo: GitHub

Overview

This started as a random thought one night when I wanted to walk the dog and switch things up. Loops takes a starting point, a target distance, and a hilliness preference, and hands back up to three walking loops that return to where you started. Type an address, use your location, click the map, or paste coordinates; pick 0.5 to 6 miles and how much climbing you want; get three named routes with an elevation profile, a compass heading, and a GPX file.

There’s no backend. Geocoding, the walking graph, elevation sampling, route generation, and walk history all run in the browser; a 17-line Node script (server.mjs) exists only to serve static files during development. The whole repository, seven JavaScript modules plus the HTML shell, styles, config, and test suite, is 1,794 lines, no build step and no framework: <script type="module"> and a CDN import are the entire toolchain.

What makes this more than a thin wrapper around a map library is the routing. Loops doesn’t call a walking-directions API; it builds its own weighted graph from raw OpenStreetMap data, searches it for candidate loops, scores and deduplicates them, and layers elevation and route editing on top. That’s the part worth explaining.

Building a Loop from Open Map Data

A generated loop starts as an Overpass API query for every walkable way near the starting point (footways, paths, residential and classified roads, steps), cached in IndexedDB for a week so repeat searches don’t refetch. A module worker turns that into an adjacency graph and runs the loop search: sweep 12 compass bearings around the start, and at each bearing try three waypoint radii and two turn directions, looking for a pair of points that makes a reasonable loop shape. Each candidate is stitched together with weighted Dijkstra paths, where an edge already used earlier in the loop costs five times as much on a later leg, which is what keeps candidates from just running out and back along the same street.

Every candidate is scored on distance accuracy, retracing, and quiet paths versus roads. Similar candidates (loops sharing more than 72% of their street segments, by Jaccard similarity on the edge set) get deduplicated before the best three go to the elevation step. Loops outside 60 to 145% of the requested distance, or with more than 32% retracing, are dropped rather than shown as a compromise. In a sparse area, that can mean fewer than three results, or an honest ā€œno good loops hereā€ rather than a route that closes but isn’t the walk anyone asked for.

Road classes aren’t a hard filter. Primary and secondary roads carry a 2.5x path-cost penalty (tertiary 1.85x) specifically so a route can still use a busy road’s unmapped sidewalk when the quieter way around is much longer. The 2.5 is a placeholder set just above tertiary, not a measured value, and the code says to retune it if loops start hugging busy roads. Foot-specific access and one-way tagging is read separately from vehicle rules, since a street that’s one-way for cars is usually still walkable both directions.

Modeling Hills Without a Sensor

Elevation comes from Terrarium-format PNG tiles (zoom 14), decoded per pixel as R * 256 + G + B / 256 - 32768 and bilinearly interpolated across tile boundaries so elevation doesn’t step at tile edges. Each route is resampled every 20 meters, smoothed over a five-sample window, then run through a hysteresis filter that only counts a climb once elevation moves 3 meters past a local low point, so DEM noise on a flat block isn’t counted as a hill. If any tile in a candidate’s path fails to load, that route’s elevation comes back as unavailable rather than zero, and hill-based ranking is disabled entirely rather than silently favoring whichever candidates happen to have data.

The three terrain preferences (gentler, moderate, more climbing) only rerank candidates a search already produced; they can’t manufacture a hilly loop where the street network doesn’t have one. There’s also a progression feature: after a completed walk with elevation data, Loops offers a ā€œnext effortā€ target at 1.07 times that walk’s equivalent flat distance (physical distance plus nine times the elevation gain in meters), then rescores new candidates against that heavier number. It’s a planning heuristic borrowed from a common effort-equivalence rule of thumb, not a training plan or a claim of exact difficulty.

Editing and Drawing Your Own Route

Two more paths besides the generated loops. Dragging a selected route’s line onto a nearby street sends a local reroute request to the worker: it excludes the dropped segment, keeps the rest of the loop untouched, and searches only the neighborhood around the drag rather than rebuilding the whole route, with an undo that restores the previous version. Exclusions apply to that one edited loop, not a permanent blacklist.

The other path skips generation entirely: tap points on the map in order and Loops connects them with real walking paths, closing the loop back at the start. Taps snap to the nearest walkable street segment within 60 meters, not the nearest graph node, which fixed a real bug: a tap near the middle of a long primary road with no separately mapped sidewalk used to jump to the nearest side-street dead end, and the route detoured there and back for no reason. Snapping to the segment, then walking to whichever end of it is closer to the tap, fixed that.

Limits

Loops trusts OpenStreetMap for sidewalks, crossings, lighting, and access restrictions, and OSM doesn’t tag those consistently, so a route reflects what’s mapped, not a safety or accessibility guarantee. The start point snaps to the nearest mapped path within 250 meters, and that offset isn’t included in the reported distance. Target distance is approximate by design (candidates outside 60 to 145% of the ask are excluded), and drawn routes aren’t checked against a target distance at all, since you chose where they go. Elevation is a DEM estimate that can disagree with the ground at bridges, tunnels, and stairs. There’s no offline map download, no background location tracking, and no turn-by-turn guidance, only a suggested route and a GPX file.

Tests

18 unit tests run through Node’s built-in test runner with zero dependencies, covering geometry and antimeridian sampling, elevation hysteresis, OSM access filtering, one-way handling, shortest-path reuse penalties, the bearing sweep producing genuinely distinct closed loops, empty and disconnected graphs, Terrarium tile decoding, GPX escaping, route reversal, drag-based rerouting, and the segment-snapping fix above. A separate Playwright-driven browser suite documents 13 further end-to-end scenarios (route generation, location handling, mobile layout, and more) against intercepted network fixtures; it needs a running server, a real Chrome install, and CDN access, so it wasn’t run for this page, only read.

Features

  • Three loop candidates per search - deduplicated by street overlap, scored on distance accuracy, retracing, and road mix
  • A hand-built routing graph, not a directions API - OSM ways and nodes turned into a weighted graph in a Web Worker
  • Elevation-aware ranking - three hilliness preferences rerank candidates from Terrarium DEM tiles, disabled if any candidate is missing terrain data
  • Progressive difficulty - after a completed walk, offers a next target scaled to that walk’s climbing-adjusted distance
  • Drag-to-reroute - pull the route onto another street for a local detour that leaves the rest of the loop alone, with undo
  • Draw-your-own routes - tap points on the map and get real walking paths between them, snapped to the street network
  • GPX export and reversal - either direction, with the elevation profile and heading updated to match
  • Local walk history - completed walks, including route geometry, saved in IndexedDB with no account or backend
  • Saved starting points - named locations with an optional default, so reopening the app skips re-entering an address

Tech Stack

  • Language: Vanilla JavaScript, ES modules, no transpilation and no bundler
  • Map rendering: MapLibre GL JS, loaded from a CDN rather than installed as a dependency
  • Routing: A hand-written weighted Dijkstra implementation with a binary heap, in a Web Worker so it doesn’t block the UI
  • Data sources: Photon for geocoding, Overpass for the walking graph, Terrarium elevation tiles, OpenStreetMap raster tiles for the basemap
  • Storage: IndexedDB for walk history, saved locations, and caching; nothing leaves the browser except requests to those map services
  • Testing: Node’s built-in test runner for 18 dependency-free unit tests, Playwright for a documented browser integration suite
  • Dev server: A 17-line stdlib HTTP server for local development; production is static file hosting