aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend/Controllers
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-11-21 10:53:03 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-11-21 10:53:03 +0100
commit7061660e7d475fe3ed016858a49a0c9b7ba10c18 (patch)
tree3b27e96d7a6d2148ab7cccc3785e3c000342a796 /src/Costasdev.Busurbano.Backend/Controllers
parent4fcf9ad479441e7661933b954cc878355bde1e5d (diff)
Show path from bus position to terminus
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Controllers')
-rw-r--r--src/Costasdev.Busurbano.Backend/Controllers/VigoController.cs34
1 files changed, 34 insertions, 0 deletions
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<IActionResult> 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<IActionResult> 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
});