BZShiTi.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 BZShiTi : 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. private string _str;
  20. public BZShiTi() : base()
  21. {
  22. this.ConditionPanelName = "单一实体标注";
  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. }
  31. private void MapControl_MouseMove(object sender, MouseEventArgs e)
  32. {
  33. if (m_StartPoint != Point2D.Empty)
  34. {
  35. m_EndPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  36. GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  37. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  38. int index = MapControl.Map.TrackingLayer.IndexOf("MapControl_MouseMove");
  39. if (index > -1) MapControl.Map.TrackingLayer.Remove(index);
  40. MapControl.Map.TrackingLayer.Add(geoLine, "MapControl_MouseMove");
  41. MapControl.Map.Refresh();
  42. }
  43. }
  44. private void MapControl_MouseClick(object sender, MouseEventArgs e)
  45. {
  46. if (e.Button == MouseButtons.Left && MapControl.Action == SuperMap.UI.Action.Select && m_StartPoint == Point2D.Empty)
  47. {
  48. _selection = MapControl.Map.FindSelection(true);
  49. if (_selection is null || _selection.Length != 1)
  50. {
  51. Sunny.UI.UIMessageTip.ShowError("没有选中任何节点元素"); return;
  52. }
  53. _recordset = _selection[0].ToRecordset();
  54. if (_recordset.RecordCount != 1)
  55. {
  56. Sunny.UI.UIMessageTip.ShowError("选中的节点没有数据"); return;
  57. }
  58. DatasetVector dv = _recordset.Dataset as DatasetVector;
  59. if (dv.Name == dvJSLK_cp.Name)
  60. {
  61. if (!ComsStatic.HasField(dv, "cd"))
  62. { Sunny.UI.UIMessageTip.ShowError("当前管线没有长度信息"); return; }
  63. _str = "L=" + ComsStatic.StringToDouble(_recordset.GetFieldValue("cd"), 2).ToString() + "米";
  64. }
  65. else
  66. {
  67. if (!ComsStatic.HasField(dv, "x") || !ComsStatic.HasField(dv, "y"))
  68. { Sunny.UI.UIMessageTip.ShowError("当前管点没有坐标数据"); return; }
  69. _str = string.Format("X:{0}\r\nY:{1}", ComsStatic.StringToDouble(_recordset.GetFieldValue("x"), 2).ToString(), ComsStatic.StringToDouble(_recordset.GetFieldValue("y"), 2).ToString());
  70. }
  71. m_StartPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  72. MapControl.Action = SuperMap.UI.Action.Pan;
  73. MapControl.Map.Refresh();
  74. }
  75. else if (e.Button == MouseButtons.Left && m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  76. {
  77. TextPart m_TextPart = new TextPart();
  78. m_TextPart.X = m_EndPoint.X; m_TextPart.Y = m_EndPoint.Y;
  79. m_TextPart.Text = _str;
  80. GeoText geoText = new GeoText(m_TextPart, ComsStatic.textStyle_Brown_6mm_BottomLeft);
  81. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  82. GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  83. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  84. MapControl.Map.TrackingLayer.Add(geoLine, "geoLine");
  85. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  86. MapControl.Map.Refresh();
  87. }
  88. }
  89. public override void AfterClose()
  90. {
  91. MapControl.MouseClick -= MapControl_MouseClick;
  92. MapControl.MouseMove -= MapControl_MouseMove;
  93. base.AfterClose();
  94. }
  95. private void InitializeComponent()
  96. {
  97. this.SuspendLayout();
  98. //
  99. // ToolsConditions
  100. //
  101. this.Name = "坐标标注";
  102. this.ResumeLayout(false);
  103. }
  104. }
  105. }