cxYuanXing.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using WWPipeLine.MapBasic;
  12. namespace WWPipeLine.MapTools.Conditions.Sercher
  13. {
  14. public class cxYuanXing : ConditionPanel
  15. {
  16. private Sunny.UI.UIComboBox uiCBLayers;
  17. private Sunny.UI.UILabel uilbMsg;
  18. GeoRegion m_geo = null;
  19. public cxYuanXing() : base()
  20. {
  21. this.ConditionPanelName = "圆形查询";
  22. InitializeComponent();
  23. uilbMsg.Text = "鼠标左键长按画圆形";
  24. }
  25. protected override void OnLoad(EventArgs e)
  26. {
  27. MapControl.Action = SuperMap.UI.Action.CreateCircle;
  28. MapControl.Tracked += new TrackedEventHandler(TrackedHandler);
  29. uiCBLayers.ValueMember = "LayerDatasetName";
  30. uiCBLayers.DisplayMember = "LayerCaption";
  31. uiCBLayers.DataSource = getLayers();
  32. }
  33. private void TrackedHandler(object sender, TrackedEventArgs e)
  34. {
  35. if (e.Geometry is null) return;
  36. m_geo = e.Geometry.Clone() as GeoRegion;
  37. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("查询区域绘制失败"); return; }
  38. GeoStyle m_GeoStyle = new GeoStyle { LineColor = Color.Red, LineWidth = 1, FillBackOpaque = false, FillOpaqueRate = 10 };
  39. m_geo.Style = m_GeoStyle;
  40. MapControl.Map.TrackingLayer.Clear();
  41. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRectangle");
  42. MapControl.Map.Refresh();
  43. }
  44. public override object Do(DockPanel dockPanel = null)
  45. {
  46. IsConditionValid = false;
  47. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("请先绘制查询区域"); return false; }
  48. DatasetVector datasetVector = this.DatasourceMapControl.Datasets[uiCBLayers.SelectedValue.ToString()] as DatasetVector;
  49. if (datasetVector is null)
  50. {
  51. Sunny.UI.UIMessageTip.ShowError("当前选择的图层没有可用的数据"); return false;
  52. }
  53. Recordset recordset = datasetVector.Query(m_geo, 1, "1=1", CursorType.Static);
  54. if (recordset is null)
  55. {
  56. Sunny.UI.UIMessageTip.ShowError("当前图层没有查询到数据"); return false;
  57. }
  58. Layer layer = MapControl.Map.Layers.FindLayer(datasetVector);
  59. Selection selection = layer.Selection;
  60. selection.FromRecordset(recordset);
  61. layer.Selection = selection;
  62. MapControl.Map.Refresh();
  63. DataTable dt = RecordsetToDataTable(recordset, uiCBLayers.SelectedText);
  64. recordset.Close(); recordset.Dispose();
  65. return dt;
  66. }
  67. public override void AfterClose()
  68. {
  69. MapControl.Tracked -= new TrackedEventHandler(TrackedHandler);
  70. base.AfterClose();
  71. }
  72. private void InitializeComponent()
  73. {
  74. this.uilbMsg = new Sunny.UI.UILabel();
  75. this.uiCBLayers = new Sunny.UI.UIComboBox();
  76. this.SuspendLayout();
  77. //
  78. // uilbMsg
  79. //
  80. this.uilbMsg.AutoSize = true;
  81. this.uilbMsg.Font = new System.Drawing.Font("微软雅黑", 12F);
  82. this.uilbMsg.Location = new System.Drawing.Point(3, 39);
  83. this.uilbMsg.Name = "uilbMsg";
  84. this.uilbMsg.Size = new System.Drawing.Size(74, 21);
  85. this.uilbMsg.TabIndex = 0;
  86. this.uilbMsg.Text = "操作说明";
  87. this.uilbMsg.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
  88. //
  89. // uiCBLayers
  90. //
  91. this.uiCBLayers.DataSource = null;
  92. this.uiCBLayers.FillColor = System.Drawing.Color.White;
  93. this.uiCBLayers.Font = new System.Drawing.Font("微软雅黑", 12F);
  94. this.uiCBLayers.Location = new System.Drawing.Point(60, 5);
  95. this.uiCBLayers.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
  96. this.uiCBLayers.MinimumSize = new System.Drawing.Size(63, 0);
  97. this.uiCBLayers.Name = "uiCBLayers";
  98. this.uiCBLayers.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
  99. this.uiCBLayers.Size = new System.Drawing.Size(328, 29);
  100. this.uiCBLayers.TabIndex = 3;
  101. this.uiCBLayers.Text = "请选择需要查询的图层";
  102. this.uiCBLayers.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
  103. //
  104. // cxYuanXing
  105. //
  106. this.Controls.Add(this.uiCBLayers);
  107. this.Controls.Add(this.uilbMsg);
  108. this.Name = "cxYuanXing";
  109. this.Size = new System.Drawing.Size(392, 215);
  110. this.ResumeLayout(false);
  111. this.PerformLayout();
  112. }
  113. }
  114. }