aboutsummaryrefslogtreecommitdiff
path: root/src/Costasdev.Busurbano.Backend
diff options
context:
space:
mode:
authorAriel Costas Guerrero <ariel@costas.dev>2025-12-25 02:37:21 +0100
committerAriel Costas Guerrero <ariel@costas.dev>2025-12-25 02:37:21 +0100
commit0197a19973940d40a373b8aa68b2791391149cef (patch)
tree36ac440484dabaebd8b17089c56f984e64601f45 /src/Costasdev.Busurbano.Backend
parent843cfb208849d652da16e943247057cf5a251254 (diff)
Implement selecting stop layers to display
Diffstat (limited to 'src/Costasdev.Busurbano.Backend')
-rw-r--r--src/Costasdev.Busurbano.Backend/Controllers/TileController.cs36
-rw-r--r--src/Costasdev.Busurbano.Backend/Services/FeedService.cs2
2 files changed, 32 insertions, 6 deletions
diff --git a/src/Costasdev.Busurbano.Backend/Controllers/TileController.cs b/src/Costasdev.Busurbano.Backend/Controllers/TileController.cs
index f3fe51c..52d919f 100644
--- a/src/Costasdev.Busurbano.Backend/Controllers/TileController.cs
+++ b/src/Costasdev.Busurbano.Backend/Controllers/TileController.cs
@@ -84,7 +84,7 @@ public class TileController : ControllerBase
var tileDef = new NetTopologySuite.IO.VectorTiles.Tiles.Tile(x, y, z);
VectorTile vt = new() { TileId = tileDef.Id };
- var lyr = new Layer { Name = "stops" };
+ var stopsLayer = new Layer { Name = "stops" };
responseBody.Data?.StopsByBbox?.ForEach(stop =>
{
@@ -108,12 +108,13 @@ public class TileController : ControllerBase
{
// The ID will be used to request the arrivals
{ "id", stop.GtfsId },
- // The feed is the first part of the GTFS ID, corresponding to the feed where the info comes from, used for icons probably
+ // The feed is the first part of the GTFS ID
{ "feed", idParts[0] },
// The public identifier, usually feed:code or feed:id, recognisable by users and in other systems
{ "code", $"{idParts[0]}:{codeWithinFeed}" },
- // The name of the stop
{ "name", _feedService.NormalizeStopName(feedId, stop.Name) },
+ { "icon", GetIconNameForFeed(feedId) },
+ { "transitKind", GetTransitKind(feedId) },
// Routes
{ "routes", JsonSerializer
.Serialize(
@@ -146,10 +147,10 @@ public class TileController : ControllerBase
}
};
- lyr.Features.Add(feature);
+ stopsLayer.Features.Add(feature);
});
- vt.Layers.Add(lyr);
+ vt.Layers.Add(stopsLayer);
using var ms = new MemoryStream();
vt.Write(ms, minLinealExtent: 1, minPolygonalExtent: 2);
@@ -160,6 +161,31 @@ public class TileController : ControllerBase
return File(ms.ToArray(), "application/x-protobuf");
}
+ private string GetIconNameForFeed(string feedId)
+ {
+ return feedId switch
+ {
+ "vitrasa" => "stop-vitrasa",
+ "santiago" => "stop-santiago",
+ "coruna" => "stop-coruna",
+ "xunta" => "stop-xunta",
+ "renfe" => "stop-renfe",
+ "feve" => "stop-feve",
+ _ => "stop-generic",
+ };
+ }
+
+ private string GetTransitKind(string feedId)
+ {
+ return feedId switch
+ {
+ "vitrasa" or "santiago" or "coruna" => "bus",
+ "xunta" => "coach",
+ "renfe" or "feve" => "train",
+ _ => "unknown",
+ };
+ }
+
private List<StopTileResponse.Route> GetDistinctRoutes(string feedId, List<StopTileResponse.Route> routes)
{
List<StopTileResponse.Route> distinctRoutes = [];
diff --git a/src/Costasdev.Busurbano.Backend/Services/FeedService.cs b/src/Costasdev.Busurbano.Backend/Services/FeedService.cs
index 6cebcf2..a8710b5 100644
--- a/src/Costasdev.Busurbano.Backend/Services/FeedService.cs
+++ b/src/Costasdev.Busurbano.Backend/Services/FeedService.cs
@@ -37,7 +37,7 @@ public class FeedService
{
return feed switch
{
- "vitrasa" => ("#95D516", "#000000"),
+ "vitrasa" => ("#81D002", "#000000"),
"santiago" => ("#508096", "#FFFFFF"),
"coruna" => ("#E61C29", "#FFFFFF"),
"xunta" => ("#007BC4", "#FFFFFF"),