BZCheQi.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. using System.Text;
  11. namespace WWPipeLine.MapTools.Conditions.FuZhuGongJu
  12. {
  13. public class BZCheQi : 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 StringBuilder sb = new StringBuilder();
  20. public BZCheQi() : base()
  21. {
  22. this.ConditionPanelName = "扯旗标注";
  23. toolStripLB.Text = "鼠标左键点击选择需要标注的管线,再次点击完成标注。";
  24. InitializeComponent();
  25. }
  26. protected override void OnLoad(EventArgs e)
  27. {
  28. ComsStatic.SetLayersIsSelectableFalse(ComsStatic.dvJSLK.Name, true);
  29. MapControl.Action = SuperMap.UI.Action.Select;
  30. MapControl.MouseClick += MapControl_MouseClick;
  31. MapControl.MouseMove += MapControl_MouseMove;
  32. }
  33. private void MapControl_MouseMove(object sender, MouseEventArgs e)
  34. {
  35. if (m_StartPoint != Point2D.Empty)
  36. {
  37. m_EndPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  38. GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  39. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  40. int index = MapControl.Map.TrackingLayer.IndexOf("MapControl_MouseMove");
  41. if (index > -1) MapControl.Map.TrackingLayer.Remove(index);
  42. MapControl.Map.TrackingLayer.Add(geoLine, "MapControl_MouseMove");
  43. MapControl.Map.RefreshTrackingLayer();
  44. }
  45. }
  46. private void MapControl_MouseClick(object sender, MouseEventArgs e)
  47. {
  48. if (e.Button == MouseButtons.Left && MapControl.Action == SuperMap.UI.Action.Select && m_StartPoint == Point2D.Empty)
  49. {
  50. _selection = MapControl.Map.FindSelection(true);
  51. if (_selection is null || _selection.Length != 1)
  52. {
  53. Sunny.UI.UIMessageTip.ShowError("没有选中任何管线元素"); return;
  54. }
  55. _recordset = _selection[0].ToRecordset();
  56. if (_recordset.RecordCount != 1)
  57. {
  58. Sunny.UI.UIMessageTip.ShowError("一次只可标记一条管线"); return;
  59. }
  60. QueryParameter queryParameter = new QueryParameter
  61. {
  62. AttributeFilter = string.Format(" pzlx='扯旗标注配置' AND gxlx='{0}' AND valueEnable=1 ", _recordset.Dataset.Name),
  63. ResultFields = new string[] { "pzKey", "valueBefore", "valueAfter" },
  64. OrderBy = new string[] { " valueSort asc " },
  65. CursorType = CursorType.Static
  66. };
  67. Recordset rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
  68. if (rd.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("选中的图层未配置标注字段信息"); return; }
  69. rd.MoveFirst();
  70. sb.Clear();
  71. while (!rd.IsEOF)
  72. {
  73. string ziduan = rd.GetFieldValue("pzKey").ToString();
  74. if (ComsStatic.HasField(_recordset, ziduan))
  75. {
  76. sb.AppendFormat("{0}:{1}{2}\r\n", rd.GetFieldValue("valueBefore"), _recordset.GetFieldValue(ziduan)?.ToString().Split('.')[0], rd.GetFieldValue("valueAfter"));
  77. }
  78. rd.MoveNext();
  79. }
  80. m_StartPoint = _recordset.GetGeometry().InnerPoint;
  81. }
  82. else if (e.Button == MouseButtons.Left && m_StartPoint != Point2D.Empty && m_EndPoint != Point2D.Empty)
  83. {
  84. TextPart m_TextPart = new TextPart();
  85. m_TextPart.AnchorPoint = m_EndPoint;
  86. m_TextPart.Text = sb.ToString();
  87. GeoText geoText = new GeoText(m_TextPart, ComsStatic.BiaoZhuFengGe());
  88. MapControl.Map.TrackingLayer.Add(geoText, "geoText");
  89. GeoLine geoLine = new GeoLine(new Point2Ds() { m_StartPoint, m_EndPoint });
  90. geoLine.Style = ComsStatic.geoStyle_Brown_05mm;
  91. MapControl.Map.TrackingLayer.Add(geoLine, "geoLine");
  92. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  93. MapControl.Map.Refresh();
  94. }
  95. }
  96. public override void AfterClose()
  97. {
  98. MapControl.MouseClick -= MapControl_MouseClick;
  99. MapControl.MouseMove -= MapControl_MouseMove;
  100. base.AfterClose();
  101. }
  102. private void InitializeComponent()
  103. {
  104. this.SuspendLayout();
  105. //
  106. // ToolsConditions
  107. //
  108. this.Name = "坐标标注";
  109. this.ResumeLayout(false);
  110. }
  111. }
  112. }