From 4a866f5352a51916ddb9849b2d68213856196c9c Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Tue, 23 Dec 2025 21:33:17 +0100 Subject: Full real-time page, coruña real time MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Services/Processors/ShapeProcessor.cs | 37 +++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) (limited to 'src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs') diff --git a/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs b/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs index 300ce70..93e4a4f 100644 --- a/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs +++ b/src/Costasdev.Busurbano.Backend/Services/Processors/ShapeProcessor.cs @@ -20,6 +20,9 @@ public class ShapeProcessor : IArrivalsProcessor foreach (var arrival in context.Arrivals) { + // If shape is already populated (e.g. by VitrasaRealTimeProcessor), skip + if (arrival.Shape != null) continue; + if (arrival.RawOtpTrip is not ArrivalsAtStopResponse.Arrival otpArrival) continue; var encodedPoints = otpArrival.Trip.Geometry?.Points; @@ -34,14 +37,46 @@ public class ShapeProcessor : IArrivalsProcessor var points = Decode(encodedPoints); if (points.Count == 0) continue; - arrival.Shape = new + var features = new List(); + + // Route LineString + features.Add(new { type = "Feature", geometry = new { type = "LineString", coordinates = points.Select(p => new[] { p.Lon, p.Lat }).ToList() + }, + properties = new { type = "route" } + }); + + // Stops + if (otpArrival.Trip.Stoptimes != null) + { + foreach (var stoptime in otpArrival.Trip.Stoptimes) + { + features.Add(new + { + type = "Feature", + geometry = new + { + type = "Point", + coordinates = new[] { stoptime.Stop.Lon, stoptime.Stop.Lat } + }, + properties = new + { + type = "stop", + name = stoptime.Stop.Name + } + }); } + } + + arrival.Shape = new + { + type = "FeatureCollection", + features = features }; } catch (Exception ex) -- cgit v1.3