public string GetFirstRoad() { string roadCode; var road = Program.dt.GetFirst(out roadCode); int indexValue = 0; do { var roadItem = road[indexValue]; var a1 = (from item in roadItem.Cross1 where item.CrossState == 1 && item.RoadCode1 == roadCode orderby item.RoadOrder1 + item.Percent1 ascending select item).ToList(); var a2 = (from item in roadItem.Cross2 where item.CrossState == 1 && item.RoadCode2 == roadCode orderby item.RoadOrder2 + item.Percent2 ascending select item).ToList(); if (a1.Count > 0 && a2.Count > 0) { if (a1.First().RoadOrder1 + a1.First().Percent1 < a2.First().RoadOrder2 + a2.First().Percent2) { var obj = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = a1.First().RoadCode2, anotherRoadOrder = a1.First().RoadOrder2, roadCode = a1.First().RoadCode1, roadOrder = a1.First().RoadOrder1, longitude = a1.First().BDLongitude, latitude = a1.First().BDLatitude }; var sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(obj); return(sendMsg); } else { var obj = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = a2.First().RoadCode1, anotherRoadOrder = a2.First().RoadOrder1, roadCode = a2.First().RoadCode2, roadOrder = a2.First().RoadOrder2, longitude = a2.First().BDLongitude, latitude = a2.First().BDLatitude }; var sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(obj); return(sendMsg); } } else if (a1.Count > 0) { var obj = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = a1.First().RoadCode2, anotherRoadOrder = a1.First().RoadOrder2, roadCode = a1.First().RoadCode1, roadOrder = a1.First().RoadOrder1, longitude = a1.First().BDLongitude, latitude = a1.First().BDLatitude }; var sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(obj); return(sendMsg); } else if (a2.Count > 0) { var obj = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = a2.First().RoadCode1, anotherRoadOrder = a2.First().RoadOrder1, roadCode = a2.First().RoadCode2, roadOrder = a2.First().RoadOrder2, longitude = a2.First().BDLongitude, latitude = a2.First().BDLatitude }; var sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(obj); return(sendMsg); } indexValue++; }while (road.ContainsKey(indexValue)); throw new Exception(""); }
public string PreviousCross(MapEditor.PreviousCross pc) { Dictionary <string, Dictionary <int, OssModel.SaveRoad.RoadInfo> > road; Program.dt.GetData(out road); double percent; double lon, lat; { var roadItem = road[pc.roadCode][pc.roadOrder]; var a1 = (from item in roadItem.Cross1 where item.CrossState == 1 && item.RoadCode2 == pc.anotherRoadCode && item.RoadOrder2 == pc.anotherRoadOrder select item).ToList(); var a2 = (from item in roadItem.Cross2 where item.CrossState == 1 && item.RoadCode1 == pc.anotherRoadCode && item.RoadOrder1 == pc.anotherRoadOrder select item).ToList(); if (a1.Count == 1) { percent = a1[0].Percent1; lon = a1[0].BDLongitude; lat = a1[0].BDLatitude; } else { percent = a2[0].Percent2; lon = a2[0].BDLongitude; lat = a2[0].BDLatitude; } } double maxValue = -1; int roadOrder = pc.roadOrder; CommonClass.MapEditor.Position positionResult = null; do { var roadItem = road[pc.roadCode][roadOrder]; { var a1 = (from item in roadItem.Cross1 where item.CrossState == 1 && (item.RoadCode2 != pc.anotherRoadCode || item.RoadOrder2 != pc.anotherRoadOrder) && item.RoadOrder1 + item.Percent1 < percent + pc.roadOrder select item).ToList(); for (var i = 0; i < a1.Count; i++) { if (a1[i].Percent1 + a1[i].RoadOrder1 > maxValue) { maxValue = a1[i].Percent1 + a1[i].RoadOrder1; positionResult = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = a1[i].RoadCode2, anotherRoadOrder = a1[i].RoadOrder2, roadCode = a1[i].RoadCode1, roadOrder = a1[i].RoadOrder1, longitude = a1[i].BDLongitude, latitude = a1[i].BDLatitude }; } } } { var a2 = (from item in roadItem.Cross2 where item.CrossState == 1 && (item.RoadCode1 != pc.anotherRoadCode || item.RoadOrder1 != pc.anotherRoadOrder) && item.RoadOrder2 + item.Percent2 < percent + pc.roadOrder select item).ToList(); for (var i = 0; i < a2.Count; i++) { if (a2[i].Percent2 + a2[i].RoadOrder2 > maxValue) { maxValue = a2[i].Percent2 + a2[i].RoadOrder2; positionResult = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = a2[i].RoadCode1, anotherRoadOrder = a2[i].RoadOrder1, roadCode = a2[i].RoadCode2, roadOrder = a2[i].RoadOrder2, longitude = a2[i].BDLongitude, latitude = a2[i].BDLatitude }; } } } roadOrder--; }while (road[pc.roadCode].ContainsKey(roadOrder)); if (positionResult == null) { positionResult = new CommonClass.MapEditor.Position() { c = "Position", anotherRoadCode = pc.anotherRoadCode, anotherRoadOrder = pc.anotherRoadOrder, roadCode = pc.roadCode, roadOrder = pc.roadOrder, longitude = lon, latitude = lat }; } var sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(positionResult); return(sendMsg); }