BZShuanDian.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 SuperMap.UI;
  8. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  9. {
  10. public class BZShuanDian : BasicToolBar
  11. {
  12. private Point2D m_StartPoint = Point2D.Empty;
  13. private Point2D m_EndPoint = Point2D.Empty;
  14. public BZShuanDian() : base()
  15. {
  16. this.ConditionPanelName = "栓点标注";
  17. InitializeComponent();
  18. toolStripLB.Text = "鼠标左键点击选择起点,再次点击选择终点,并完成标注。";
  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. GeoLine line = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  38. line.Style = ComsStatic.geoStyle_Brown_05mm;
  39. MapControl.Map.TrackingLayer.Add(line, "geoLine");
  40. TextPart m_TextPart = new TextPart();
  41. m_TextPart.AnchorPoint = line.InnerPoint;
  42. m_TextPart.Text = string.Format("{0}M", Math.Round(line.Length));
  43. double rotate = 0.0D;
  44. if (e.Azimuth < 180) rotate = -e.Azimuth + 90;
  45. else rotate = 270 - e.Azimuth;
  46. GeoText geoText = new GeoText(m_TextPart, ComsStatic.BiaoZhuFengGe());
  47. geoText.Rotate(line.InnerPoint, rotate);
  48. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  49. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  50. MapControl.Map.Refresh();
  51. }
  52. }
  53. public override void AfterClose()
  54. {
  55. MapControl.Tracked -= MapControl_Tracked;
  56. MapControl.Tracking -= MapControl_Tracking;
  57. base.AfterClose();
  58. }
  59. private void InitializeComponent()
  60. {
  61. this.SuspendLayout();
  62. //
  63. // ToolsConditions
  64. //
  65. this.ResumeLayout(false);
  66. }
  67. }
  68. }