Library phase 2: rename/recolor nodes, rename and move folders, split a layer into items; offline routing design

This commit is contained in:
randy committed 2026-11-13 21:16:35 +01:00
1 parent 4d838395b8
commit 6f5f11cb4d
9 files changed
+467 -39

No files matched your search

+18 -1
View File
@@ -2,7 +2,7 @@
:toc:
:toclevels: 2
Status: *phase 1 implemented* (`lib/maptool/library.rb`, see Decisions); phases 2–4 proposed. Replaces the file-based store behind
Status: *phases 1–2 implemented* (`lib/maptool/library.rb`, see Decisions); phases 3–4 proposed. Replaces the file-based store behind
Tracks & Points (`GpxStore`) with an item-based library that OsmAnd, Locus
Map and the MapTool web app can all be synced against.
@@ -324,6 +324,23 @@ removed once nothing uses them.
* Migration runs on first start (no `library.sqlite` yet); `rake
library:migrate` re-runs it (idempotent).
== Decisions (phase 2)
* Rename and color apply to tracks, routes and layers (the node in the
tree). Color is stored as `properties.color` and drawn as the line
color. A layer's color is laid over its legacy GeoJSON when it's served.
Single points keep their category color from the GPX.
* Folders: rename, and move by dragging one onto another folder (or onto
the tree's blank space for the top level). Moving into a folder's own
subfolder, or next to a sibling of the same name, is refused.
* "Split into items" turns a migrated layer into ordinary items in its
folder. Its notes keep their ids, the legacy file is copied to
`sources/` as their "original", and the layer is tombstoned.
`data/gpx/` isn't touched. A note edited in an unsplit layer still
goes to its legacy file.
* `GpxStore` stays, since unsplit layers are still drawn from it. It goes
away once nothing is a layer any more.
== Open questions
* Folder depth over 3 — fine to require Locus Premium?
+113
View File
@@ -0,0 +1,113 @@
= Offline routing — design
:toc:
:toclevels: 1
Status: proposal, nothing implemented yet.
== Goal
Car/camper routing that works with no internet, from the same OSM
extracts the offline map is built from, with the vehicle's dimensions
(height, width, length, weight) respected, so the route doesn't go
under a 3 m bridge or over a 3.5 t bridge. Later on the same engine:
an elevation profile of the route and isochrones ("how far in 2 hours").
== Engine: Valhalla
[cols="1,3"]
|===
| Valhalla
| `truck` costing takes height/width/length/weight/axle load per
*request*, so one graph serves any vehicle. Has `/isochrone`,
`/height` and `/optimized_route` built in. Tiles are a memory-mapped
tar, so RAM stays modest even for many countries. Chosen.
| GraphHopper
| Java is already in the image (Planetiler), and custom models can do
dimensions too, but the import for ~16 GB of PBF wants a heap close
to the server's 30 GB RAM.
| OSRM
| Fastest queries, but restrictions are baked in at build time: one
graph per vehicle profile, no dimension parameters per request.
|===
== Data
The PBF files are already there: `data/geofabrik_cache/<CC>.osm.pbf`,
one per country selected for the offline map (`data/offline_regions.json`,
currently 14 countries, ~16 GB). Routing uses exactly that set, so
there's no second region picker. The files are hard-linked into
`data/routing/pbf/` (same file system, no copies, and Geofabrik refreshes
don't change a build that's in progress).
Measured on the server: 16 cores, 30 GB RAM, 780 GB free. Rough
expectation for this set: tiles 15–25 GB, a build of a few hours. The
build runs at a low priority and the old tiles keep serving while it
runs.
== Containers
Valhalla isn't packaged for Debian trixie, so it doesn't go into the
maptool image. Instead there's one more compose service, the same pattern
as `kiwix`:
[source,yaml]
----
valhalla:
image: ghcr.io/valhalla/valhalla:<pinned tag> # renovate bumps it
restart: unless-stopped
command: ["/app/bin/routing-service.sh"]
volumes:
- ./data/routing:/routing:z
- ./build/bin/routing-service.sh:/app/bin/routing-service.sh:ro,z
----
It uses the base image (binaries only), not `valhalla-scripted`. The
scripted image only rebuilds when the container restarts, and maptool
can't restart containers. Instead `bin/routing-service.sh` (~40 lines of
shell) runs inside it:
. Serve `valhalla_service` from `tiles.tar`, if one exists.
. Poll for `data/routing/build-request.json`. When it shows up, build
into `staging/` (`valhalla_build_config`, `valhalla_build_admins`,
`valhalla_build_timezones`, `valhalla_build_tiles`,
`valhalla_build_extract`), writing the current step to `status.json`.
. When the build succeeds, swap `staging/tiles.tar` in and restart
`valhalla_service`. When it fails, keep the old tiles and put the log
in `status.json`.
maptool reaches it at `http://valhalla:8002` (`VALHALLA_URL`), server
side only, like `KIWIX_URL`.
== maptool side
* "Build routing" next to the existing offline/terrain builds, login
required. It writes `build-request.json` and links the PBF files.
Status and history appear in the same build panel (`build_history`).
* `POST /api/route` proxies to Valhalla `/route` with `costing: truck`
and the vehicle profile filled in. It's open to everyone, like the
map. Login is required only to save the result.
* Vehicle profile: height, width, length, weight. Stored server-side,
one for now, editable in the route panel.
* Route panel: start, end and via points (map click, search result, GPS
position, a library point), the route drawn with distance, time and
turn list. "Save to library" stores it as a `route` item, so the
route goes to OsmAnd/Locus through the same export as everything
else.
== Phases
. Container + build script + "Build routing" + status. Done when
`curl valhalla:8002/route` answers on the server.
. `/api/route`, the vehicle profile, the route panel, save to library.
. Elevation profile of the route (sampled from `terrain.pmtiles`, which
is already there, instead of Valhalla's own SRTM download), then
isochrones.
== Open questions
* Pin a Valhalla version: take the latest `ghcr.io/valhalla/valhalla`
release tag at implementation time and add it to Renovate (a docker
image in compose is tracked by default).
* Trailer / several vehicle profiles: one profile until it's needed.