From 7061660e7d475fe3ed016858a49a0c9b7ba10c18 Mon Sep 17 00:00:00 2001 From: Ariel Costas Guerrero Date: Fri, 21 Nov 2025 10:53:03 +0100 Subject: Show path from bus position to terminus --- .../Controllers/VigoController.cs | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'src/Costasdev.Busurbano.Backend/Controllers') diff --git a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs index 6423c2f..f1f5f4a 100644 --- a/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs +++ b/src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs @@ -46,6 +46,38 @@ public class VigoController : ControllerBase } } + [HttpGet("GetShape")] + public async Task GetShape( + [FromQuery] string shapeId, + [FromQuery] int startPointIndex = 0 + ) + { + // Include a significant number of previous points to ensure continuity and context + // Backtrack 50 points to cover any potential gaps or dense point sequences + var adjustedStartIndex = Math.Max(0, startPointIndex - 50); + var path = await _shapeService.GetShapePathAsync(shapeId, adjustedStartIndex); + if (path == null) + { + return NotFound(); + } + + // Convert to GeoJSON LineString + var coordinates = path.Select(p => new[] { p.Longitude, p.Latitude }).ToList(); + + var geoJson = new + { + type = "Feature", + geometry = new + { + type = "LineString", + coordinates = coordinates + }, + properties = new { } + }; + + return Ok(geoJson); + } + [HttpGet("GetStopTimetable")] public async Task GetStopTimetable( [FromQuery] int stopId, @@ -278,6 +310,7 @@ public class VigoController : ControllerBase Minutes = (int)(closestCirculation.CallingDateTime()!.Value - now).TotalMinutes, TripId = closestCirculation.TripId, ServiceId = closestCirculation.ServiceId, + ShapeId = closestCirculation.ShapeId, }, RealTime = new RealTimeData { @@ -316,6 +349,7 @@ public class VigoController : ControllerBase Minutes = (int)(sched.CallingDateTime()!.Value - now).TotalMinutes, TripId = sched.TripId, ServiceId = sched.ServiceId, + ShapeId = sched.ShapeId, }, RealTime = null }); -- cgit v1.3