public IActionResult GetRoute(double startLAT, double startLON, double endLAT, double endLON, [FromRoute] string method) { List <double[]> lst = new List <double[]>(); var final = new Hashtable(); Calculations cal = new Calculations(); int V_No, grapgNo, start, end; switch (method) { case "f": V_No = Data.footGrapheVertices; grapgNo = 0; break; case "v": V_No = Data.vehicleGrapheVertices; grapgNo = 1; break; default: V_No = Data.footGrapheVertices; grapgNo = 0; break; } start = cal.GetNearestVertexNo(V_No, grapgNo, startLAT, startLON); end = cal.GetNearestVertexNo(V_No, grapgNo, endLAT, endLON); if (start != end) { int[] routes = cal.GetRouteNumbers(grapgNo, start, end); double[,] routeLocations; foreach (int r in routes) { if (grapgNo == 0) { routeLocations = LocationData.GetFootRoute(r); } else { routeLocations = LocationData.GetVehicleRoute(r); } lst.AddRange(new List <double[]>(cal.ValidateRoute(start, end, grapgNo, r, routeLocations))); } final.Add("routelocations", lst); final.Add("distance_time", cal.FindDistanceAndTime(grapgNo, start, end)); return(Json(final)); } return(Json(final)); }
public IActionResult GetPlace(double startLAT, double startLON, int placeID, string method) { List <double[]> lst = new List <double[]>(); List <double[]> zeroFloorRouteSet = new List <double[]>(); List <double[]> stair_0_1_RouteSet = new List <double[]>(); List <double[]> stair_1_2_RouteSet = new List <double[]>(); List <double[]> firstFloorRouteSet = new List <double[]>(); List <double[]> secondFloorRouteSet = new List <double[]>(); double distance = 0, time = 0; var final = new Hashtable(); double[,] routeLocations; double[] temp = new double[2], distanceAndTime; Calculations cal = new Calculations(); int V_No, graphNo, start, localEnd, innerStart = 0, innerEnd = 0; int[] ids, routes; double[,] floorLocations; Dictionary <string, double[]> place; Place pl; switch (method) { case "f": V_No = Data.footGrapheVertices; graphNo = 0; break; case "v": V_No = Data.vehicleGrapheVertices; graphNo = 1; break; default: V_No = Data.footGrapheVertices; graphNo = 0; break; } start = cal.GetNearestVertexNo(V_No, graphNo, startLAT, startLON); localEnd = cal.FindEnterenceVertexNo(V_No, graphNo, start, placeID); if (start != localEnd) { int[] route = cal.GetRouteNumbers(graphNo, start, localEnd); distanceAndTime = cal.FindDistanceAndTime(graphNo, start, localEnd); distance += distanceAndTime[0]; time += distanceAndTime[1]; foreach (int r in route) { if (graphNo == 0) { routeLocations = LocationData.GetFootRoute(r); } else { routeLocations = LocationData.GetVehicleRoute(r); } lst.AddRange(new List <double[]>(cal.ValidateRoute(start, localEnd, graphNo, r, routeLocations))); } final.Add("outerroutelocations", new List <double[]>(lst)); } lst.Clear(); for (int i = 0; i < Data.CSMainOuterInnerMatch.Length; i++) { if (Data.CSMainOuterInnerMatch[i] == localEnd) { innerStart = i; break; } } for (int i = 0; i < Data.CSMainPlaceMatch.Length; i++) { if (Data.CSMainPlaceMatch[i] == placeID) { innerEnd = i; break; } } graphNo = 2; ids = LocationData.GetDepartmentAndFloor(placeID); routes = cal.GetRouteNumbers(graphNo, innerStart, innerEnd); distanceAndTime = cal.FindDistanceAndTime(graphNo, innerStart, innerEnd); distance += distanceAndTime[0]; time += distanceAndTime[1]; //according to the department,no of arrays should change foreach (int rt in routes) { if (Data.CSFloor_0_RouteNumbers.Contains(rt)) { routeLocations = LocationData.GetInnerRoute(ids[0], rt); zeroFloorRouteSet.AddRange(new List <double[]>(cal.ValidateRoute(innerStart, innerEnd, graphNo, rt, routeLocations))); } else if (Data.CSFloor_1_RouteNumbers.Contains(rt)) { routeLocations = LocationData.GetInnerRoute(ids[0], rt); firstFloorRouteSet.AddRange(new List <double[]>(cal.ValidateRoute(innerStart, innerEnd, graphNo, rt, routeLocations))); } else if (Data.CSFloor_2_RouteNumbers.Contains(rt)) { routeLocations = LocationData.GetInnerRoute(ids[0], rt); secondFloorRouteSet.AddRange(new List <double[]>(cal.ValidateRoute(innerStart, innerEnd, graphNo, rt, routeLocations))); } else if (Data.CSStairBetwenn_0_1.Contains(rt)) { routeLocations = LocationData.GetInnerRoute(ids[0], rt); stair_0_1_RouteSet.AddRange(new List <double[]>(cal.ValidateRoute(innerStart, innerEnd, graphNo, rt, routeLocations))); } else if (Data.CSStairBetwenn_1_2.Contains(rt)) { routeLocations = LocationData.GetInnerRoute(ids[0], rt); stair_1_2_RouteSet.AddRange(new List <double[]>(cal.ValidateRoute(innerStart, innerEnd, graphNo, rt, routeLocations))); } } if (zeroFloorRouteSet.Count != 0) { final.Add("floor_0_routelocations", new List <double[]>(zeroFloorRouteSet)); lst.Clear(); floorLocations = LocationData.GetFloorLocations(ids[0], 0); for (int i = 0; i < floorLocations.GetLength(0); i++) { lst.Add(new double[] { floorLocations[i, 0], floorLocations[i, 1] }); } final.Add("floor_0_locations", new List <double[]>(lst)); } if (firstFloorRouteSet.Count != 0) { final.Add("floor_1_routelocations", new List <double[]>(firstFloorRouteSet)); lst.Clear(); floorLocations = LocationData.GetFloorLocations(ids[0], 1); for (int i = 0; i < floorLocations.GetLength(0); i++) { lst.Add(new double[] { floorLocations[i, 0], floorLocations[i, 1] }); } final.Add("floor_1_locations", new List <double[]>(lst)); } if (secondFloorRouteSet.Count != 0) { final.Add("floor_2_routelocations", new List <double[]>(secondFloorRouteSet)); lst.Clear(); floorLocations = LocationData.GetFloorLocations(ids[0], 2); for (int i = 0; i < floorLocations.GetLength(0); i++) { lst.Add(new double[] { floorLocations[i, 0], floorLocations[i, 1] }); } final.Add("floor_2_locations", new List <double[]>(lst)); } if (stair_0_1_RouteSet.Count != 0) { final.Add("stair_0_1_locations", stair_0_1_RouteSet); } if (stair_1_2_RouteSet.Count != 0) { final.Add("stair_1_2_locations", stair_1_2_RouteSet); } place = LocationData.GetPlaceWithName(placeID); pl = new Place(); foreach (KeyValuePair <string, double[]> pair in place)//only once { temp = pair.Value; pl = new Place() { name = pair.Key, lat = temp[0], lon = temp[1] }; } final.Add("place", pl); final.Add("distance_time", new double[] { distance, Math.Round(time, 1) }); return(Json(final)); }