BZZuoBiao.cs 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. }
  20. protected override void OnLoad(EventArgs e)
  21. {
  22. MapControl.Action = SuperMap.UI.Action.CreateLine;
  23. MapControl.Tracked += new TrackedEventHandler(MapControl_Tracked);
  24. MapControl.Tracking += new TrackingEventHandler(MapControl_Tracking);
  25. }
  26. private void MapControl_Tracking(object sender, TrackingEventArgs e)
  27. {
  28. if (m_StartPoint == Point2D.Empty)
  29. m_StartPoint = new Point2D(e.X, e.Y);
  30. else
  31. m_EndPoint = new Point2D(e.X, e.Y);
  32. }
  33. private void MapControl_Tracked(object sender, TrackedEventArgs e)
  34. {
  35. if (m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  36. {
  37. TextPart m_TextPart = new TextPart();
  38. m_TextPart.AnchorPoint = m_EndPoint;
  39. m_TextPart.Text = string.Format("X:{0}\r\nY:{1}", Math.Round(m_StartPoint.X, 2), Math.Round(m_StartPoint.Y, 2));
  40. GeoText geoText = new GeoText(m_TextPart, ComsStatic.BiaoZhuFengGe());
  41. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  42. Point2D p3 = new Point2D(geoText.Bounds.Right, geoText.Bounds.Bottom);
  43. //此处调试geoText.Bounds 左右、上下端点几乎一致 但是实际上界面是有XY坐标显示额
  44. //geoText.Bounds.Left 833130.131007001
  45. //geoText.Bounds.Right 833130.131007401
  46. //geoText.Bounds.Top 5051136.9966243524
  47. //geoText.Bounds.Bottom 5051136.9966239519
  48. GeoLine geoLine = new GeoLine();
  49. geoLine.AddPart(new Point2Ds() { m_StartPoint, m_EndPoint, p3 });
  50. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  51. MapControl.Map.TrackingLayer.Add(geoLine, "geoLine");
  52. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  53. MapControl.Map.RefreshTrackingLayer();
  54. }
  55. }
  56. public override void AfterClose()
  57. {
  58. MapControl.Tracked -= MapControl_Tracked;
  59. MapControl.Tracking -= MapControl_Tracking;
  60. base.AfterClose();
  61. }
  62. private void InitializeComponent()
  63. {
  64. this.SuspendLayout();
  65. //
  66. // ToolsConditions
  67. //
  68. this.ResumeLayout(false);
  69. }
  70. }
  71. }