cxDuoBianXing.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. using SuperMap.Data;
  2. using SuperMap.Mapping;
  3. using SuperMap.UI;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Drawing;
  8. using WeifenLuo.WinFormsUI.Docking;
  9. using WWPipeLine.MapBasic.Conditions;
  10. namespace WWPipeLine.MapTools.Conditions.Sercher
  11. {
  12. public class cxDuoBianXing : ConditionPanel
  13. {
  14. private Sunny.UI.UILabel uilbMsg;
  15. private Sunny.UI.UIComboBox uiCBLayers;
  16. GeoRegion m_geo = null;
  17. public cxDuoBianXing() : base()
  18. {
  19. this.ConditionPanelName = "多边形查询";
  20. InitializeComponent();
  21. uilbMsg.Text = "鼠标右键开始绘制多边形,依次点击鼠标左键,构建多边形断点,再次点击右键结束绘制。";
  22. }
  23. protected override void OnLoad(EventArgs e)
  24. {
  25. //MapControl.TrackMode = TrackMode.Track;
  26. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  27. MapControl.Tracked += new TrackedEventHandler(TrackedHandler);
  28. uiCBLayers.ValueMember = "LayerDatasetName";
  29. uiCBLayers.DisplayMember = "LayerCaption";
  30. uiCBLayers.DataSource = getLayers();
  31. }
  32. private void TrackedHandler(object sender, TrackedEventArgs e)
  33. {
  34. if (e.Geometry is null) return;
  35. m_geo = e.Geometry.Clone() as GeoRegion;
  36. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("查询区域绘制失败"); return; }
  37. GeoStyle m_GeoStyle = new GeoStyle { LineColor = Color.Red, LineWidth = 1, FillBackOpaque = false, FillOpaqueRate = 10 };
  38. m_geo.Style = m_GeoStyle;
  39. MapControl.Map.TrackingLayer.Clear();
  40. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRegion");
  41. MapControl.Map.Refresh();
  42. }
  43. public override object Do(DockPanel dockPanel = null)
  44. {
  45. IsConditionValid = false;
  46. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("请先绘制查询区域"); return false; }
  47. DatasetVector datasetVector = this.DatasourceMapControl.Datasets[uiCBLayers.SelectedValue.ToString()] as DatasetVector;
  48. if (datasetVector is null)
  49. {
  50. Sunny.UI.UIMessageTip.ShowError("当前选择的图层没有可用的数据"); return false;
  51. }
  52. Recordset recordset = datasetVector.Query(m_geo, 1, "1=1", CursorType.Static);
  53. if (recordset is null)
  54. {
  55. Sunny.UI.UIMessageTip.ShowError("当前图层没有查询到数据"); return false;
  56. }
  57. Layer layer = MapControl.Map.Layers.FindLayer(datasetVector);
  58. Selection selection = layer.Selection;
  59. selection.FromRecordset(recordset);
  60. layer.Selection = selection;
  61. //MapControl.Map.TrackingLayer.Clear();
  62. MapControl.Map.Refresh();
  63. DataTable dt = RecordsetToDataTable(recordset, uiCBLayers.SelectedText);
  64. recordset.Close(); recordset.Dispose();
  65. return dt;
  66. //return _dvEx.ToDataTable(recordsetCount);
  67. //DatasetVector datasetVector;
  68. ////Recordset recordsetCount = MapControl.Map.FindSelection(true)[0].ToRecordset();
  69. //Recordset recordset = null;
  70. ////Selection selection = new Selection();
  71. //foreach (Layer layer in MapControl.Map.Layers) //.FindLayer("JSLK@CL_PostGreSQL")
  72. //{
  73. // datasetVector = layer.Dataset as DatasetVector;
  74. // if (datasetVector == null) continue;
  75. // recordset = datasetVector.Query(m_geo, 1, "1=1", CursorType.Static);
  76. // if (recordset == null) continue;
  77. // //recordsetCount.AddNew(recordset.GetGeometry());
  78. // //recordsetCount.Update();
  79. // //selection.Clear();
  80. // Selection selection = layer.Selection;
  81. // selection.FromRecordset(recordset);
  82. // layer.Selection = selection;
  83. //}
  84. //recordset.Close(); recordset.Dispose();
  85. //MapControl.Map.Refresh();
  86. //DatasetVectorEx _dvEx = new DatasetVectorEx("recordsetCount");
  87. ////return _dvEx.ToDataTable(recordsetCount);
  88. }
  89. public override void AfterClose()
  90. {
  91. MapControl.Tracked -= new TrackedEventHandler(TrackedHandler);
  92. base.AfterClose();
  93. }
  94. private void InitializeComponent()
  95. {
  96. this.uilbMsg = new Sunny.UI.UILabel();
  97. this.uiCBLayers = new Sunny.UI.UIComboBox();
  98. this.SuspendLayout();
  99. //
  100. // uilbMsg
  101. //
  102. this.uilbMsg.AutoSize = true;
  103. this.uilbMsg.Font = new System.Drawing.Font("微软雅黑", 12F);
  104. this.uilbMsg.Location = new System.Drawing.Point(3, 35);
  105. this.uilbMsg.Name = "uilbMsg";
  106. this.uilbMsg.Size = new System.Drawing.Size(74, 21);
  107. this.uilbMsg.TabIndex = 0;
  108. this.uilbMsg.Text = "操作说明";
  109. this.uilbMsg.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  110. //
  111. // uiCBLayers
  112. //
  113. this.uiCBLayers.DataSource = null;
  114. this.uiCBLayers.FillColor = System.Drawing.Color.White;
  115. this.uiCBLayers.Font = new System.Drawing.Font("微软雅黑", 12F);
  116. this.uiCBLayers.Location = new System.Drawing.Point(60, 5);
  117. this.uiCBLayers.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  118. this.uiCBLayers.MinimumSize = new System.Drawing.Size(63, 0);
  119. this.uiCBLayers.Name = "uiCBLayers";
  120. this.uiCBLayers.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
  121. this.uiCBLayers.Size = new System.Drawing.Size(328, 29);
  122. this.uiCBLayers.TabIndex = 1;
  123. this.uiCBLayers.Text = "请选择需要查询的图层";
  124. this.uiCBLayers.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
  125. //
  126. // cxDuoBianXing
  127. //
  128. this.Controls.Add(this.uiCBLayers);
  129. this.Controls.Add(this.uilbMsg);
  130. this.Name = "cxDuoBianXing";
  131. this.Size = new System.Drawing.Size(392, 215);
  132. this.ResumeLayout(false);
  133. this.PerformLayout();
  134. }
  135. }
  136. }