Navigation: arrived 30 m from the end (banner, drive mode), navigating on past it (the reroute turns back); the next maneuver's lanes from 1 km or 45 s at the speed driven, in drive mode a cell under the maneuver over the map ("ahead" in the profile, shown only with something in it) with the next traffic signal; signals with no route: /api/road also routes 1.5 km straight on from the last fix and gives that way's signals, the nearest one in front shown. TODO: the CAN GNSS follow done (the LTE tracker a layer to switch on), any tracker point followable later
CI / check (push) Successful in 1m22s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-03 17:57:27 +01:00
1 parent ad975bcf62
commit a6158f4083
7 files changed
+110 -15

No files matched your search

+16 -7
View File
@@ -324,7 +324,8 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
instead of "the first maneuver ahead by km"; arrival at 30 m. Done: progress only forward — instead of "the first maneuver ahead by km"; arrival at 30 m. Done: progress only forward —
the position looked for near the last one first (`locate`, 0.1 km back to 3 km ahead), so a the position looked for near the last one first (`locate`, 0.1 km back to 3 km ahead), so a
route along the same road twice or crossing itself doesn't jump; the step still advances 5 m route along the same road twice or crossing itself doesn't jump; the step still advances 5 m
past the maneuver. Arrival still to do past the maneuver. Arrival: 30 m from the end "Arrived" (banner, drive mode), the navigation
goes on — driven past it, the reroute turns back to it
** [x] The navigation banner across the top (Dashboard widget, on by default): the next ** [x] The navigation banner across the top (Dashboard widget, on by default): the next
maneuver's arrow (Valhalla's maneuver type), distance and street, "then …" when the next one maneuver's arrow (Valhalla's maneuver type), distance and street, "then …" when the next one
follows within 300 m, its lanes from 1 km, the street being driven; `/api/route` maneuvers follows within 300 m, its lanes from 1 km, the street being driven; `/api/route` maneuvers
@@ -337,12 +338,20 @@ already reaches the home MQTT broker (`mqtt_ext`) from ESPHome nodes in `~/espho
mode's Menu, off by default mode's Menu, off by default
** [x] Lanes as SVG arrows, one per direction bit, the lanes to take (Valhalla's `active`) blue ** [x] Lanes as SVG arrows, one per direction bit, the lanes to take (Valhalla's `active`) blue
with that direction bold with that direction bold
*** [ ] Lane guidance before motorway exits (lanes several maneuvers ahead), bigger on the *** [x] Lane guidance before motorway exits (lanes several maneuvers ahead), bigger on the
driving screen driving screen. Done: the next maneuver's lanes from 1 km or 45 s at the speed driven, in drive
** [ ] Traffic signals with no route: around the position (Valhalla `locate` or the offline mode a cell under the maneuver (`ahead` in the profile), shown only when there's something
PBF), and only for the direction driven (`traffic_signals:direction`) ** [x] Traffic signals with no route: around the position (Valhalla `locate` or the offline
** [ ] The "Navigate" follow mode for the CAN GNSS position (today the MQTT tracker and the PBF), and only for the direction driven (`traffic_signals:direction`). Done: `/api/road` also routes
browser's GNSS control), the dashboard as part of the driving-mode UI 1.5 km straight on from the last fix (leaving in the direction driven) and gives that way's signals;
the nearest one in front shown (dashboard, drive mode's `ahead` cell up to 1 km). The
`:direction` tag not yet
** [x] The "Navigate" follow mode for the CAN GNSS position (today the MQTT tracker and the
browser's GNSS control), the dashboard as part of the driving-mode UI. Done: drive mode's Follow
follows the CAN GNSS; the LTE tracker (MQTT) is a tracker layer to switch on (a second car, the car
seen from home), Meshtastic the same with the nodes picked
*** [ ] Any point of a tracker layer can be the one the map follows — one at a time (picking
another one, or the car's own GNSS, takes it over); today only the MQTT tracker's card has "Navigate"
** [x] `locate()` scans the whole route each fix — a window around the last hit on long routes ** [x] `locate()` scans the whole route each fix — a window around the last hit on long routes
** [ ] Shared trip — one itinerary per server for every screen (the cab's display, the tablet ** [ ] Shared trip — one itinerary per server for every screen (the cab's display, the tablet
or display in the back, phones): the co-driver adds a stop, the driver's view reroutes on the or display in the back, phones): the co-driver adds a stop, the driver's view reroutes on the
+27 -1
View File
@@ -328,11 +328,37 @@ module Maptool
shape: points.map { |lon, lat| { lon: Float(lon), lat: Float(lat) } }, costing: "auto", shape_match: "map_snap", shape: points.map { |lon, lat| { lon: Float(lon), lat: Float(lat) } }, costing: "auto", shape_match: "map_snap",
filters: { attributes: %w[edge.names edge.road_class edge.speed_limit edge.surface], action: "include" }) filters: { attributes: %w[edge.names edge.road_class edge.speed_limit edge.surface], action: "include" })
edge = data["edges"]&.last or raise RouteError, "no road here" edge = data["edges"]&.last or raise RouteError, "no road here"
{ name: edge["names"]&.first, road_class: edge["road_class"], speed_limit: speed_limit(edge["speed_limit"]), surface: edge["surface"] }.compact { name: edge["names"]&.first, road_class: edge["road_class"], speed_limit: speed_limit(edge["speed_limit"]), surface: edge["surface"],
signals: signals_ahead(valhalla_url, points) }.compact
rescue ArgumentError, TypeError rescue ArgumentError, TypeError
raise RouteError, "invalid coordinates" raise RouteError, "invalid coordinates"
end end
AHEAD_KM = 1.5
# The traffic signals on the road ahead with no route: a route from the
# last fix, leaving in the direction driven, to AHEAD_KM straight on;
# [[lon, lat, km from the fix], ...], nil if that fails (it's extra).
# ponytail: "straight on" picks the way at a junction, a signal past a
# turn the driver then takes is missed until the next fix's lookup
def self.signals_ahead(valhalla_url, points)
(lon0, lat0), (lon, lat) = points.last(2).map { |p| p.map { |v| Float(v) } }
rad = Math::PI / 180
dx = (lon - lon0) * Math.cos(lat * rad)
dy = lat - lat0
return nil if dx.zero? && dy.zero?
heading = (Math.atan2(dx, dy) / rad) % 360
deg = AHEAD_KM / 111.32
to = { lon: lon + deg * Math.sin(heading * rad) / Math.cos(lat * rad), lat: lat + deg * Math.cos(heading * rad) }
data = valhalla(valhalla_url, "/route", locations: [{ lon: lon, lat: lat, heading: heading.round, heading_tolerance: 45 }, to],
costing: "auto", directions_type: "none")
along_route(valhalla_url, data.dig("trip", "legs"), "auto", {})&.dig(:signals)
rescue RouteError, Unavailable, Net::ReadTimeout, NoMethodError, TypeError, ArgumentError
nil
end
private_class_method :signals_ahead
ISOCHRONE_MAX_MINUTES = 240 # Valhalla's own default limit ISOCHRONE_MAX_MINUTES = 240 # Valhalla's own default limit
# How far the vehicle gets from [lon, lat] in each of `minutes`: a # How far the vehicle gets from [lon, lat] in each of `minutes`: a
+8
View File
@@ -3614,6 +3614,14 @@ html:not(.driving) .drive-cell { display: none; }
.drive-cell--limit { color: var(--sign-ring); } .drive-cell--limit { color: var(--sign-ring); }
.drive-cell--maneuver, .drive-cell--maneuver,
.drive-cell--compass { flex-direction: row; align-items: center; justify-content: flex-start; gap: 12px; } .drive-cell--compass { flex-direction: row; align-items: center; justify-content: flex-start; gap: 12px; }
/* under the maneuver, over the map: the lanes (bigger than the desktop's) and the next signal */
.drive-cell--ahead { position: relative; z-index: 2; align-self: start; height: var(--cell, 80px); flex-direction: row; align-items: center; justify-content: center; gap: calc(16px * var(--s, 1)); }
.drive-cell--ahead[hidden] { display: none; }
.drive-ahead__lanes svg.dash-lane { width: calc(40px * var(--s, 1)); height: calc(54px * var(--s, 1)); }
.drive-ahead__signal { display: flex; align-items: center; gap: 8px; font-size: calc(24px * var(--s, 1)); font-weight: 700; font-variant-numeric: tabular-nums; }
.drive-ahead__signal .dash-signal { width: calc(14px * var(--s, 1)); height: calc(36px * var(--s, 1)); background:
radial-gradient(circle at 50% 17%, #e53935 28%, transparent 31%), radial-gradient(circle at 50% 50%, #fbc02d 28%, transparent 31%),
radial-gradient(circle at 50% 83%, #43a047 28%, transparent 31%), #222; }
.drive-cell--maneuver .dash-banner__icon { width: calc(42px * var(--s, 1)); height: calc(56px * var(--s, 1)); } .drive-cell--maneuver .dash-banner__icon { width: calc(42px * var(--s, 1)); height: calc(56px * var(--s, 1)); }
.drive-status__brand { font-size: calc(14px * var(--s, 1)); letter-spacing: 0.12em; } .drive-status__brand { font-size: calc(14px * var(--s, 1)); letter-spacing: 0.12em; }
.drive-status--ok { color: var(--inst-ok); } .drive-status--ok { color: var(--inst-ok); }
+1
View File
@@ -13,6 +13,7 @@
{ "area": "1 / 11 / 2 / 13", "widget": "field", "value": "time" }, { "area": "1 / 11 / 2 / 13", "widget": "field", "value": "time" },
{ "area": "1 / 13 / 2 / 15", "widget": "field", "value": "sun" }, { "area": "1 / 13 / 2 / 15", "widget": "field", "value": "sun" },
{ "area": "1 / 15 / 2 / 17", "widget": "status" }, { "area": "1 / 15 / 2 / 17", "widget": "status" },
{ "area": "2 / 1 / 3 / 5", "widget": "ahead" },
{ "area": "2 / 14 / 3 / 17", "widget": "field", "value": "nextStop", "small": true }, { "area": "2 / 14 / 3 / 17", "widget": "field", "value": "nextStop", "small": true },
{ "area": "3 / 14 / 4 / 17", "widget": "field", "value": "toNextStop" }, { "area": "3 / 14 / 4 / 17", "widget": "field", "value": "toNextStop" },
{ "area": "4 / 14 / 5 / 17", "widget": "field", "value": "etaNextStop" }, { "area": "4 / 14 / 5 / 17", "widget": "field", "value": "etaNextStop" },
+31 -6
View File
@@ -36,7 +36,10 @@ const MAX_HDOP = 5; // ~ over 10 m off at the NEO-6M's few m UERE
const REROUTE_EVERY_MS = 15000; const REROUTE_EVERY_MS = 15000;
const ROAD_EVERY_MS = 4000; // /api/road at most this often, only while moving const ROAD_EVERY_MS = 4000; // /api/road at most this often, only while moving
const TRACE_STEP_M = 10; // fixes kept for /api/road at least this far apart const TRACE_STEP_M = 10; // fixes kept for /api/road at least this far apart
const LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close const LANES_AHEAD_M = 1000; // the next maneuver's lanes from this close (or LANES_AHEAD_S at the speed driven)
const LANES_AHEAD_S = 45;
const ARRIVE_M = 30; // this close to the end: arrived (navigation goes on: past it, the route turns back)
const ARRIVE_TYPES = [4, 5, 6]; // Valhalla's destination maneuvers
const DEFAULT_WIDGETS = { inclinometer: true, speed: true, altitude: true, navigation: true, banner: true }; const DEFAULT_WIDGETS = { inclinometer: true, speed: true, altitude: true, navigation: true, banner: true };
const THEN_M = 300; // the maneuver after the next one shown with it when it follows this closely const THEN_M = 300; // the maneuver after the next one shown with it when it follows this closely
// Voice prompts (speechSynthesis, Valhalla's verbal instructions), on/off in // Voice prompts (speechSynthesis, Valhalla's verbal instructions), on/off in
@@ -86,7 +89,7 @@ const LANE_ANGLES = { 2: 0, 16: -45, 8: -90, 4: -135, 32: 45, 64: 90, 128: 135,
const LANE_REVERSE = 256; const LANE_REVERSE = 256;
// One lane as an SVG: an arrow per direction it allows; `active` (the // One lane as an SVG: an arrow per direction it allows; `active` (the
// directions to take, a bitmask too) drawn bold. // directions to take, a bitmask too) drawn bold.
function laneSvg({ directions, active = 0 }) { export function laneSvg({ directions, active = 0 }) {
const arrow = (bit) => { const arrow = (bit) => {
const cls = `dash-lane__arrow${active & bit ? " dash-lane__take" : ""}`; const cls = `dash-lane__arrow${active & bit ? " dash-lane__take" : ""}`;
return bit === LANE_REVERSE ? uturnPath(cls) : arrowPath(LANE_ANGLES[bit], cls); return bit === LANE_REVERSE ? uturnPath(cls) : arrowPath(LANE_ANGLES[bit], cls);
@@ -236,6 +239,21 @@ export class DashboardControl {
notifyRouteProgress(km); notifyRouteProgress(km);
} }
// With no route: the nearest of /api/road's signals ahead that's still in
// front (within 90° of the heading), straight-line metres.
_signalAhead(position) {
const heading = this._heading()?.deg;
if (heading == null || !this._road?.signals?.length) return null;
const ahead = this._road.signals
.map(([lon, lat]) => {
const dx = (lon - position[0]) * Math.cos(position[1] * RAD), dy = lat - position[1];
const off = Math.abs((((Math.atan2(dx, dy) / RAD - heading) % 360) + 540) % 360 - 180);
return off < 90 ? meters(position, [lon, lat]) : null;
})
.filter((m) => m != null);
return ahead.length ? Math.min(...ahead) : null;
}
_speak(index, maneuver, m, speed) { _speak(index, maneuver, m, speed) {
let voiceOn = false; let voiceOn = false;
try { voiceOn = localStorage.getItem(VOICE_KEY) === "on"; } catch { /* private window */ } try { voiceOn = localStorage.getItem(VOICE_KEY) === "on"; } catch { /* private window */ }
@@ -283,12 +301,14 @@ export class DashboardControl {
maneuver: maneuver && { ...maneuver, m: (maneuver.at - at) * 1000 }, maneuver: maneuver && { ...maneuver, m: (maneuver.at - at) * 1000 },
then: maneuver && then && then.at - maneuver.at <= THEN_M / 1000 ? then : null, then: maneuver && then && then.at - maneuver.at <= THEN_M / 1000 ? then : null,
street: onStreet, street: onStreet,
arrived: ARRIVE_TYPES.includes(maneuvers.at(-1)?.type) && (!maneuver || (index === maneuvers.length - 1 && (maneuver.at - at) * 1000 <= ARRIVE_M)),
lanesM: Math.max(LANES_AHEAD_M, (speed ?? 0) * LANES_AHEAD_S),
}; };
if (maneuver && off <= ON_ROUTE_M) this._speak(index, maneuver, (maneuver.at - at) * 1000, speed ?? 0); if (maneuver && off <= ON_ROUTE_M) this._speak(index, maneuver, (maneuver.at - at) * 1000, speed ?? 0);
return; return;
} }
this._progress(null); this._progress(null);
this._nav = { limit: this._road?.speed_limit ?? null, offRoute: !!this._route, street: this._road?.name }; this._nav = { limit: this._road?.speed_limit ?? null, offRoute: !!this._route, street: this._road?.name, signal: this._signalAhead(position) };
if (this._route && (speed ?? 0) >= MOVING_MS && Date.now() - this._rerouteAt >= REROUTE_EVERY_MS) { if (this._route && (speed ?? 0) >= MOVING_MS && Date.now() - this._rerouteAt >= REROUTE_EVERY_MS) {
this._rerouteAt = Date.now(); this._rerouteAt = Date.now();
requestReroute(position, this._route.viaKm.filter((km) => km <= this._lastAt).length); requestReroute(position, this._route.viaKm.filter((km) => km <= this._lastAt).length);
@@ -502,7 +522,7 @@ export class DashboardControl {
if (n?.maneuver && !this._settings.widgets.banner) { if (n?.maneuver && !this._settings.widgets.banner) {
const { text, m, lanes } = n.maneuver; const { text, m, lanes } = n.maneuver;
rows.push(`<div class="dash-maneuver">${distance(m)} · ${esc(text)}</div>`); rows.push(`<div class="dash-maneuver">${distance(m)} · ${esc(text)}</div>`);
if (lanes && m <= LANES_AHEAD_M) { if (lanes && m <= (n.lanesM ?? LANES_AHEAD_M)) {
rows.push(`<div class="dash-lanes">${lanes.map(laneSvg).join("")}</div>`); rows.push(`<div class="dash-lanes">${lanes.map(laneSvg).join("")}</div>`);
} }
} }
@@ -514,14 +534,19 @@ export class DashboardControl {
// closely, its lanes from LANES_AHEAD_M, and the street being driven. // closely, its lanes from LANES_AHEAD_M, and the street being driven.
_renderBanner() { _renderBanner() {
const n = this._nav; const n = this._nav;
const show = this._settings.widgets.banner && !!n?.maneuver; const show = this._settings.widgets.banner && !!(n?.maneuver || n?.arrived);
this._banner.hidden = !show; this._banner.hidden = !show;
if (!show) return; if (!show) return;
this._banner.style.setProperty("--dash-alpha", Math.max(0.8, this._settings.opacity ?? DEFAULT_OPACITY)); this._banner.style.setProperty("--dash-alpha", Math.max(0.8, this._settings.opacity ?? DEFAULT_OPACITY));
if (n.arrived) {
this._banner.innerHTML = `<div class="dash-banner__main">${maneuverSvg(4)}<div><div class="dash-banner__distance">Arrived</div>` +
`<div class="dash-banner__street">${esc(n.street || "")}</div></div></div>`;
return;
}
const { m, type, street, text, exit, lanes } = n.maneuver; const { m, type, street, text, exit, lanes } = n.maneuver;
const what = street ? `${exit ? `${exit}. exit · ` : ""}${esc(street)}` : esc(text); const what = street ? `${exit ? `${exit}. exit · ` : ""}${esc(street)}` : esc(text);
const then = n.then ? `<div class="dash-banner__then">then ${maneuverSvg(n.then.type)} ${esc(n.then.street || n.then.text)}</div>` : ""; const then = n.then ? `<div class="dash-banner__then">then ${maneuverSvg(n.then.type)} ${esc(n.then.street || n.then.text)}</div>` : "";
const lanesRow = lanes && m <= LANES_AHEAD_M ? `<div class="dash-lanes dash-banner__lanes">${lanes.map(laneSvg).join("")}</div>` : ""; const lanesRow = lanes && m <= (n.lanesM ?? LANES_AHEAD_M) ? `<div class="dash-lanes dash-banner__lanes">${lanes.map(laneSvg).join("")}</div>` : "";
const onStreet = n.street ? `<div class="dash-banner__on">on ${esc(n.street)}</div>` : ""; const onStreet = n.street ? `<div class="dash-banner__on">on ${esc(n.street)}</div>` : "";
this._banner.innerHTML = `<div class="dash-banner__main">${maneuverSvg(type)}<div><div class="dash-banner__distance">${distance(m)}</div>` + this._banner.innerHTML = `<div class="dash-banner__main">${maneuverSvg(type)}<div><div class="dash-banner__distance">${distance(m)}</div>` +
`<div class="dash-banner__street">${what}</div></div></div>${lanesRow}${then}${onStreet}`; `<div class="dash-banner__street">${what}</div></div></div>${lanesRow}${then}${onStreet}`;
+16 -1
View File
@@ -3,7 +3,7 @@ import { requestGnssFollow, onRouteChanged } from "/js/panels.js";
import { pauseFollow, resumeFollow, isFollowing } from "/js/gnss.js"; import { pauseFollow, resumeFollow, isFollowing } from "/js/gnss.js";
import { formatDuration } from "/js/route.js"; import { formatDuration } from "/js/route.js";
import { isLoggedIn } from "/js/auth.js"; import { isLoggedIn } from "/js/auth.js";
import { watchDashboard, maneuverSvg, distance, VOICE_KEY } from "/js/dashboard.js"; import { watchDashboard, maneuverSvg, laneSvg, distance, VOICE_KEY } from "/js/dashboard.js";
import { formatSunInfo } from "/js/sun.js"; import { formatSunInfo } from "/js/sun.js";
import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js"; import { pointsMenu, layersMenu, terrainMenu, elevationHtml, cellButton, bindKey, emptyRow as empty, escapeHtml } from "/js/drive_menus.js";
@@ -467,10 +467,24 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
} }
}; };
// Under the maneuver, over the map, only when there's something: the next
// maneuver's lanes (from 1 km, further at speed) and the next traffic signal.
const renderAhead = (el) => {
const n = dash?.nav;
const lanes = !n?.arrived && n?.maneuver?.lanes && n.maneuver.m <= n.lanesM ? n.maneuver.lanes : null;
const signal = n?.signal != null && n.signal <= 1000 ? n.signal : null;
el.hidden = !lanes && signal == null;
if (el.hidden) return;
el.innerHTML = (lanes ? `<div class="dash-lanes drive-ahead__lanes">${lanes.map(laneSvg).join("")}</div>` : "") +
(signal != null ? `<span class="drive-ahead__signal"><span class="dash-signal"></span>${distance(signal)}</span>` : "");
};
const renderManeuver = (el) => { const renderManeuver = (el) => {
const n = dash?.nav; const n = dash?.nav;
if (n?.offRoute) { if (n?.offRoute) {
el.innerHTML = `<div><span class="drive-cell__value drive-cell--caution">Off the route</span><span class="drive-cell__label">rerouting</span></div>`; el.innerHTML = `<div><span class="drive-cell__value drive-cell--caution">Off the route</span><span class="drive-cell__label">rerouting</span></div>`;
} else if (n?.arrived) {
el.innerHTML = `${maneuverSvg(4)}<div class="drive-cell__text"><span class="drive-cell__value">Arrived</span><span class="drive-cell__street">${escapeHtml(n.street || "")}</span></div>`;
} else if (n?.maneuver) { } else if (n?.maneuver) {
const { m, type, street, text, exit } = n.maneuver; const { m, type, street, text, exit } = n.maneuver;
const what = street ? `${exit ? `${exit}. exit · ` : ""}${escapeHtml(street)}` : escapeHtml(text); const what = street ? `${exit ? `${exit}. exit · ` : ""}${escapeHtml(street)}` : escapeHtml(text);
@@ -515,6 +529,7 @@ export function setupDriving(map, nightButton, routePanel, gpxPanel) {
const [value, unit, cls = "", extra = ""] = fieldValue(name, a); const [value, unit, cls = "", extra = ""] = fieldValue(name, a);
el.innerHTML = `${extra}<span class="drive-cell__label">${FIELDS[name] || name}</span><span class="drive-cell__value ${cls}">${escapeHtml(value)} <small>${escapeHtml(unit)}</small></span>`; el.innerHTML = `${extra}<span class="drive-cell__label">${FIELDS[name] || name}</span><span class="drive-cell__value ${cls}">${escapeHtml(value)} <small>${escapeHtml(unit)}</small></span>`;
} else if (cell.widget === "maneuver") renderManeuver(el); } else if (cell.widget === "maneuver") renderManeuver(el);
else if (cell.widget === "ahead") renderAhead(el);
else if (cell.widget === "status") { else if (cell.widget === "status") {
el.innerHTML = `<b class="drive-status__brand">MAPTOOL</b><span class="drive-cell__muted"><span class="${navigator.onLine ? "drive-status--ok" : ""}">●</span> ${navigator.onLine ? "online" : "offline"}${log?.active ? ` · <span class="drive-status--rec">● rec</span>` : ""}</span>`; el.innerHTML = `<b class="drive-status__brand">MAPTOOL</b><span class="drive-cell__muted"><span class="${navigator.onLine ? "drive-status--ok" : ""}">●</span> ${navigator.onLine ? "online" : "offline"}${log?.active ? ` · <span class="drive-status--rec">● rec</span>` : ""}</span>`;
} else if (cell.widget === "elevation") renderElevation(el, cell); } else if (cell.widget === "elevation") renderElevation(el, cell);
+11
View File
@@ -170,6 +170,17 @@ class RoutingTest < Minitest::Test
assert_raises(Maptool::Routing::RouteError) { Maptool::Routing.road("http://x", [[17.1, 48.1]]) } assert_raises(Maptool::Routing::RouteError) { Maptool::Routing.road("http://x", [[17.1, 48.1]]) }
end end
def test_the_road_gives_the_signals_ahead_from_a_route_straight_on
http = ->(body) { "HTTP/1.1 200 OK\r\nContent-Length: #{body.bytesize}\r\n\r\n#{body}" }
road = JSON.generate(edges: [{ names: ["B"], road_class: "primary" }])
route = JSON.generate(trip: { legs: [{ shape: "wdg|xA{ubdQc@w@" }] })
along = JSON.generate(admins: [{ country_code: "SK" }], edges: [{ length: 0.4, end_shape_index: 1, end_node: { traffic_signal: true, admin_index: 0 } }])
request = serve_once(http[road], http[route], http[along]) do |url|
assert_equal [0.4], Maptool::Routing.road(url, [[17.1, 48.1], [17.1, 48.2]])[:signals].map(&:last)
end
assert_includes request, %("heading":0,"heading_tolerance":45)
end
def test_bicycle_and_foot_use_their_own_costing_without_the_country_lookup def test_bicycle_and_foot_use_their_own_costing_without_the_country_lookup
reply = JSON.generate(trip: { summary: { length: 1.5, time: 90 }, legs: [{ shape: "wdg|xA{ubdQc@w@", maneuvers: [] }] }) reply = JSON.generate(trip: { summary: { length: 1.5, time: 90 }, legs: [{ shape: "wdg|xA{ubdQc@w@", maneuvers: [] }] })
request = serve_once("HTTP/1.1 200 OK\r\nContent-Length: #{reply.bytesize}\r\n\r\n#{reply}") do |url| request = serve_once("HTTP/1.1 200 OK\r\nContent-Length: #{reply.bytesize}\r\n\r\n#{reply}") do |url|