Skip to content

Latest commit

 

History

History
155 lines (112 loc) · 4.15 KB

routing.md

File metadata and controls

155 lines (112 loc) · 4.15 KB

Routing

Reverse-engineered route-building used by the public frontend.

GdeBenz builds driving routes between the user and a station. It uses a cascade of routing providers: a first-party /api/nav/route proxy, then an optional external OSRM/Valhalla fallback. A second endpoint /api/road-route proxies OSRM for road sheets.


/api/nav/route

GET /api/nav/route?from={lat},{lon}&to={lat},{lon}
  • Coordinates formatted with .toFixed(5).
  • Timeout: max(2200, round(0.6 * uv)) where uv = 7000 ms (default route timeout) → ~4200 ms.
  • Uses cache: "no-store".

Response

{
  "routes": [
    {
      "distance": 12345,
      "duration": 900,
      "geometry": { "coordinates": [[lon, lat], ...] },
      "legs": [ { "steps": [ ... ] } ]
    }
  ]
}

Each route is parsed by bv() into:

Field Meaning
dist distance (metres)
dur duration (seconds)
pts [lat, lon] pairs (coordinates flipped from GeoJSON [lon, lat])
man turn-by-turn maneuvers extracted from legs[].steps[]

kv() keeps the fastest route (routes[0]) and up to 3 alternatives within 125% of its distance and duration.

Validation

wv(route, from, to) accepts a route only if the first and last points are within 2 km (Ti() haversine) of the requested endpoints.

Circuit breaker

  • After 3 consecutive failures the route proxy is disabled for 5 minutes (3e5 ms, rv._pxDead).
  • HTTP 4xx responses reset the failure counter without disabling.
  • A 700 ms minimum interval is enforced between calls.

External fallback

When the proxy is unavailable, the client calls OSRM directly:

https://router.project-osrm.org/route/v1/driving/{lon},{lat}[;{via_lon},{via_lat}];{to_lon},{to_lat}
  ?overview=full&geometries=geojson&steps=true&alternatives={3|false}[&continue_straight=false]
  • With a via-point: alternatives=false&continue_straight=false.
  • Without: alternatives=3.

/api/road-route

GET /api/road-route?from={lat},{lon}&to={lat},{lon}
  • Coordinates rounded to 1/500 degree: Math.round(500 * x) / 500.
  • Timeout 7 s.
  • Only attempted when the direct distance ≤ 9 km.

Response (OSRM shape)

{
  "code": "Ok",
  "geometry": { "coordinates": [[lon, lat], ...] },
  "distance_km": 12,
  "duration_s": 900
}

Client processing:

  • code must equal "Ok" and geometry.coordinates must exist.
  • Coordinates flipped to [lat, lon]; route rejected if fewer than 10 points.
  • Cumulative distance computed with QI(); route rejected if total ≤ 4 km.
  • Produces a road object:
{
  slug: "osrm", name: "", divided: "none",
  len_km: Math.round(distance_km || totalKm),
  pts, _cum,
  milestones: [{ name: fromName || "Старт", km: 0 }],
  city_zones: [], route_names: null,
  _eta_s: duration_s || null,
  _osrm: 1
}

Circuit breakers

  • 404 → KI._osrmDead = 1 (permanently disabled for the session).
  • 5xx or 429 → cooldown for 60 s (KI._osrmCold).

If OSRM fails, the client falls back to a locally-computed highway route (cM() over KI.idx.highways), and shows "Между этими точками маршрут не строится" if none exists.


Alternative provider (Valhalla)

A secondary route builder posts to Valhalla:

POST https://valhalla1.openstreetmap.de/route
{
  "locations": [...],
  "costing": "auto",
  "costing_options": { "auto": { "use_tolls": false } },
  "directions_options": { "units": "kilometers" }
}

Toll avoidance is toggled by localStorage["gb_nav_notoll"] === "1".


Constants

Constant Value Meaning
uv 7000 ms default nav/route timeout
mv 5000 ms secondary timeout
fv 4000 ms tertiary timeout
endpoint tolerance 2 km wv() endpoint acceptance
alternatives window 125% kv() distance/duration ratio
route proxy cooldown 5 min after 3 failures
OSRM cooldown 60 s on 5xx/429

Notes

All information was obtained from the publicly distributed JavaScript bundle. No server-side source code or private implementation details are included.