Driving mode ("Drive": big buttons — follow, zoom, 2D/3D, night, route overview — the sidebar hidden); palettes instead of the inversion (the UI's greys onto --ui-*, MapLibre's controls too, night → Night, new ◑ Dusk); the navigated route magenta, the driven part dimmed; route progress only forward (locate near the last position first); rerouting on the server off its own GNSS (TripStore#follow), the browser's only without the shared trip; the overview map hidden while following in 3D; the topbar's items apart
This commit is contained in:
1 parent
12b4ac6725
commit
07a4d363ec
13 files changed
+520
-219
No files matched your search
@@ -25,6 +25,67 @@ module Maptool
|
||||
@mutex.synchronize { @trip.dup }
|
||||
end
|
||||
|
||||
ON_ROUTE_M = 30 # as the dashboard's
|
||||
OFF_ROUTE_FIXES = 3
|
||||
MAX_HDOP = 5
|
||||
MIN_SPEED = 1.5 # m/s: standing next to the route isn't a detour
|
||||
REROUTE_EVERY_S = 15
|
||||
|
||||
# Every GNSS fix (App.gnss_update): off the trip's route for
|
||||
# OFF_ROUTE_FIXES fixes while driving, routes again from here to the
|
||||
# points not reached yet — on the server, so it happens with no screen
|
||||
# open; the screens pick the new version up by polling. The block routes
|
||||
# (as #update's). In a thread of its own: CAN's reader doesn't wait.
|
||||
def follow(position, speed:, hdop: nil, now: Time.now.to_f, &router)
|
||||
trip = get
|
||||
route = trip[:route]
|
||||
return unless route && trip[:points].size >= 2
|
||||
|
||||
at, off = self.class.locate(route[:geometry][:coordinates], position)
|
||||
if off <= ON_ROUTE_M
|
||||
@off_fixes = 0
|
||||
@last_at = at
|
||||
return
|
||||
end
|
||||
return if (hdop || 0) > MAX_HDOP
|
||||
|
||||
@off_fixes = (@off_fixes || 0) + 1
|
||||
return if @off_fixes < OFF_ROUTE_FIXES || speed.to_f < MIN_SPEED || (@reroute_at && now - @reroute_at < REROUTE_EVERY_S) || @rerouting
|
||||
|
||||
@reroute_at = now
|
||||
@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)
|
||||
Thread.new do
|
||||
update(points: points, vehicle: trip[:vehicle], avoid: trip[:avoid], editing: trip[:editing], &router)
|
||||
rescue StandardError => e
|
||||
warn "trip reroute: #{e.message}"
|
||||
ensure
|
||||
@rerouting = false
|
||||
@off_fixes = 0
|
||||
end
|
||||
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)
|
||||
along = 0.0
|
||||
best = [0.0, Float::INFINITY]
|
||||
coords.each_cons(2) do |(ax, ay), (bx, by)|
|
||||
ax *= cos
|
||||
bx *= cos
|
||||
px = lon * cos
|
||||
len2 = (bx - ax)**2 + (by - ay)**2
|
||||
t = len2.zero? ? 0.0 : (((px - ax) * (bx - ax) + (lat - ay) * (by - ay)) / len2).clamp(0.0, 1.0)
|
||||
off = Math.hypot(px - (ax + t * (bx - ax)), lat - (ay + t * (by - ay))) * 111_320
|
||||
length = Math.sqrt(len2) * 111.32
|
||||
best = [along + t * length, off] if off < best[1]
|
||||
along += length
|
||||
end
|
||||
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
|
||||
|
||||
Reference in new issue
Block a user