BZShiTi.cs 4.1 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 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. toolStripLB.Text = "鼠标左键点击选择需要标注的实体元素,再次点击完成标注。";
  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.RefreshTrackingLayer();
  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[] _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. QueryParameter queryParameter = new QueryParameter
  59. {
  60. AttributeFilter = string.Format(" pzlx='标注字段配置' AND gxlx='{0}' AND valueEnable=1 ", _recordset.Dataset.Name),
  61. ResultFields = new string[] { "pzKey", "valueBefore", "valueAfter" },
  62. OrderBy = new string[] { " valueSort asc " },
  63. CursorType = CursorType.Static
  64. };
  65. Recordset rd = ComsStatic.dvJSLK_PZ.Query(queryParameter);
  66. if (rd.RecordCount == 0) { Sunny.UI.UIMessageTip.ShowError("选中的图层未配置标注字段信息"); return; }
  67. rd.MoveFirst();
  68. sb.Clear();
  69. while (!rd.IsEOF)
  70. {
  71. string ziduan = rd.GetFieldValue("pzKey").ToString();
  72. if (ComsStatic.HasField(_recordset, ziduan))
  73. {
  74. sb.AppendFormat("{0}:{1}{2}\r\n", rd.GetFieldValue("valueBefore"), _recordset.GetFieldValue(ziduan)?.ToString().Split('.')[0], rd.GetFieldValue("valueAfter"));
  75. }
  76. rd.MoveNext();
  77. }
  78. m_StartPoint = _recordset.GetGeometry().InnerPoint;
  79. //m_StartPoint = MapControl.Map.PixelToMap(new Point(e.X, e.Y));
  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. m_StartPoint = Point2D.Empty; m_EndPoint = Point2D.Empty;
  92. MapControl.Map.Refresh();
  93. }
  94. }
  95. public override void AfterClose()
  96. {
  97. MapControl.MouseClick -= MapControl_MouseClick;
  98. MapControl.MouseMove -= MapControl_MouseMove;
  99. ComsStatic.RecordsetDispose(_recordset);
  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. }