From df83274bed6b2a71f08fe24e4844b8dc268d2590 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Tue, 1 Sep 2026 14:49:44 +0000 Subject: [PATCH] fix: render isolated route acceleration and braking events --- lib/features/map/map_screen.dart | 53 +++++++++++++++++++++++++------- 1 file changed, 42 insertions(+), 11 deletions(-) diff --git a/lib/features/map/map_screen.dart b/lib/features/map/map_screen.dart index dd7916b..5288d1f 100644 --- a/lib/features/map/map_screen.dart +++ b/lib/features/map/map_screen.dart @@ -309,32 +309,63 @@ class _MapScreenState extends ConsumerState { required String idPrefix, required Color color, }) { + if (samples.isEmpty) return []; + + // A threshold crossing is often only one telemetry sample wide. Requiring + // two consecutive qualifying samples made isolated acceleration/braking + // events disappear from the map. Build event runs, then include one GPS + // sample on each side so every event renders as a visible route segment. final polylines = []; - List segment = []; + final eventIndices = []; + + for (var i = 0; i < samples.length; i++) { + final g = samples[i].longitudinalG ?? samples[i].accelX; + if (g != null && g.isFinite && predicate(g)) { + eventIndices.add(i); + } + } + if (eventIndices.isEmpty) return polylines; + + var runStart = eventIndices.first; + var runEnd = eventIndices.first; var segmentIndex = 0; - void flush() { - if (segment.length >= 2) { + void emitRun(int start, int end) { + final expandedStart = start > 0 ? start - 1 : start; + final expandedEnd = end < samples.length - 1 ? end + 1 : end; + final points = []; + for (var i = expandedStart; i <= expandedEnd; i++) { + final sample = samples[i]; + points.add(AppLatLng(sample.latitude!, sample.longitude!)); + } + + // The surrounding point guarantees two points for an isolated event + // while preserving a single continuous segment for adjacent events. + if (points.length >= 2) { polylines.add(AppPolyline( id: '${idPrefix}_$segmentIndex', - points: List.from(segment), + points: points, color: color, width: 7.0, )); segmentIndex++; } - segment = []; } - for (final sample in samples) { - final g = sample.longitudinalG ?? sample.accelX; - if (g != null && g.isFinite && predicate(g)) { - segment.add(AppLatLng(sample.latitude!, sample.longitude!)); + for (var i = 1; i < eventIndices.length; i++) { + final index = eventIndices[i]; + // Keep nearby threshold samples in one event run. A gap of more than + // two samples starts a new visual event while allowing brief sensor + // dropouts inside a hard maneuver. + if (index - runEnd <= 2) { + runEnd = index; } else { - flush(); + emitRun(runStart, runEnd); + runStart = runEnd = index; } } - flush(); + emitRun(runStart, runEnd); + return polylines; }