private void mSceneControl_OnMouseDown(object sender, ISceneControlEvents_OnMouseDownEvent e) { if (mPointSearch.Checked)//check按钮处于打勾状态 { //查询 mSceneControl.SceneGraph.LocateMultiple(mSceneControl.SceneGraph.ActiveViewer, e.x, e.y, esriScenePickMode.esriScenePickAll, false, out mHit3DSet); mHit3DSet.OnePerLayer(); if (mHit3DSet == null)//没有选中对象 { MessageBox.Show("没有选中对象"); } else { //显示在ResultForm控件中。 mResultForm.Show(); mResultForm.refeshView(mHit3DSet); } mSceneControl.Refresh(); } }
public override void OnMouseDown(int Button, int Shift, int X, int Y) { // TODO: Add ToolEditFeatures.OnMouseDown implementation try { ISceneControl pSceneCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as ISceneControl; if (pSceneCtr != null) { IPoint po; object owner, obj; pSceneCtr.SceneGraph.Locate(pSceneCtr.SceneViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out po, out owner, out obj);//po就是得到的点 //方法2 IHit3DSet pHit3dSet = null; pSceneCtr.SceneGraph.LocateMultiple(pSceneCtr.SceneGraph.ActiveViewer, X, Y, esriScenePickMode.esriScenePickGeography, true, out pHit3dSet); //po = pHit3D.Point;//po就是得到的点 //如果想得到某图层元素,可以看看下面代码 // int index = 2; if (pHit3dSet == null) { return; } pHit3dSet.OnePerLayer(); IHit3D pHit3D = (IHit3D)pHit3dSet.Hits.get_Element(0); IFeature pFeature = (IFeature)pHit3D.Object; if (pFeature == null) { return; } ILayer pLayer = owner as ILayer; if (pLayer == null) { return; } if (pLayer.Name != "Crater" && pLayer.Name != "NonCrater") { return; } IFeatureClass pFeatureClass = ((IFeatureLayer)pLayer).FeatureClass; pSceneCtr.Scene.ClearSelection(); pSceneCtr.Scene.SelectFeature(pLayer, pFeature); IActiveView pActiveView = pSceneCtr.Scene as IActiveView; pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); IMultiPatch pMP = pFeature.Shape as IMultiPatch; FrmEditFeatures.setXLabel((pMP.Envelope.XMax + pMP.Envelope.XMin) / 2); FrmEditFeatures.setYLabel((pMP.Envelope.YMax + pMP.Envelope.YMin) / 2); } IMapControl2 pMapCtr = (((IToolbarControl)m_hookHelper.Hook).Buddy) as IMapControl2; if (pMapCtr != null) { IMap pMap = pMapCtr.Map; IPoint po = pMapCtr.ToMapPoint(X, Y); ISelectionEnvironment pSelectionEnv = new SelectionEnvironmentClass(); pMap.SelectByShape(po, pSelectionEnv, true); //for (int i = 0; i < pMap.LayerCount; i++ ) //{ // ILayer pLayer = pMap.get_Layer(i); // if (pLayer.Name == "Crater") // { // pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); // } // if (pLayer.Name =="NonCrater") // { // pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, pLayer, null); // } //} pMapCtr.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, null, null); IEnumFeatureSetup pSelectionsetup = pMap.FeatureSelection as IEnumFeatureSetup; pSelectionsetup.AllFields = true;//这里是关键 IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature; IFeature pF = pFeatureCollection.Next(); if (pF != null && pF.Shape is IMultiPatch) { IMultiPatch pMP = pF.Shape as IMultiPatch; FrmEditFeatures.setXLabel((pMP.Envelope.XMax + pMP.Envelope.XMin) / 2); FrmEditFeatures.setYLabel((pMP.Envelope.YMax + pMP.Envelope.YMin) / 2); } //ISelection pSelection =pMap.FeatureSelection; ////从Map.FeatureSelection获得ISelection不能读到Feature的其他属性, ////这是因为从axMapControl1.Map.FeatureSelection QI到IEnumFeature 时, ////ArcGIS中FeatureSelection默认的时候只存入Feature 的Shape,而不是整个Feature的字段数据。 ////如果要查看其他数据,必须要进行以下转换才可以: //IEnumFeatureSetup pSelectionsetup = pSelection as IEnumFeatureSetup; //pSelectionsetup.AllFields = true;//这里是关键 //IEnumFeature pFeatureCollection = pSelectionsetup as IEnumFeature; //IFeature pF = pFeatureCollection.Next(); //if (pF != null) //{ // pF.Class //} } } catch (System.Exception ex) { } }