AE三维点击查询(3D Identify)的实现,类似ArcGIS的Identify对话框
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Function: 三维点击查询 3D Identify
// Copyright © 天下无双之dxcgis
// 2008-5-8 于岳麓山下。
主窗体中的代码:
// 在主窗体中定义一个frmIdentify窗体类的对象
frmIdentify m_frmIdentify = new frmIdentify();
// SceneControl1的MouseDown 事件中添加代码
private void axSceneControl1_OnMouseDown(object sender, ISceneControlEvents_OnMouseDownEvent e)
{
//三维查询
axSceneControl1.SceneGraph.IsNavigating = false;
IHit3DSet pHit3DSet;
axSceneControl1.SceneGraph.LocateMultiple(axSceneControl1.SceneGraph.ActiveViewer,
e.x, e.y, esriScenePickMode.esriScenePickAll, false, out pHit3DSet);
pHit3DSet.OnePerLayer();
if (pHit3DSet.Hits.Count == 0)
{
MessageBox.Show("当前点未能查找到任何要素");
return;
}
IDisplay3D pDisplay3D = (IDisplay3D)axSceneControl1.Scene.SceneGraph;//用于高亮显示要素
//显示信息窗体
m_frmIdentify.listBox1.Items.Clear();
m_frmIdentify.listView1.Items.Clear();
m_frmIdentify.pHit3DSet = pHit3DSet;
m_frmIdentify.pDisplay3D = pDisplay3D;
m_frmIdentify.InitData();
m_frmIdentify.Location = System.Windows.Forms.Cursor.Position; //获得当前鼠标的屏幕坐标
m_frmIdentify.Show();
m_frmIdentify.Focus();
}
3D Identify 窗体(frmIdentify)的代码:
public partial class frmIdentify : Form
{
public IHit3DSet pHit3DSet;
public IDisplay3D pDisplay3D;
public frmIdentify()
{
InitializeComponent();
}
private void frmIdentify_Load(object sender, EventArgs e)
{
}
private void btnHide_Click(object sender, EventArgs e)
{
this.Hide();
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
listView1.Items.Clear();//消除 listView1 的内容
IHit3D pHit3D = (IHit3D)pHit3DSet.Hits.get_Element(listBox1.SelectedIndex);
IFeature pFeature = (IFeature)pHit3D.Object;
for (int j = 0; j < pFeature.Fields.FieldCount; j++)
{
ListViewItem li = new ListViewItem();
li.SubItems.Clear();
li.SubItems[0].Text = pFeature.Fields.get_Field(j).Name;
li.SubItems.Add(pFeature.get_Value(j).ToString());
listView1.Items.Add(li);
}
//pDisplay3D.AddFlashFeature(pFeature.Shape);
pDisplay3D.FlashGeometry(pHit3D.Owner,pHit3D.Object);
}
//自己添加的方法,用以初始化窗体。
public void InitData()
{
listBox1.Items.Clear();//消除 listBox1 的内容
listView1.Items.Clear();//消除 listView1 的内容
if (pHit3DSet == null)
return;
for (int i = 0; i < pHit3DSet.Hits.Count; )
{
IHit3D pHit3D = (IHit3D)pHit3DSet.Hits.get_Element(i);
IPoint pPoint = pHit3D.Point;
//if (pPoint.IsEmpty)
// return;
ILayer pLayer = (ILayer)pHit3D.Owner;
//判断是否为要素图层
if (pLayer is IFeatureLayer)
{
IFeature pFeature = (IFeature)pHit3D.Object;
listBox1.Items.Add(pLayer.Name);//在列表中添加图层名
//for (int j = 0; j < pFeature.Fields.FieldCount; j++)
// strHits += "
:" + pFeature.Fields.get_Field(j).Name + pFeature.get_Value(j).ToString();
pDisplay3D.AddFlashFeature(pFeature.Shape);
i++; //计数i加1
}
else
{
//不是要素层就从pHit3DSet中删去,因删除后总数减1,计数i不加1
pHit3DSet.Hits.Remove(i);
}
}
pDisplay3D.FlashFeatures();
}
}
转自ESRI官论坛的dxcGIS