1. 程式人生 > >AE編輯-顯示、增加、刪除節點

AE編輯-顯示、增加、刪除節點

高亮顯示節點

   //高亮顯示節點和端點

        public void HighLightNode()

        {

            //清空

            _mapCtrl.Map.ClearSelection();

            _mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeoSelection, null, _mapCtrl.ActiveView.Extent);

            var pGraphicsContainer = _mapCtrl.Map as

 IGraphicsContainer;

            pGraphicsContainer.DeleteAllElements();

            _mapCtrl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);

            //增加

            ISimpleFillSymbol simpleFillSymbol = new SimpleFillSymbolClass();

            ISimpleLineSymbol

 simpleLineSymbol = new SimpleLineSymbolClass

            {

                Color = new RgbColorClass { Red = 255, Green = 0, Blue = 0 },

                Width = 2,

                Style = esriSimpleLineStyle.esriSLSSolid

            };

            ISimpleMarkerSymbol simpleMarkerSymbol = new SimpleMarkerSymbolClass

            {

                Color =

                    new RgbColorClass { Red = 255, Green = 0, Blue = 0 },

                Style = esriSimpleMarkerStyle.esriSMSCircle,

                Size = 5

            };

            switch (currentFeature.Shape.GeometryType)

            {

                case esriGeometryType.esriGeometryPoint:

                    //IMarkerElement pMarkerElement = new MarkerElementClass();

                    //pMarkerElement.Symbol = simpleMarkerSymbol;

                    //var pEla = pMarkerElement as IElement;

                    //pEla.Geometry = currentFeature.Shape;

                    //var pActiveView = _mapCtrl.ActiveView;

                    //var pGraphicsContainer = _mapCtrl.Map as IGraphicsContainer;

                    //pGraphicsContainer.AddElement(pEla, 0);

                    //pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);

                    break;

                case esriGeometryType.esriGeometryPolyline:

                    ILineElement pLineElement = new LineElementClass();

                    pLineElement.Symbol = simpleLineSymbol;

                    var pEla1 = pLineElement as IElement;

                    pEla1.Geometry = currentFeature.Shape;

                    var pActiveView1 = _mapCtrl.ActiveView;

                    var pGraphicsContainer1 = _mapCtrl.Map as IGraphicsContainer;

                    pGraphicsContainer1.AddElement(pEla1, 0);

                    pActiveView1.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);

                    break;

                case esriGeometryType.esriGeometryPolygon:

                    IPolygonElement pPolygonElement = new PolygonElementClass { Symbol = simpleFillSymbol };

                    var pEla2 = pPolygonElement as IElement;

                    pEla2.Geometry = currentFeature.Shape;

                    var pActiveView2 = _mapCtrl.ActiveView;

                    var pGraphicsContainer2 = _mapCtrl.Map as IGraphicsContainer;

                    pGraphicsContainer2.AddElement(pEla2, 0);

                    pActiveView2.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _mapCtrl.ActiveView.Extent);

                    break;

            }

            //顯示節點

            //step1:建立節點符號

            ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();

            pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;

            pVertexMarkerSymbol.Size = 3;

            pVertexMarkerSymbol.Angle = 0;

            IRgbColor rgbVertex = new RgbColorClass();

            rgbVertex.Green = 255;

            pVertexMarkerSymbol.Color = rgbVertex;

            ISimpleMarkerSymbol pEndPointMarkerSymbol = new SimpleMarkerSymbol();

            pEndPointMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;

            pEndPointMarkerSymbol.Size = 4;

            pEndPointMarkerSymbol.Angle = 0;

            IRgbColor rgbEndPoint = new RgbColorClass();

            rgbEndPoint.Red = 255;

            pEndPointMarkerSymbol.Color = rgbEndPoint;

            //D斷要素的型別

            if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)

            {

                IGeometryCollection pGeoColl;

                ISegmentCollection pSegColl;

                ISegment pSegment;

                IPath path;

                IPointCollection pEndPointCol;

                IMultipoint pEndPoints;

                IPoint pEndPoint;

                pEndPoints = new MultipointClass();

                pEndPointCol = pEndPoints as IPointCollection;

                pGeoColl = currentFeature.Shape as IGeometryCollection;

                for (int i = 0; i < pGeoColl.GeometryCount; i++)

                {

                    pSegColl = pGeoColl.get_Geometry(i) as ISegmentCollection;

                    path = pGeoColl.get_Geometry(i) as IPath;

                    pEndPointCol.AddPoint(path.FromPoint);

                    pEndPointCol.AddPoint(path.ToPoint);

                    for (int j = 0; j < pSegColl.SegmentCount; j++)

                    {

                        pSegment = pSegColl.get_Segment(j);

                        //show vertex

                        AddPointSymbolToMap(pSegment.FromPoint, pVertexMarkerSymbol);

                        AddPointSymbolToMap(pSegment.ToPoint, pVertexMarkerSymbol);

                    }

                }

                //show endpoint

                for (int k = 0; k < pEndPointCol.PointCount; k++)

                {

                    pEndPoint = pEndPointCol.get_Point(k);

                    AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);

                }

            }

            else if (currentFeature.Shape.GeometryType == esriGeometryType.esriGeometryPoint)

            {

                IPoint pEndPoint;

                pEndPoint = currentFeature.Shape as IPoint;

                AddPointSymbolToMap(pEndPoint, pEndPointMarkerSymbol);

            }

        }

