Files
TREK/wiki/Route-Optimization.md
T
Maurice 44c92052a3 docs(wiki): bring the pages in line with 4.3.0
Every page was read against the code on dev. What changed:

- Pages that described 4.2 behaviour: satellite view on the vector maps,
  the mobile journal timeline, Collab with its fifth tab, the Review badge,
  clustered pins on the share page, the Leaflet preset list, the strict
  guard on fe80::/10, the invite link tools and their scopes, the Public
  API scope rules, the permission count in the plugin SDK.
- Features of this release that no page mentioned: videos in a journal
  entry, receipts on an expense, the Google transit backend, routing
  counters, the rating on a place, the navigation menu, car stops, the
  manual school holiday catalogue and its MCP tools, the Dawarich panel in
  the Atlas, the release notes modal, plugin frames going fullscreen, the
  corridor call into the search provider hook.
- Statements that sent an admin the wrong way: DEFAULT_LANGUAGE is not in
  the Helm ConfigMap, env.PORT cannot be changed on the chart alone, the
  rotation script does not cover the document sync credentials, event
  handlers cannot broadcast, there is no per user MFA reset in the admin
  panel, the demo user can edit, an unparsable APP_URL stops the server.
- Updating gets a section for 4.3.0: the TREK Places API as the new
  default, the new variables, the Overpass timeout, SSO sessions on an
  OIDC only instance, the migration that puts booked nights on the drive.
2026-09-20 12:11:41 +02:00

6.9 KiB

Route Optimization

TREK calculates walking and driving times between your places and can reorder them to minimize total travel distance.

Route Optimization

Route calculation

TREK uses OSRM (Open Source Routing Machine) to calculate routes between consecutive places in the selected day. No API key is required. By default that is the public FOSSGIS OSRM, which allows about one request a second. An admin can point TREK at an OSRM of their own under Admin → User Defaults (Own routing engine, restart required); see Road-Trip.

The route toggle in the day-plan footer offers a Driving and a Walking profile (each routed on the matching OSRM network). Installed plugins can add further profiles: a plugin with the routeProvider hook — for example an e-mobility plugin that plans charging stops — appears as an extra mode next to Driving/Walking. When such a profile is selected, that plugin computes the day's route: its geometry is drawn on the map, planned stops (e.g. chargers) appear as small dots on the line, and the leg connectors show the plugin's travel times plus any note it attaches ("25 min charge"). If the plugin fails or times out, TREK falls back to straight lines exactly as it does on an OSRM outage.

That toggle sets the day's default travel mode. It is stored on the day, so each day of a trip can differ and the choice survives a reload.

A single leg can override the day default: click the connector row between two entries and pick Driving, Walking, or any plugin profile for that leg alone, or Use day default to clear the override again. The same menu sits on the connectors to and from the day's accommodation and on the connector arriving after a transport booking, where it sets the mode of the leg arriving at that stop. Every connector shows the icon and the time of the mode its leg was actually drawn with.

When the trip has a start and an end date and you may edit the day, that menu also carries a Public transit entry. It opens the automated transit search (see Transport-Flights-Trains-Cars) already filled in with the leg's two endpoints and the departure time of the stop you are leaving.

Route segments reset at any transport reservation (flight, train, car, bus, or cruise) between two places — that leg is not driven or walked, so no ground route is drawn across it.

Counting routing requests

Admin: counting is on by default. To switch it off, set route_usage_enabled to false in the app_settings table of the database; there is no screen for it.

Every route is worked out in the browser against the routing host, so the server never sees a request of its own. The browser therefore tallies what it asks for and posts the totals in batches, and the instance keeps one row per day, routing profile and kind of request: how many requests, how many waypoints, roughly how many kilometres, how many came back without a route, and whether they went to the public hosts or to your own engine. Counters only: no coordinate, no route, no user and no trip are in them, and they never leave the instance.

Signed in as an admin, GET /api/route-usage/summary returns the totals, the requests per day, the busiest day, the split per profile and per kind of request, and the share answered by a self-hosted engine. DELETE /api/route-usage wipes the counters. Rows older than 400 days are deleted every night, whether counting is on or off.

Route display

  • Colored line segments connect consecutive places on the map.
  • Between each pair of consecutive places, a slim connector row in the day plan carries that leg's travel time and distance, with an icon for the mode it was routed in.
  • Plugins can attach time entries to the day plan (e.g. planned charging time at a stop, a security buffer before a flight). They appear as slim rows under the place or booking they belong to, and their minutes are added to the day's footer total as "+X min".

Optimize route

The Optimize button in the day's route tools reorders places in the current day to minimize total travel distance. A nearest-neighbor pass produces a good starting order, then a 2-opt pass untangles the crossings that pass leaves behind — both measure straight-line (Euclidean) distance.

With Optimize route from accommodation (Settings → General → Travel & map, on by default) the run is anchored on the day's hotel: a loop out from and back to it, or a hotel-to-hotel run on a transfer day. With the setting off, or on a day whose accommodation has no coordinates, it starts from the first place instead. A day with fewer than three places is left alone on desktop, and the mobile day sheet only offers the button from three up. The Optimize action in the plan screen's Plan mode has no such floor — two movable places with coordinates are enough, and with a hotel anchoring the run even those two can swap.

Only free places are reordered. A place keeps its slot if you locked it, or if it has a time set — a timed stop is anchored by its time. Those stops stay where they are and the reordered ones fill the gaps between them. On mobile there is no lock, so only a set time pins a stop.

The reorder can be undone immediately using the undo action that appears after it is applied.

Open the day in a map app

Two icon buttons in the day's route tools hand the current day to an external map app, both using its places in planned order, bookended by the day's accommodation exactly the way the drawn route is.

Open in Google Maps builds a https://www.google.com/maps/dir/lat,lng/lat,lng/… URL containing all stops in order and opens it in a new tab. A day with a single stop opens as a map search on that point instead.

Open in CoMaps (the compass icon beside it) hands the same day to CoMaps for offline navigation and carries the day's travel mode with it — the day's own default, or the current route profile when the day has none. A day of exactly two stops goes over as a real turn-by-turn route in that mode (walking as pedestrian, cycling as bicycle, everything else as vehicle). Any other day goes over as named pins, because CoMaps' route link takes a start and a destination and nothing between them, and handing over the whole day beats quietly dropping the middle of the plan. For the full itinerary as one navigable track, use the GPX export.

Both buttons are on mobile as well, in the day sheet.

Planning a whole drive

For a trip that is one long drive, the Road-Trip addon adds a Road trip view beside Days: the whole trip as one chain of legs with arrival times, daily travel times, driving limits, search along the route, via points and avoidance of toll roads, motorways and ferries.

See also: Day-Plans-and-Notes · Map-Features · Display-Settings · Road-Trip