BZZuoBiao.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using SuperMap.Data;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Windows.Forms;
  5. using WWPipeLine.MapBasic.Conditions;
  6. using WWPipeLine.MapBasic;
  7. using System.Drawing;
  8. using SuperMap.UI;
  9. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  10. {
  11. public class BZZuoBiao : BasicToolBar
  12. {
  13. private Point2D m_StartPoint = Point2D.Empty;
  14. private Point2D m_EndPoint = Point2D.Empty;
  15. public BZZuoBiao() : base()
  16. {
  17. this.ConditionPanelName = "坐标标注";
  18. InitializeComponent();
  19. //this.SetSize(0, 0);
  20. //IsShowConditionForm = false;
  21. toolStripLB.Text = "";
  22. }
  23. protected override void OnLoad(EventArgs e)
  24. {
  25. MapControl.Action = SuperMap.UI.Action.CreateLine;
  26. MapControl.Cursor = Cursors.Arrow;
  27. MapControl.Tracked += new TrackedEventHandler(MapControl_Tracked);
  28. MapControl.Tracking += new TrackingEventHandler(MapControl_Tracking);
  29. MapControl.MouseUp += MapControl_MouseUp;
  30. }
  31. private void MapControl_MouseUp(object sender, MouseEventArgs e)
  32. {
  33. Point point = new Point(e.X, e.Y);
  34. Point2D p = MapControl.Map.PixelToMap(point);
  35. }
  36. private void MapControl_Tracking(object sender, TrackingEventArgs e)
  37. {
  38. if (m_StartPoint == Point2D.Empty)
  39. m_StartPoint = new Point2D(e.X, e.Y);
  40. else
  41. m_EndPoint = new Point2D(e.X, e.Y);
  42. }
  43. private void MapControl_Tracked(object sender, TrackedEventArgs e)
  44. {
  45. if (m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  46. {
  47. TextPart m_TextPart = new TextPart();
  48. m_TextPart.X = m_EndPoint.X; m_TextPart.Y = m_EndPoint.Y;
  49. m_TextPart.Text = string.Format("X:{0}\r\nY:{1}", Math.Round(m_StartPoint.X, 2), Math.Round(m_StartPoint.Y, 2));
  50. GeoText geoText = new GeoText(m_TextPart, ComsStatic.textStyle_Brown_6mm_BottomLeft);
  51. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  52. Point2D p3 = new Point2D(geoText.Bounds.Right, geoText.Bounds.Bottom);
  53. //此处调试geoText.Bounds 左右、上下端点几乎一致 但是世界上界面是有XY坐标显示额
  54. //geoText.Bounds.Left 833130.131007001
  55. //geoText.Bounds.Right 833130.131007401
  56. //geoText.Bounds.Top 5051136.9966243524
  57. //geoText.Bounds.Bottom 5051136.9966239519
  58. GeoLine geoLine = new GeoLine();
  59. geoLine.AddPart(new Point2Ds() { m_StartPoint, m_EndPoint, p3 });
  60. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  61. MapControl.Map.TrackingLayer.Add(geoLine, "geoLine");
  62. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  63. MapControl.Map.Refresh();
  64. }
  65. }
  66. public override void AfterClose()
  67. {
  68. MapControl.Tracked -= MapControl_Tracked;
  69. MapControl.Tracking -= MapControl_Tracking;
  70. base.AfterClose();
  71. }
  72. private void InitializeComponent()
  73. {
  74. this.SuspendLayout();
  75. //
  76. // ToolsConditions
  77. //
  78. this.Name = "坐标标注";
  79. this.ResumeLayout(false);
  80. }
  81. }
  82. }