123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- using SuperMap.Data;
- using SuperMap.Mapping;
- using SuperMap.UI;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Drawing;
- using WeifenLuo.WinFormsUI.Docking;
- using WWPipeLine.MapBasic.Conditions;
- namespace WWPipeLine.MapTools.Conditions.Sercher
- {
- public class cxDuoBianXing : ConditionPanel
- {
- private Sunny.UI.UILabel uilbMsg;
- private Sunny.UI.UIComboBox uiCBLayers;
- GeoRegion m_geo = null;
- public cxDuoBianXing() : base()
- {
- this.ConditionPanelName = "多边形查询";
- InitializeComponent();
- uilbMsg.Text = "鼠标右键开始绘制多边形,依次点击鼠标左键,构建多边形断点,再次点击右键结束绘制。";
- }
- protected override void OnLoad(EventArgs e)
- {
- //MapControl.TrackMode = TrackMode.Track;
- MapControl.Action = SuperMap.UI.Action.CreatePolygon;
- MapControl.Tracked += new TrackedEventHandler(TrackedHandler);
- uiCBLayers.ValueMember = "LayerDatasetName";
- uiCBLayers.DisplayMember = "LayerCaption";
- uiCBLayers.DataSource = getLayers();
- }
- private void TrackedHandler(object sender, TrackedEventArgs e)
- {
- if (e.Geometry is null) return;
- m_geo = e.Geometry.Clone() as GeoRegion;
- if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("查询区域绘制失败"); return; }
- GeoStyle m_GeoStyle = new GeoStyle { LineColor = Color.Red, LineWidth = 1, FillBackOpaque = false, FillOpaqueRate = 10 };
- m_geo.Style = m_GeoStyle;
- MapControl.Map.TrackingLayer.Clear();
- MapControl.Map.TrackingLayer.Add(m_geo, "GeoRegion");
- MapControl.Map.Refresh();
- }
- public override object Do(DockPanel dockPanel = null)
- {
- IsConditionValid = false;
- if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("请先绘制查询区域"); return false; }
- DatasetVector datasetVector = this.DatasourceMapControl.Datasets[uiCBLayers.SelectedValue.ToString()] as DatasetVector;
- if (datasetVector is null)
- {
- Sunny.UI.UIMessageTip.ShowError("当前选择的图层没有可用的数据"); return false;
- }
- Recordset recordset = datasetVector.Query(m_geo, 1, "1=1", CursorType.Static);
- if (recordset is null)
- {
- Sunny.UI.UIMessageTip.ShowError("当前图层没有查询到数据"); return false;
- }
- Layer layer = MapControl.Map.Layers.FindLayer(datasetVector);
- Selection selection = layer.Selection;
- selection.FromRecordset(recordset);
- layer.Selection = selection;
- //MapControl.Map.TrackingLayer.Clear();
- MapControl.Map.Refresh();
- DataTable dt = RecordsetToDataTable(recordset, uiCBLayers.SelectedText);
- recordset.Close(); recordset.Dispose();
- return dt;
- //return _dvEx.ToDataTable(recordsetCount);
- //DatasetVector datasetVector;
- ////Recordset recordsetCount = MapControl.Map.FindSelection(true)[0].ToRecordset();
- //Recordset recordset = null;
- ////Selection selection = new Selection();
- //foreach (Layer layer in MapControl.Map.Layers) //.FindLayer("JSLK@CL_PostGreSQL")
- //{
- // datasetVector = layer.Dataset as DatasetVector;
- // if (datasetVector == null) continue;
- // recordset = datasetVector.Query(m_geo, 1, "1=1", CursorType.Static);
- // if (recordset == null) continue;
- // //recordsetCount.AddNew(recordset.GetGeometry());
- // //recordsetCount.Update();
- // //selection.Clear();
- // Selection selection = layer.Selection;
- // selection.FromRecordset(recordset);
- // layer.Selection = selection;
- //}
- //recordset.Close(); recordset.Dispose();
- //MapControl.Map.Refresh();
- //DatasetVectorEx _dvEx = new DatasetVectorEx("recordsetCount");
- ////return _dvEx.ToDataTable(recordsetCount);
- }
- public override void AfterClose()
- {
- MapControl.Tracked -= new TrackedEventHandler(TrackedHandler);
- base.AfterClose();
- }
- private void InitializeComponent()
- {
- this.uilbMsg = new Sunny.UI.UILabel();
- this.uiCBLayers = new Sunny.UI.UIComboBox();
- this.SuspendLayout();
- //
- // uilbMsg
- //
- this.uilbMsg.AutoSize = true;
- this.uilbMsg.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uilbMsg.Location = new System.Drawing.Point(3, 35);
- this.uilbMsg.Name = "uilbMsg";
- this.uilbMsg.Size = new System.Drawing.Size(74, 21);
- this.uilbMsg.TabIndex = 0;
- this.uilbMsg.Text = "操作说明";
- this.uilbMsg.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // uiCBLayers
- //
- this.uiCBLayers.DataSource = null;
- this.uiCBLayers.FillColor = System.Drawing.Color.White;
- this.uiCBLayers.Font = new System.Drawing.Font("微软雅黑", 12F);
- this.uiCBLayers.Location = new System.Drawing.Point(60, 5);
- this.uiCBLayers.Margin = new System.Windows.Forms.Padding(4, 5, 4, 5);
- this.uiCBLayers.MinimumSize = new System.Drawing.Size(63, 0);
- this.uiCBLayers.Name = "uiCBLayers";
- this.uiCBLayers.Padding = new System.Windows.Forms.Padding(0, 0, 30, 2);
- this.uiCBLayers.Size = new System.Drawing.Size(328, 29);
- this.uiCBLayers.TabIndex = 1;
- this.uiCBLayers.Text = "请选择需要查询的图层";
- this.uiCBLayers.TextAlignment = System.Drawing.ContentAlignment.MiddleLeft;
- //
- // cxDuoBianXing
- //
- this.Controls.Add(this.uiCBLayers);
- this.Controls.Add(this.uilbMsg);
- this.Name = "cxDuoBianXing";
- this.Size = new System.Drawing.Size(392, 215);
- this.ResumeLayout(false);
- this.PerformLayout();
- }
- }
- }
|