AE实现右键点击TOC控件任意图层显示属性表
2013-11-07 21:05
681 查看
private void axTOCControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.ITOCControlEvents_OnMouseDownEvent
e)
{
if (e.button
== 2)
{
esriTOCControlItem Item =
new esriTOCControlItem();
IBasicMap pMap =
new MapClass();
ILayer pLayer =
new FeatureLayerClass();
object pOther
= new
object();
object pIndex
= new
object();
this.axTOCControl1.HitTest(e.x, e.y,
ref Item,
ref pMap, ref pLayer,
ref pOther,
ref pIndex);
IMapControl2 pMapControl = (IMapControl2)axMapControl1.Object;
IFeatureLayer pFeatureLayer = pLayer
as IFeatureLayer;
FrmAttribute pFemAttribute =
new FrmAttribute(pMapControl, pFeatureLayer.Name);
pFemAttribute.Show();
}
}
其中用到的AxTOCControl.HitTest(e.x, e.y, pItem, pMap, pLayer, pOther, pIndex)方法,主要用于获得当前鼠标点击的图层,pItem, pMap, pLayer, pOther, pIndex几个参数均带ref关键字,返回e.x,e.y位置项所关联的对象,即图层,标注等。
在属性表窗口的代码:
View
Code
e)
{
if (e.button
== 2)
{
esriTOCControlItem Item =
new esriTOCControlItem();
IBasicMap pMap =
new MapClass();
ILayer pLayer =
new FeatureLayerClass();
object pOther
= new
object();
object pIndex
= new
object();
this.axTOCControl1.HitTest(e.x, e.y,
ref Item,
ref pMap, ref pLayer,
ref pOther,
ref pIndex);
IMapControl2 pMapControl = (IMapControl2)axMapControl1.Object;
IFeatureLayer pFeatureLayer = pLayer
as IFeatureLayer;
FrmAttribute pFemAttribute =
new FrmAttribute(pMapControl, pFeatureLayer.Name);
pFemAttribute.Show();
}
}
其中用到的AxTOCControl.HitTest(e.x, e.y, pItem, pMap, pLayer, pOther, pIndex)方法,主要用于获得当前鼠标点击的图层,pItem, pMap, pLayer, pOther, pIndex几个参数均带ref关键字,返回e.x,e.y位置项所关联的对象,即图层,标注等。
在属性表窗口的代码:
View
Code
public partial class FrmAttribute : Form { public IMapControl2 pMapControl; public IMap pMap; public int LayerIndex; public string LayerName; public FrmAttribute(IMapControl2 pMapControl,string LyrName) { InitializeComponent(); this.pMapControl = pMapControl; pMap = pMapControl.Map; LayerName = LyrName; } private void FrmAttribute_Load(object sender, EventArgs e) { GetValues(); } public void GetValues() { for (int i = 0; i < pMap.LayerCount; i++) { if (LayerName == pMap.get_Layer(i).Name) { LayerIndex = i; break; } } IFeatureLayer pFeatureLayer = pMap.get_Layer(LayerIndex) as IFeatureLayer; IFields pFields = pFeatureLayer.FeatureClass.Fields; dataGridView1.ColumnCount = pFields.FieldCount; for (int i = 0; i < pFields.FieldCount; i++) { string fieldname; fieldname = pFields.get_Field(i).Name; dataGridView1.Columns[i].Name = fieldname; } IFeatureCursor pFeatureCursor = pFeatureLayer.FeatureClass.Search(null, false); IFeature pFeature = pFeatureCursor.NextFeature(); while (pFeature != null) { string[] fldvalue=new string[pFields.FieldCount]; for (int i = 0; i < pFields.FieldCount; i++) { if (pFields.get_Field(i).Name == "Shape") { fldvalue[i] = Convert.ToString(pFeature.Shape.GeometryType); } else { fldvalue[i] = Convert.ToString(pFeature.get_Value(i)); } } dataGridView1.Rows.Add(fldvalue); pFeature = pFeatureCursor.NextFeature(); } } private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e) { string FID; FID =dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString(); if (FID == "") return; IActiveView pActiveView; pActiveView = (IActiveView)pMap; pMap.ClearSelection(); pActiveView.Refresh(); IQueryFilter pQueryFilter = new QueryFilterClass(); pQueryFilter.WhereClause = "FID=" + FID; IFeatureLayer pFeatureLayer; pFeatureLayer = (IFeatureLayer)pMap.get_Layer(LayerIndex); IFeatureCursor pFeatureCursor; pFeatureCursor = pFeatureLayer.Search(pQueryFilter, false); IFeature pFeature; pFeature = pFeatureCursor.NextFeature(); pMap.SelectFeature(pFeatureLayer, pFeature); IPoint pPoint = new PointClass(); pPoint.X = (pFeature.Extent.XMin + pFeature.Extent.XMax) / 2; pPoint.Y = (pFeature.Extent.YMin + pFeature.Extent.YMax) / 2; pMapControl.CenterAt(pPoint); pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, null); } }
相关文章推荐
- AE实现右键点击TOC控件任意图层显示属性表
- C#+AE 调整TOCControl控件中图层的显示顺序
- 鼠标在slide控件的任意位置上点击,滑块滑动到该位置是如何实现的,有什么属性吗?
- 控件显示之后,点击其他位置隐藏的实现
- 实现自定义android柱状图控件!可显示气温!可相应点击事件的回调!
- Android 点击按钮实现控件显示隐藏
- 写一个HTML页面,实现以下功能,左键点击页面时显示“您好”,右键点击时显示“禁止右键”。并在2秒钟后自动关闭页面
- C# 用ToolStripDropDown实现任意Windows控件弹出显示
- ae+C#实现图层管理控件上的图层移动功能
- [置顶] 利用photoView实现可点击放大到全屏显示的控件,效果类似于微信朋友圈点开看大图
- 显示栅格图层和矢量图层的属性表(AE开发)
- TocControl图层控件不显示图层的问题
- 将图层属性表的信息显示在DataGridView的控件上
- 巧用DBGrid控件的Sort属性实现“点击标题栏自动排序功能”。(改进版本)
- 分级渲染图层后更新TOC控件显示效果
- js实现点击某个控件并在附近显示一个层
- 巧用DBGrid控件的Sort属性实现“点击标题栏自动排序功能”
- 网络请求加载控件的简单实现,能显示加载中、没网络、加载失败点击重新加载等状态
- TextView属性android:ellipsize实现跑马灯效果,TextView内容过长加省略号,点击显示全部内容
- pushbutton成为可点击的图标(实现全透明,不论点击与否都只显示Icon)(也就是一个万能控件)