private void btnLoadRoute_Click(object sender, EventArgs e) { if (MapGis.RouteList.Count == 0) { DataTable stationposition = dpicbll.GetStationPositionByFileID(this.FileID); DataTable routedt = dpicbll.GetRouteInfoPositionByFileID(this.FileID); if (routedt.Rows.Count > 0) { this.MapGis.ClareRouteModelList(); this.MapGis.ClearAllStation(); for (int i = 0; i < stationposition.Rows.Count; i++) { string stationname = stationposition.Rows[i][0].ToString(); PointF p = new PointF(float.Parse(stationposition.Rows[i][1].ToString()), float.Parse(stationposition.Rows[i][2].ToString())); MapGis.AddConfigStation(stationname, p); } for (int i = 0; i < routedt.Rows.Count; i++) { if (i % 2 != 0) { ZzhaControlLibrary.RouteModel rm = new RouteModel(); string from = routedt.Rows[i][0].ToString(); string[] fromxy = from.Split(','); rm.From = new PointF(float.Parse(fromxy[0]), float.Parse(fromxy[1])); string to = routedt.Rows[i][1].ToString(); string[] toxy = to.Split(','); rm.To = new PointF(float.Parse(toxy[0]), float.Parse(toxy[1])); rm.RouteLength = int.Parse(routedt.Rows[i][2].ToString()); MapGis.AddConfigRouteModel(rm); } } MapGis.FlashAll(); this.btnCreate.Enabled = true; this.btnLoadRoute.Enabled = false; } else { MessageBox.Show("您尚未配置过路径,无法载入上次路径配置信息...", "提示", MessageBoxButtons.OK); } } }
private void PaintRoutTen(Graphics g, RouteModel rm) { PointF from = PositionChanger.ZoomPositionChange(Convert.ToDouble(MapWidth) / Convert.ToDouble(OldMapWidth), rm.From); from = PositionChanger.PositionChange(new Point(1, 1), new Point(MapX + 1, MapY + 1), from); PointF to = PositionChanger.ZoomPositionChange(Convert.ToDouble(MapWidth) / Convert.ToDouble(OldMapWidth), rm.To); to = PositionChanger.PositionChange(new Point(1, 1), new Point(MapX + 1, MapY + 1), to); //g.FillEllipse(Brushes.Red, from.X - 6, from.Y - 6, 12, 12); //g.FillEllipse(Brushes.Red, to.X - 6, to.Y - 6, 12, 12); //g.DrawLine(rm.PenColor, from, to); g.DrawLine(new Pen(rm.PenColor, 3.0f), from, to); }
/// <summary> /// 获取坐标点 /// </summary> /// <param name="i"></param> private void GetRoute(int i) { if (IsPaintRoute) { if (i == Index) { //Czlt-向Hash表里添加分站名称和出分站时间 strPassTime = MoverList[i].StrPassTime; strStationName = MoverList[i].StrStationName; strHeadName = MoverList[i].LabHead; if (strPassTime != null && strStationName != null) { if (hashStation.ContainsKey(strStationName.Trim())) { hashStation.Remove(strStationName.Trim()); } hashStation.Add(strStationName.Trim(), strPassTime.Trim()); } } //Czlt-路线模块对象 RouteModel rm = new RouteModel(); switch (i) { case 0: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList0.Clear(); } } rm.From = new PointF(MoverList[i].OldX, MoverList[i].OldY); rm.To = new PointF(MoverList[i].X, MoverList[i].Y); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.Blue; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList0.Add(rm); break; case 1: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList1.Clear(); } } rm.From = new PointF(MoverList[i].OldX + 4, MoverList[i].OldY + 4); rm.To = new PointF(MoverList[i].X + 4, MoverList[i].Y + 4); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.Yellow; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList1.Add(rm); break; case 2: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList2.Clear(); } } rm.From = new PointF(MoverList[i].OldX - 4, MoverList[i].OldY - 4); rm.To = new PointF(MoverList[i].X - 4, MoverList[i].Y -4); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.Green; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList2.Add(rm); break; case 3: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList3.Clear(); } } rm.From = new PointF(MoverList[i].OldX - 8, MoverList[i].OldY - 8); rm.To = new PointF(MoverList[i].X - 8, MoverList[i].Y - 8); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.Magenta; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList3.Add(rm); break; case 4: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList4.Clear(); } } rm.From = new PointF(MoverList[i].OldX + 8, MoverList[i].OldY + 8); rm.To = new PointF(MoverList[i].X + 8, MoverList[i].Y + 8); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.MediumSlateBlue; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList4.Add(rm); break; case 5: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList5.Clear(); } } rm.From = new PointF(MoverList[i].OldX + 8, MoverList[i].OldY + 8); rm.To = new PointF(MoverList[i].X + 8, MoverList[i].Y + 8); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.DodgerBlue; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList5.Add(rm); break; case 6: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList6.Clear(); } } rm.From = new PointF(MoverList[i].OldX - 8, MoverList[i].OldY - 8); rm.To = new PointF(MoverList[i].X - 8, MoverList[i].Y - 8); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.Indigo; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList6.Add(rm); break; case 7: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList7.Clear(); } } rm.From = new PointF(MoverList[i].OldX + 4, MoverList[i].OldY + 4); rm.To = new PointF(MoverList[i].X + 4, MoverList[i].Y + 4); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.YellowGreen; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList7.Add(rm); break; case 8: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList8.Clear(); } } rm.From = new PointF(MoverList[i].OldX - 4, MoverList[i].OldY - 4); rm.To = new PointF(MoverList[i].X - 4, MoverList[i].Y - 4); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.SaddleBrown; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList8.Add(rm); break; case 9: if (StartPoint.X.Equals(MoverList[i].X) && StartPoint.Y.Equals(MoverList[i].Y)) { if (MoverList[i].NowStationsIndex != MoverList[i].StationSum) { CzltRouteList9.Clear(); } } rm.From = new PointF(MoverList[i].OldX , MoverList[i].OldY ); rm.To = new PointF(MoverList[i].X , MoverList[i].Y ); rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); if (HashNameColor.ContainsKey(i)) { rm.PenColor = (Color)HashNameColor[i]; } else { rm.PenColor = Color.Navy; } if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); CzltRouteList9.Add(rm); break; default: break; } } }
private void ZzhaMapGis_MouseClick(object sender, MouseEventArgs e) { if (IsBeginDrawRoute) { if (IsEverStop) { for (int i = 0; i < lpt.Count; i++) { lpt.RemoveAt(0); } } if (this.lsvItems.Items.Count < 1) { if (this.lsvItems.Items.Count < 1) { if (lpt.Count > 0) { RouteModel rm = new RouteModel(); rm.From = lpt[0]; PointF p = ComparePoint(e.Location); rm.To = p; rm.RouteLength = Convert.ToInt32(Math.Sqrt(Math.Pow(rm.From.X - rm.To.X, 2) + Math.Pow(rm.From.Y - rm.To.Y, 2))); this.RouteList.Add(rm); if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); FlashMap(); mouseflag = true; for (int i = 0; i < lpt.Count; i++) { lpt.RemoveAt(0); } if (IsRouteLine) { return; } } } else { MessageBox.Show("分站位置尚未配置完成,请配置完成后再配置路径!", "提示", MessageBoxButtons.OK); } bool BFirst = false; //添加配置代码 if (mouseflag) { if (!(this.lsvItems.Items.Count > 0)) { PointF p = ComparePoint(e.Location); lpt.Add(p); listPointDraw = lpt; FlashMap(); //routeFrom = p; //mouseflag = false; } } } } else { for (int i = 0; i < lpt.Count; i++) { lpt.RemoveAt(0); } } }
public void AddConfigRouteModel(RouteModel rm) { this.RouteList.Add(rm); if (!ExitsRoutePoint.Contains(rm.From)) ExitsRoutePoint.Add(rm.From); if (!ExitsRoutePoint.Contains(rm.To)) ExitsRoutePoint.Add(rm.To); }
private void 载入路径LToolStripMenuItem_Click(object sender, EventArgs e) { if (MapGis.RouteList.Count == 0) { DataTable stationposition = new Graphics_RouteBLL().GetStationHeadPosition(); DataTable routedt = new Graphics_RouteBLL().GetAllRoute(); if (routedt.Rows.Count > 0) { this.MapGis.ClareRouteModelList(); this.MapGis.ClearAllStation(); for (int i = 0; i < stationposition.Rows.Count; i++) { string stationname = stationposition.Rows[i][0].ToString(); PointF p = new PointF(float.Parse(stationposition.Rows[i][1].ToString()), float.Parse(stationposition.Rows[i][2].ToString())); MapGis.AddConfigStation(stationname, p); } for (int i = 0; i < routedt.Rows.Count; i++) { ZzhaControlLibrary.RouteModel rm = new RouteModel(); string from = routedt.Rows[i][0].ToString(); string[] fromxy = from.Split(','); rm.From = new PointF(float.Parse(fromxy[0]), float.Parse(fromxy[1])); string to = routedt.Rows[i][1].ToString(); string[] toxy = to.Split(','); rm.To = new PointF(float.Parse(toxy[0]), float.Parse(toxy[1])); rm.RouteLength = int.Parse(routedt.Rows[i][2].ToString()); MapGis.AddConfigRouteModel(rm); } MapGis.FlashAll(); } else { MessageBox.Show("您尚未配置过路径,无法载入上次路径配置信息...", "提示", MessageBoxButtons.OK); } } }