BZMaiShen.cs 3.2 KB

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