BZCheQi.cs 4.0 KB

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