Driving menu Trip: the stops as big rows (look, ✓ passed, ↑ ↓, ✕), a stop at the crosshair, the start at the car, search of saved points and offline places; each leg's km and time (legs_s) and the total, in the route panel too; passed stops kept (not routed, dimmed, editable) — a reroute marks them instead of dropping them; /status.html: every status endpoint full width (the debug panel links it); the trip-as-plan-and-log model and planned-vs-driven colors in docs/TODO
CI / check (push) Successful in 22s
CI / deploy (push) Successful in 17s

This commit is contained in:
randy committed 2026-12-01 02:21:14 +01:00
1 parent 0eb9d05cdc
commit 809e88ab1a
14 files changed
+517 -101

No files matched your search

+24 -10
View File
@@ -39,7 +39,7 @@ module Maptool
def follow(position, speed:, hdop: nil, now: Time.now.to_f, &router)
trip = get
route = trip[:route]
return unless route && trip[:points].size >= 2
return unless route && trip[:points].count { |p| !p[:passed] } >= 2
at, off = self.class.locate(route[:geometry][:coordinates], position)
if off <= ON_ROUTE_M
@@ -56,7 +56,7 @@ module Maptool
@rerouting = true
leg = 0
passed = (route[:properties][:legs_km] || [])[0...-1].map { |km| leg += km }.count { |km| km <= (@last_at || 0) }
points = [{ lngLat: position, name: "My position", nav: false }] + trip[:points].drop(1 + passed)
points = self.class.passed_on(trip[:points], passed, position)
Thread.new do
update(points: points, vehicle: trip[:vehicle], avoid: trip[:avoid], editing: trip[:editing], &router)
rescue StandardError => e
@@ -67,6 +67,17 @@ module Maptool
end
end
# The points after a detour: the start and the `passed` vias reached so
# far marked passed (the start dropped if it was an earlier "My
# position", not a stop), then the position as the new start, then the rest.
def self.passed_on(points, passed, position)
done, ahead = points.partition { |p| p[:passed] }
ahead = ahead.dup
reached = ahead.shift(1 + passed)
reached.shift if reached.first&.dig(:name) == "My position"
done + reached.map { |p| p.merge(passed: true) } + [{ lngLat: position, name: "My position", nav: false, passed: false }] + ahead
end
# Nearest point on the line ([[lon, lat], ...]): [km along it, meters off it].
def self.locate(coords, (lon, lat))
cos = Math.cos(lat * Math::PI / 180)
@@ -86,21 +97,24 @@ module Maptool
best
end
# points: [{ lngLat: [lon, lat], name:, nav: }]. Routes through them with
# the block (locations, vehicle id, avoid → the /api/route Feature, may
# raise Routing errors) unless only names/nav changed — the old route
# stays then. Last write wins.
# points: [{ lngLat: [lon, lat], name:, nav:, passed: }]. Routes through
# the ones not passed with the block (locations, vehicle id, avoid → the
# /api/route Feature, may raise Routing errors) unless only names/nav
# changed — the old route stays then. Passed points stay in the trip
# (shown dimmed, still editable: a stop missed out added afterwards),
# just not routed. Last write wins.
def update(points:, vehicle:, avoid:, editing:)
points = points.map { |p| { lngLat: p.fetch(:lngLat).map { |v| Float(v) }, name: p[:name], nav: !!p[:nav] } }
points = points.map { |p| { lngLat: p.fetch(:lngLat).map { |v| Float(v) }, name: p[:name], nav: !!p[:nav], passed: !!p[:passed] } }
avoid = (avoid || {}).to_h { |k, v| [k.to_sym, !!v] }
before = get
same_route = before[:points].map { |p| p[:lngLat] } == points.map { |p| p[:lngLat] } &&
routed = ->(list) { list.reject { |p| p[:passed] }.map { |p| p[:lngLat] } }
same_route = routed.(before[:points]) == routed.(points) &&
before[:vehicle] == vehicle && before[:avoid] == avoid && !before[:error]
route, error = if same_route then [before[:route], nil]
elsif points.size < 2 then [nil, nil]
elsif routed.(points).size < 2 then [nil, nil]
else
begin
[yield(points.map { |p| p[:lngLat] }, vehicle, avoid), nil]
[yield(routed.(points), vehicle, avoid), nil]
rescue Routing::RouteError, Routing::Unavailable => e
[nil, e.message]
end