BZMaiShen.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. using SuperMap.Mapping;
  11. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  12. {
  13. public class BZMaiShen : BasicToolBar
  14. {
  15. private Point2D m_StartPoint = Point2D.Empty;
  16. private Point2D m_EndPoint = Point2D.Empty;
  17. private Selection[] _selection = null;
  18. private Recordset _recordset = null;
  19. public BZMaiShen() : base()
  20. {
  21. this.ConditionPanelName = "埋深标注";
  22. this.toolStripLB.Text = "先选择管点,再右键绘制";
  23. InitializeComponent();
  24. }
  25. protected override void OnLoad(EventArgs e)
  26. {
  27. MapControl.Action = SuperMap.UI.Action.Select;
  28. MapControl.MouseClick += MapControl_MouseClick;
  29. MapControl.MouseMove += MapControl_MouseMove;
  30. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true);
  31. }
  32. private void MapControl_MouseMove(object sender, MouseEventArgs e)
  33. {
  34. if (m_StartPoint != Point2D.Empty)
  35. {
  36. m_EndPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  37. GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  38. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  39. int index = MapControl.Map.TrackingLayer.IndexOf("MapControl_MouseMove");
  40. if (index > -1) MapControl.Map.TrackingLayer.Remove(index);
  41. MapControl.Map.TrackingLayer.Add(geoLine, "MapControl_MouseMove");
  42. MapControl.Map.Refresh();
  43. }
  44. }
  45. private void MapControl_MouseClick(object sender, MouseEventArgs e)
  46. {
  47. if (e.Button == MouseButtons.Left && MapControl.Action == SuperMap.UI.Action.Select && m_StartPoint == Point2D.Empty)
  48. {
  49. _selection = MapControl.Map.FindSelection(true);
  50. if (_selection is null || _selection.Length != 1)
  51. {
  52. Sunny.UI.UIMessageTip.ShowError("没有选中任何节点元素"); return;
  53. }
  54. _recordset = _selection[0].ToRecordset();
  55. if (_recordset.RecordCount != 1 || !ComsStatic.HasField(_recordset, "ms"))
  56. {
  57. Sunny.UI.UIMessageTip.ShowError("选中的节点没有埋深数据"); return;
  58. }
  59. m_StartPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  60. MapControl.Action = SuperMap.UI.Action.Pan;
  61. MapControl.Map.Refresh();
  62. }
  63. else if (e.Button == MouseButtons.Left && m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  64. {
  65. TextPart m_TextPart = new TextPart();
  66. m_TextPart.X = m_EndPoint.X; m_TextPart.Y = m_EndPoint.Y;
  67. m_TextPart.Text = "埋深:" + ComsStatic.StringToDouble(_recordset.GetFieldValue("ms"), 2).ToString() + "米";
  68. GeoText geoText = new GeoText(m_TextPart, ComsStatic.textStyle_Brown_6mm_BottomLeft);
  69. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  70. GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  71. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  72. MapControl.Map.TrackingLayer.Add(geoLine, "geoLine");
  73. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  74. MapControl.Map.Refresh();
  75. }
  76. }
  77. public override void AfterClose()
  78. {
  79. MapControl.MouseClick -= MapControl_MouseClick;
  80. MapControl.MouseMove -= MapControl_MouseMove;
  81. base.AfterClose();
  82. }
  83. private void InitializeComponent()
  84. {
  85. this.SuspendLayout();
  86. //
  87. // ToolsConditions
  88. //
  89. this.Name = "坐标标注";
  90. this.ResumeLayout(false);
  91. }
  92. }
  93. }