public static string AgentPath(MapAgentPath path, bool addBoundingBoxex = true) { var result = new GeoJsonMultiLine(); for(int i = 0; i < path.Points.Count - 2; i++) { var p0 = path.Points[i]; var p1 = path.Points[i + 1]; var segment = new List<List<double>> { new List<double> { p0.Lon, p0.Lat }, new List<double> { p1.Lon, p1.Lat } }; result.Coordinates.Add(segment); } if (addBoundingBoxex) { foreach (var tileId in path.TileIds) { var bbox = new List<List<double>>(); var (lon0, lat0, lon1, lat1) = TileMath.GetTileBounds(tileId, WorldGraph.Zoom); bbox.Add(new List<double> { lon0, lat0 }); bbox.Add(new List<double> { lon1, lat0 }); bbox.Add(new List<double> { lon1, lat1 }); bbox.Add(new List<double> { lon0, lat1 }); bbox.Add(new List<double> { lon0, lat0 }); result.Coordinates.Add(bbox); } } return JsonSerializer.Serialize(result, SerializerOptions); }
public static string Segments(List<GeoCoord> segments) { var result = new GeoJsonMultiLine(); for (int i = 0; i < segments.Count; i += 2) { var p0 = segments[i]; var p1 = segments[i + 1]; var segment = new List<List<double>> { new List<double> { p0.Lon, p0.Lat }, new List<double> { p1.Lon, p1.Lat } }; result.Coordinates.Add(segment); } return JsonSerializer.Serialize(result, SerializerOptions); }