BZShiTi.cs 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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 BZShiTi : BasicToolBar
  14. {
  15. private Point2D m_StartPoint = Point2D.Empty;
  16. private Point2D m_EndPoint = Point2D.Empty;
  17. private Recordset _recordset = null;
  18. private StringBuilder sb = new StringBuilder();
  19. public BZShiTi() : base()
  20. {
  21. this.ConditionPanelName = "单一实体标注";
  22. InitializeComponent();
  23. }
  24. protected override void OnLoad(EventArgs e)
  25. {
  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 = _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. //_recordset.GetFieldValue(ziduan)?.ToString().Split('.')[0]
  74. sb.AppendFormat("{0}:{1}{2}\r\n", rd.GetFieldValue("valueBefore"), _recordset.GetFieldValue(ziduan), rd.GetFieldValue("valueAfter"));
  75. }
  76. rd.MoveNext();
  77. }
  78. ComsStatic.RecordsetDispose(rd);
  79. m_StartPoint = _recordset.GetGeometry().InnerPoint;
  80. //m_StartPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  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. MapControl.Map.RefreshTrackingLayer();
  93. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  94. }
  95. }
  96. public override void AfterClose()
  97. {
  98. MapControl.MouseClick -= MapControl_MouseClick;
  99. MapControl.MouseMove -= MapControl_MouseMove;
  100. ComsStatic.RecordsetDispose(_recordset);
  101. base.AfterClose();
  102. }
  103. private void InitializeComponent()
  104. {
  105. this.SuspendLayout();
  106. //
  107. // ToolsConditions
  108. //
  109. this.Name = "坐标标注";
  110. this.ResumeLayout(false);
  111. }
  112. }
  113. }