diff options
| author | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-25 02:37:21 +0100 |
|---|---|---|
| committer | Ariel Costas Guerrero <ariel@costas.dev> | 2025-12-25 02:37:21 +0100 |
| commit | 0197a19973940d40a373b8aa68b2791391149cef (patch) | |
| tree | 36ac440484dabaebd8b17089c56f984e64601f45 /src/Costasdev.Busurbano.Backend/Controllers | |
| parent | 843cfb208849d652da16e943247057cf5a251254 (diff) | |
Implement selecting stop layers to display
Diffstat (limited to 'src/Costasdev.Busurbano.Backend/Controllers')
| -rw-r--r-- | src/Costasdev.Busurbano.Backend/Controllers/TileController.cs | 36 |
1 files changed, 31 insertions, 5 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 = []; |
