BZShuanDian.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. using WWPipeLine.MapBasic;
  10. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  11. {
  12. public class BZShuanDian : BasicToolBar
  13. {
  14. private Point2D m_StartPoint = Point2D.Empty;
  15. private Point2D m_EndPoint = Point2D.Empty;
  16. public BZShuanDian() : base()
  17. {
  18. this.ConditionPanelName = "栓点标注";
  19. InitializeComponent();
  20. }
  21. protected override void OnLoad(EventArgs e)
  22. {
  23. MapControl.Action = SuperMap.UI.Action.CreateLine;
  24. MapControl.Cursor = Cursors.Arrow;
  25. MapControl.Tracked += new TrackedEventHandler(MapControl_Tracked);
  26. MapControl.Tracking += new TrackingEventHandler(MapControl_Tracking);
  27. }
  28. private void MapControl_Tracking(object sender, TrackingEventArgs e)
  29. {
  30. if (m_StartPoint == Point2D.Empty)
  31. m_StartPoint = new Point2D(e.X, e.Y);
  32. else
  33. m_EndPoint = new Point2D(e.X, e.Y);
  34. }
  35. private void MapControl_Tracked(object sender, TrackedEventArgs e)
  36. {
  37. if (m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  38. {
  39. TextPart m_TextPart = new TextPart();
  40. GeoLine line = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  41. line.Style = ComsStatic.geoStyle_Brown_05mm;
  42. MapControl.Map.TrackingLayer.Add(line, "geoLine");
  43. m_TextPart.X = line.InnerPoint.X; m_TextPart.Y = line.InnerPoint.Y;
  44. m_TextPart.Text = string.Format("{0}M", Math.Round(line.Length));
  45. double rotate = 0.0D;
  46. if (e.Azimuth < 180) rotate = -e.Azimuth + 90;
  47. else rotate = 270 - e.Azimuth;
  48. GeoText geoText = new GeoText(m_TextPart, ComsStatic.textStyle_Brown_6mm_BottomLeft);
  49. geoText.Rotate(line.InnerPoint, rotate);
  50. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  51. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  52. MapControl.Map.Refresh();
  53. }
  54. }
  55. public override void AfterClose()
  56. {
  57. MapControl.Tracked -= MapControl_Tracked;
  58. MapControl.Tracking -= MapControl_Tracking;
  59. base.AfterClose();
  60. }
  61. private void InitializeComponent()
  62. {
  63. this.SuspendLayout();
  64. //
  65. // ToolsConditions
  66. //
  67. this.Name = "坐标标注";
  68. this.ResumeLayout(false);
  69. }
  70. }
  71. }