diff --git a/Pathfinding/PathNode.cs b/Pathfinding/PathNode.cs index 9d8ef44..66f2d31 100644 --- a/Pathfinding/PathNode.cs +++ b/Pathfinding/PathNode.cs @@ -1,4 +1,5 @@ using System.Text.Json.Serialization; +using OSMDatastructure; using OSMDatastructure.Graph; namespace Pathfinding; @@ -8,7 +9,8 @@ public class PathNode : OsmNode [JsonInclude]public new double currentPathWeight = double.MaxValue; [JsonInclude]public new double currentPathLength = double.MaxValue; [JsonInclude]public new double directDistanceToGoal = double.MaxValue; - + [JsonInclude]public Dictionary tags = new(); + public PathNode(ulong nodeId, float lat, float lon) : base(nodeId, lat, lon) { } @@ -17,7 +19,7 @@ public class PathNode : OsmNode { } - public static PathNode? FromOsmNode(OsmNode? node) + public static PathNode? FromOsmNode(OsmNode? node, HashSet? tags) { if (node is null) return null; @@ -27,6 +29,12 @@ public class PathNode : OsmNode currentPathWeight = double.IsPositiveInfinity(node.currentPathWeight) ? double.MaxValue : node.currentPathWeight, directDistanceToGoal = node.directDistanceToGoal }; + if (tags != null) + foreach (Tag tag in tags) + { + retNode.tags.Add(tag.key.ToString(), tag.value.ToString()); + } + return retNode; } } \ No newline at end of file diff --git a/Pathfinding/Pathfinder.cs b/Pathfinding/Pathfinder.cs index 7350f1b..d0758ea 100644 --- a/Pathfinding/Pathfinder.cs +++ b/Pathfinding/Pathfinder.cs @@ -30,4 +30,27 @@ public static partial class Pathfinder return double.MaxValue; return distance / speed; } + + private static List GetRouteFromCalc(OsmNode goalNode, RegionManager regionManager) + { + List path = new(); + OsmNode? currentNode = goalNode; + while (currentNode is not null) + { + HashSet? tags = null; + if (currentNode.previousPathNode is not null) + { + OsmEdge edge = currentNode.previousPathNode!.edges.First(e => e.neighborId.Equals(currentNode.nodeId)); + tags = regionManager.GetRegion(currentNode.coordinates)!.tagManager.GetTagsForWayId(edge.wayId); + } + + currentNode = currentNode.previousPathNode; + PathNode? pn = PathNode.FromOsmNode(currentNode, tags); + if(pn is not null) + path.Add(pn!); + } + + path.Reverse(); + return path; + } } \ No newline at end of file diff --git a/Pathfinding/Pathfinder_Distance.cs b/Pathfinding/Pathfinder_Distance.cs index 485dfeb..a747828 100644 --- a/Pathfinding/Pathfinder_Distance.cs +++ b/Pathfinding/Pathfinder_Distance.cs @@ -46,16 +46,6 @@ public static partial class Pathfinder } } } - - List path = new(); - OsmNode? currentNode = goalNode; - while (currentNode is not null) - { - path.Add(PathNode.FromOsmNode(currentNode)!); - currentNode = currentNode.previousPathNode; - } - path.Reverse(); - - return path; + return GetRouteFromCalc(goalNode, regionManager); } } \ No newline at end of file diff --git a/Pathfinding/Pathfinder_Time.cs b/Pathfinding/Pathfinder_Time.cs index 956c0ce..bd06080 100644 --- a/Pathfinding/Pathfinder_Time.cs +++ b/Pathfinding/Pathfinder_Time.cs @@ -50,16 +50,6 @@ public static partial class Pathfinder } } } - - List path = new(); - OsmNode? currentNode = goalNode; - while (currentNode is not null) - { - path.Add(PathNode.FromOsmNode(currentNode)!); - currentNode = currentNode.previousPathNode; - } - path.Reverse(); - - return path; + return GetRouteFromCalc(goalNode, regionManager); } } \ No newline at end of file