天天看点

基于C#的ArcEngine二次开发56:双击属性表跳转目标要素

代码思路:

  • 获取要素的objectID,根据ID选出要素
  • 通过IHookActions闪烁要素

源代码:

private void LocatePoint(DataGridViewCellEventArgs e)
        {
            int rowNO = e.RowIndex;
            if (rowNO >= 0)
            {
                int TowerObjectID = int.Parse(this.dataGridView.Rows[rowNO].Cells[0].Value.ToString());
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "TowerObjectID=" + TowerObjectID;
                IFeatureCursor pFeatureCursor = _pFeatureLayerTower.Search(pQueryFilter, false);
                IFeature pFeature = pFeatureCursor.NextFeature();
                if (pFeature != null)
                {
                    IArray geoArray = new ArrayClass();
                    geoArray.Add(pFeature.ShapeCopy);
                    //通过IHookActions闪烁要素集合 
                    HookHelperClass m_pHookHelper = new HookHelperClass();
                    m_pHookHelper.Hook = this.mapContainer.MapControl.Object;
                    IHookActions hookActions = (IHookActions)m_pHookHelper;
 
                    hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsPan);
                    //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsGraphic);
                    //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsZoom);
                    //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsCallout); 
                    Application.DoEvents();
                    m_pHookHelper.ActiveView.ScreenDisplay.UpdateWindow();
                    IPoint pPointLeft = new PointClass();
                    pPointLeft.PutCoords(this.mapContainer.MapControl.Extent.XMin, (this.mapContainer.MapControl.Extent.YMax + this.mapContainer.MapControl.Extent.YMin) / 2);
                    IPoint pPointRight = new PointClass();
                    pPointRight.PutCoords(this.mapContainer.MapControl.Extent.XMax, (this.mapContainer.MapControl.Extent.YMax + this.mapContainer.MapControl.Extent.YMin) / 2);
                    IPoint pPointUpper = new PointClass();
                    pPointUpper.PutCoords((this.mapContainer.MapControl.Extent.XMin + this.mapContainer.MapControl.Extent.XMax) / 2, this.mapContainer.MapControl.Extent.YMax);
                    IPoint pPointLower = new PointClass();
                    pPointLower.PutCoords((this.mapContainer.MapControl.Extent.XMin + this.mapContainer.MapControl.Extent.XMax) / 2, this.mapContainer.MapControl.Extent.YMin);
                    DrawLocateLine(pPointLeft, pFeature.Shape as IPoint);
                    DrawLocateLine(pPointRight, pFeature.Shape as IPoint);
                    DrawLocateLine(pPointUpper, pFeature.Shape as IPoint);
                    DrawLocateLine(pPointLower, pFeature.Shape as IPoint);
                    hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsFlash);
                  
 
                }
            }
            
        }
 
        private void DrawLocateLine(IPoint FromPoint ,IPoint ToPoint)
        {
            object o = Type.Missing;
            IPointCollection pPointCollection = new PolylineClass();
 
            pPointCollection.AddPoint(FromPoint, ref o, ref o);
            pPointCollection.AddPoint(ToPoint, ref o, ref o);
            IPolyline polyline = pPointCollection as IPolyline;
            DrawLine(polyline);
        }

        private void DrawPoint(IPoint pPoint)
        {
            
            ISimpleMarkerSymbol pMarkerSymbolTower = new SimpleMarkerSymbolClass();
            pMarkerSymbolTower.Size = 8;
            pMarkerSymbolTower.Outline = true;
            pMarkerSymbolTower.OutlineColor = (IColor)ESRI.ArcGIS.ADF.Converter.ToRGBColor(Color.Green);
            pMarkerSymbolTower.Style = esriSimpleMarkerStyle.esriSMSCircle;
 
            pMarkerSymbolTower.Color = (IColor)ESRI.ArcGIS.ADF.Converter.ToRGBColor(Color.Green);
            object o = (object)pMarkerSymbolTower;
            IGeometry pGeometry;
            pGeometry = pPoint as IGeometry;
 
            this.mapContainer.MapControl.DrawShape(pGeometry, ref o);
            
        }

        private void DrawLine(IPolyline polyline)
        {            
            ILineSymbol pLS = new SimpleLineSymbolClass();
            pLS.Width = 3;
            pLS.Color = (IColor)ESRI.ArcGIS.ADF.Converter.ToRGBColor(Color.Green);
            object o = (object)pLS;
            IGeometry pGeometry;
            pGeometry = polyline as IGeometry;
           
            this.mapContainer.MapControl.DrawShape(pGeometry,ref o);            
        }
        
}