74 lines
2.3 KiB
C#
74 lines
2.3 KiB
C#
using System.Text;
|
|
using System.Text.Json.Serialization;
|
|
using OSMDatastructure;
|
|
using OSMDatastructure.Graph;
|
|
using Pathfinding;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
// Add services to the container.
|
|
|
|
builder.Services.AddControllers();
|
|
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
|
builder.Services.AddEndpointsApiExplorer();
|
|
builder.Services.AddSwaggerGen();
|
|
|
|
var app = builder.Build();
|
|
|
|
app.MapGet("/getRouteDistance", (float latStart, float lonStart, float latEnd, float lonEnd) =>
|
|
{
|
|
DateTime startCalc = DateTime.Now;
|
|
List<PathNode> result = Pathfinder.AStarDistance("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd));
|
|
PathResult pathResult = new PathResult(DateTime.Now - startCalc, result);
|
|
return pathResult;
|
|
}
|
|
);
|
|
|
|
app.MapGet("/getRouteTime", (float latStart, float lonStart, float latEnd, float lonEnd, Tag.SpeedType vehicle) =>
|
|
{
|
|
DateTime startCalc = DateTime.Now;
|
|
List<PathNode> result = Pathfinder.AStarTime("D:/stuttgart-regbez-latest", new Coordinates(latStart, lonStart), new Coordinates(latEnd, lonEnd), vehicle);
|
|
PathResult pathResult = new PathResult(DateTime.Now - startCalc, result);
|
|
return pathResult;
|
|
}
|
|
);
|
|
|
|
app.MapGet("/getClosestNode", (float lat, float lon) =>
|
|
{
|
|
RegionManager regionManager = new RegionManager("D:/stuttgart-regbez-latest");
|
|
return regionManager.ClosestNodeToCoordinates(new Coordinates(lat, lon), Tag.SpeedType.any);
|
|
});
|
|
|
|
// Configure the HTTP request pipeline.
|
|
if (app.Environment.IsDevelopment())
|
|
{
|
|
app.UseSwagger();
|
|
app.UseSwaggerUI();
|
|
}
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|
|
|
|
internal class PathResult
|
|
{
|
|
[JsonInclude]public TimeSpan calcTime;
|
|
[JsonInclude] public double pathWeight = double.MaxValue;
|
|
[JsonInclude] public double pathTravelDistance = double.MaxValue;
|
|
[JsonInclude]public List<PathNode> pathNodes;
|
|
|
|
public PathResult(TimeSpan calcTime, List<PathNode> pathNodes)
|
|
{
|
|
this.calcTime = calcTime;
|
|
this.pathNodes = pathNodes;
|
|
if (pathNodes.Count > 0)
|
|
{
|
|
this.pathWeight = pathNodes.Last().currentPathWeight;
|
|
this.pathTravelDistance = pathNodes.First().currentPathLength;
|
|
}
|
|
}
|
|
} |