using ESRI.ArcGIS.ADF.BaseClasses; using ESRI.ArcGIS.Carto; using ESRI.ArcGIS.Controls; using ESRI.ArcGIS.Display; using ESRI.ArcGIS.esriSystem; using ESRI.ArcGIS.Geodatabase; using ESRI.ArcGIS.Geometry; using KGIS.Framework.Maps; using KGIS.Framework.Utils; using Kingo.Plugin.MapView.Views; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Kingo.Plugin.MapView.Commands { public class AttributeLookCommand : BaseTool { private IHookHelper m_hookHelper; IPoint fromPoint = null; IPoint toPoint = null; FrmFeatureAttributes frmAttr = null; private INewEnvelopeFeedback m_NewPolygonFeedback; public override void OnClick() { try { if (frmAttr == null) { frmAttr = new FrmFeatureAttributes(m_hookHelper) { Title = "识别", ResizeMode = System.Windows.ResizeMode.NoResize, WindowStartupLocation = System.Windows.WindowStartupLocation.CenterScreen, Width = 300, Height = 700 }; frmAttr.Closed += FrmAttr_CloseViewHandler; frmAttr.ShowInMainWindow(false); } this.m_NewPolygonFeedback = new NewEnvelopeFeedback() { Display = this.m_hookHelper.ActiveView.ScreenDisplay }; base.OnClick(); } catch (Exception ex) { LogAPI.Debug("点击 查看要素属性 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("点击 查看要素属性 时异常信息结束"); } } private void FrmAttr_CloseViewHandler(object sender, EventArgs e) { frmAttr.CloseViewHandler -= FrmAttr_CloseViewHandler; frmAttr = null; } public override void OnCreate(object hook) { try { if (m_hookHelper == null) { m_hookHelper = new HookHelper(); m_hookHelper.Hook = hook; } } catch (Exception ex) { m_hookHelper = new HookHelper(); m_hookHelper.Hook = null; LogAPI.Debug("初始化 查看要素属性 命令时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("初始化 查看要素属性 命令时异常信息结束"); } } public override void OnDblClick() { base.OnDblClick(); } public override void OnKeyDown(int keyCode, int shift) { base.OnKeyDown(keyCode, shift); } public override void OnKeyUp(int keyCode, int shift) { base.OnKeyUp(keyCode, shift); } public override void OnMouseDown(int button, int shift, int x, int y) { //鼠标左键按下时再去绘制矩形,区分中键按下拖动地图功能,对应bug10406 if (button == 1) { fromPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (m_NewPolygonFeedback != null) { m_NewPolygonFeedback.Start(fromPoint); } } base.OnMouseDown(button, shift, x, y); } public override void OnMouseMove(int button, int shift, int x, int y) { if (button == 1) { toPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); if (m_NewPolygonFeedback != null) { m_NewPolygonFeedback.MoveTo(toPoint); } } base.OnMouseMove(button, shift, x, y); } public override void OnMouseUp(int button, int shift, int x, int y) { try { if (button == 1) { toPoint = m_hookHelper.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y); List layers = MapsManager.Instance.MapService.GetAllVisibleLayerInMap(); IGeometry pGeometry = m_NewPolygonFeedback.Stop(); if (pGeometry == null || pGeometry.IsEmpty) { if (toPoint == null || toPoint.IsEmpty) { return; } pGeometry = toPoint; } Dictionary> features = Identify(pGeometry, layers); if (frmAttr == null) { frmAttr = new FrmFeatureAttributes(m_hookHelper); frmAttr.Title = "识别"; frmAttr.Width = 300; frmAttr.Height = 700; frmAttr.Closed += FrmAttr_CloseViewHandler; frmAttr.ShowInMainWindow(false); } frmAttr.Identify(features); } } catch (Exception ex) { //Common.Utility.LogAPI.Debug(ex); LogAPI.Debug("查看要素属性期间 鼠标抬起 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("查看要素属性期间 鼠标抬起 时异常信息结束"); } base.OnMouseUp(button, shift, x, y); } //[LogWrite(Description = "")] public override bool Deactivate() { if (frmAttr != null) { frmAttr.ClearData();//.RegistSelectionChangedEvent(); } return base.Deactivate(); } public override void Refresh(int hdc) { base.Refresh(hdc); } public override string Tooltip { get { return base.Tooltip; } } /// /// 根据线捕捉要素 /// /// /// /// //[LogWrite(Description = "")] public Dictionary> Identify(IGeometry pGeo, List pLayers, int buffer = 5) { Dictionary> result = new Dictionary>(); IArray geoArray = new ArrayClass(); try { if (pGeo != null && !pGeo.IsEmpty && pLayers != null) { foreach (IFeatureLayer item in pLayers) { //if (!item.Selectable) continue; IIdentify identify = item as IIdentify; if (identify == null) continue; //ITopologicalOperator pTopo = pGeo as ITopologicalOperator; //IGeometry pGeometry = pTopo.Buffer(buffer).Envelope as IGeometry; ESRI.ArcGIS.esriSystem.IArray array = identify.Identify(pGeo); if (array == null) continue; if (array.Count == 0) continue; if (!result.Keys.Contains(item.Name)) { result.Add(item.Name, new List()); } for (int i = 0; i < array.Count; i++) { IRowIdentifyObject row = (IRowIdentifyObject)array.get_Element(i); if (row == null) continue; IFeature f = row.Row as IFeature; result[item.Name].Add(f); if (!f.ShapeCopy.IsEmpty) { geoArray.Add(f.ShapeCopy); } } } if (geoArray.Count > 0) { FlashShapeArray(m_hookHelper, geoArray); } } } catch (Exception ex) { LogAPI.Debug("查看要素属性期间 根据线捕捉要素 时异常,异常信息如下:"); LogAPI.Debug(ex); LogAPI.Debug("查看要素属性期间 根据线捕捉要素 时异常信息结束"); throw ex; } return result; } /// /// 通过IHookActions闪烁要素集合 /// /// /// public static void FlashShapeArray(IHookHelper m_hookHelper, IArray geoArray) { IHookActions hookActions = (IHookActions)m_hookHelper; System.Windows.Forms.Application.DoEvents(); hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsFlash); } } }