新增節點

OnMouseDown事件:

IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as IProximityOperator;

                        ptInsert = proximityOperator.ReturnNearestPoint(pPt, esriSegmentExtension.esriNoExtension);

                        //step1: 建立節點符號

                        ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();

                        pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;

                        pVertexMarkerSymbol.Size = 3;

                        pVertexMarkerSymbol.Angle = 0;

                        IRgbColor rgbVertex = new RgbColorClass();

                        rgbVertex.Green = 255;

                        pVertexMarkerSymbol.Color = rgbVertex;

                        //step2: 顯示在地圖上

                        IMarkerElement pMarkerElement = new MarkerElementClass();

                        pMarkerElement.Symbol = pVertexMarkerSymbol;

                        var pEla = pMarkerElement as IElement;

                        pEla.Geometry = ptInsert as IGeometry;

                        pGraphicContainer.AddElement(pEla, 0);

                        pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);

OnMouseUp事件,新增一個節點,但不打斷線:

// 注意:如果第三個引數createPart設為true,線會被打斷,不可取

                            //?splitAtPoint

                            bool isSplitted;

                            int newPartIndex;

                            int newSegmentIndex;

                            IPolyline polyline = ucDrawPanel.currentFeature.Shape as IPolyline;

                            //插入一點,newSegmentIndex記錄插入點的相對線的節點位置

                            polyline.SplitAtPoint(ptInsert, truefalseout isSplitted, out newPartIndex, outnewSegmentIndex);

                            ucDrawPanel.currentFeature.Store();

刪除節點

OnMouseDown事件:

//step1:獲取預刪除的節點

                        IPolyline pPolyline;

                        IHitTest pHitTest;

                        bool BoolHitTest;

                        double dist = 0;

                        double DbHitDis = 0;

                        int LngPrtIdx = 0;

                        bool BoolHitRt = false;

                        hitElement = getElement(pPt, esriGeometryType.esriGeometryPolyline);

                        if (hitElement != null)

                        {

                            pPolyline = hitElement.Geometry as IPolyline;

                            pHitTest = pPolyline as IHitTest;

                            ptDelete = new PointClass();

                            BoolHitTest = pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,

                                                           esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,                                                           ref DbHitDis, ref LngPrtIdx, ref indexDelete,ref BoolHitRt);

                            // pHitTest.HitTest(pPt, pActiveView.Extent.Width / 100,esriGeometryHitPartType.esriGeometryPartVertex, ptDelete,ref DbHitDis, ref LngPrtIdx, ref LngSegIdx, ref BoolHitRt);

                            if (BoolHitTest)

                            {

                                //step2:?亮顯示,符號黑色邊框鏤空填充

                                ISimpleMarkerSymbol pVertexMarkerSymbol = new SimpleMarkerSymbolClass();

                                pVertexMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;

                                pVertexMarkerSymbol.Size = 5;

                                pVertexMarkerSymbol.Angle = 0;

                                IRgbColor rgbVertex = new RgbColorClass();

                                rgbVertex.Red = 0;

                                rgbVertex.Blue = 0;

                                rgbVertex.Green = 0;

                                pVertexMarkerSymbol.Color = rgbVertex;

                                IMarkerElement pMarkerElement = new MarkerElementClass();

                                pMarkerElement.Symbol = pVertexMarkerSymbol;

                                var pEla = pMarkerElement as IElement;

                                pEla.Geometry = ptDelete as IGeometry;

                                pGraphicContainer.AddElement(pEla, 0);

                                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, pActiveView.Extent);

                            }

                        }

OnMouseUp事件,刪除節點:

IPointCollection pointCollection = ucDrawPanel.currentFeature.Shape as IPointCollection;

                            pointCollection.RemovePoints(indexDelete, 1);

                            IPolyline polylineNew = pointCollection as IPolyline;

                            StoreFeatureGeometry(ucDrawPanel.currentFeature, polylineNew);

儲存圖形要素:

     private bool StoreFeatureGeometry(IFeature pFeature, IGeometry pIGeometry)

        {

            try

            {

                var pFeatureClass = pFeature.Class as IFeatureClass;

                var pDataset = pFeatureClass as IDataset;

                IWorkspace pWorkspace = pDataset.Workspace;

                var pWorkspaceEdit = pWorkspace as IWorkspaceEdit;

                pWorkspaceEdit.StartEditing(false);

                pWorkspaceEdit.StartEditOperation();

                pFeature.Shape = pIGeometry;

                pFeature.Store();

                pWorkspaceEdit.StopEditOperation();

                pWorkspaceEdit.StopEditing(true);

                return true;

            }

            catch (Exception ex)

            {

                return false;

            }

        }

線的打斷

關鍵字:Split

OnMouseDown事件:

IProximityOperator proximityOperator = ucDrawPanel.currentFeature.Shape as