You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
266 lines
10 KiB
266 lines
10 KiB
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.Platform; |
|
using KGIS.Framework.Utils; |
|
using KGIS.Framework.Utils.Model; |
|
using KGIS.Framework.Views; |
|
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 ControlsIdentifyToolClass : BaseMapMenuCommand |
|
{ |
|
//private IHookHelper m_hookHelper; |
|
//IPoint fromPoint = null; |
|
//IPoint toPoint = null; |
|
FrmFeatureAttribute frmAttr = null; |
|
private INewEnvelopeFeedback m_NewPolygonFeedback; |
|
private IEngineEditor m_Editor; |
|
public override void OnClick() |
|
{ |
|
try |
|
{ |
|
if (frmAttr == null) |
|
{ |
|
frmAttr = new FrmFeatureAttribute(m_hookHelper); |
|
frmAttr.CloseViewHandler += FrmAttr_CloseViewHandler; |
|
} |
|
frmAttr.ShowPanel(); |
|
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; |
|
} |
|
if (m_Editor == null) |
|
m_Editor = new EngineEditorClass(); |
|
} |
|
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); |
|
// //IPolyline line = new PolylineClass(); |
|
// //line.FromPoint = fromPoint; |
|
// //line.ToPoint = toPoint; |
|
// //.SpatialReference = m_hookHelper.FocusMap.SpatialReference; |
|
// List<IFeatureLayer> layers = MapsManager.Instance.MapService.GetAllVisibleLayerInMap<IFeatureLayer>(); |
|
// IGeometry pGeometry = m_NewPolygonFeedback.Stop(); |
|
// if (pGeometry == null || pGeometry.IsEmpty) |
|
// { |
|
// if (toPoint == null || toPoint.IsEmpty) |
|
// { |
|
// return; |
|
// } |
|
// pGeometry = toPoint; |
|
// } |
|
// Dictionary<string, List<IFeature>> features = Identify(pGeometry, layers); |
|
// if (frmAttr == null) |
|
// { |
|
// frmAttr = new FrmFeatureAttribute(m_hookHelper); |
|
// frmAttr.CloseViewHandler += FrmAttr_CloseViewHandler; |
|
// frmAttr.ShowPanel(); |
|
// } |
|
// 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; |
|
// } |
|
//} |
|
|
|
/// <summary> |
|
/// 根据线捕捉要素 |
|
/// </summary> |
|
/// <param name="pPoint"></param> |
|
/// <param name="pLayers"></param> |
|
/// <returns></returns> |
|
//[LogWrite(Description = "")] |
|
public Dictionary<string, List<IFeature>> Identify(IGeometry pGeo, List<IFeatureLayer> pLayers, int buffer = 5) |
|
{ |
|
Dictionary<string, List<IFeature>> result = new Dictionary<string, List<IFeature>>(); |
|
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<IFeature>()); |
|
} |
|
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 (result.Count > 0) |
|
// break; |
|
} |
|
if (geoArray.Count > 0) |
|
{ |
|
FlashShapeArray(m_hookHelper, geoArray); |
|
} |
|
} |
|
} |
|
catch (Exception ex) |
|
{ |
|
LogAPI.Debug("查看要素属性期间 根据线捕捉要素 时异常,异常信息如下:"); |
|
LogAPI.Debug(ex); |
|
LogAPI.Debug("查看要素属性期间 根据线捕捉要素 时异常信息结束"); |
|
|
|
throw ex; |
|
} |
|
return result; |
|
} |
|
|
|
/// <summary> |
|
/// 通过IHookActions闪烁要素集合 |
|
/// </summary> |
|
/// <param name="m_hookHelper"></param> |
|
/// <param name="geoArray"></param> |
|
public static void FlashShapeArray(IHookHelper m_hookHelper, IArray geoArray) |
|
{ |
|
IHookActions hookActions = (IHookActions)m_hookHelper; |
|
//hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsPan); |
|
//hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsGraphic); |
|
//hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsZoom); |
|
System.Windows.Forms.Application.DoEvents(); |
|
//m_hookHelper.ActiveView.ScreenDisplay.UpdateWindow(); |
|
hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsFlash); |
|
} |
|
|
|
public override bool Enabled |
|
{ |
|
get |
|
{ |
|
return m_Editor.EditState != esriEngineEditState.esriEngineStateNotEditing ? true : false; |
|
} |
|
} |
|
} |
|
|
|
}
|
|
|