public IGeometry EndFeatureEdit(int x, int y)
        {
            if (MyfeedBack == null)
            {
                return(null);
            }

            IGeometry geometry = null;
            IPoint    point    = MyMapControl.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);

            if ((MyfeedBack as IMovePointFeedback) != null)
            {
                IMovePointFeedback pointMove = MyfeedBack as IMovePointFeedback;
                geometry = pointMove.Stop() as IGeometry;
            }
            else if ((MyfeedBack as ILineMovePointFeedback) != null)
            {
                ILineMovePointFeedback lineMove = MyfeedBack as ILineMovePointFeedback;
                geometry = lineMove.Stop() as IGeometry;
            }
            else if ((MyfeedBack as IPolygonMovePointFeedback) != null)
            {
                IPolygonMovePointFeedback polyMove = MyfeedBack as IPolygonMovePointFeedback;
                geometry = polyMove.Stop() as IGeometry;
            }
            MyfeedBack = null;
            MyMapControl.ActiveView.PartialRefresh(esriViewDrawPhase.esriViewGeography, MyselectedLayer, null);
            return(geometry);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 完成地图对象编辑,取得编辑后的对象,并将其更新到图层中
        /// 建议在Map.MouseUp事件中调用本方法
        /// </summary>
        public void EditFeatureEnd()
        {
            IGeometry pGeometry;

            try
            {
                if (m_pFeedback == null)
                {
                    return;
                }

                if (m_pFeedback is IMovePointFeedback)
                {
                    IMovePointFeedback pPointMove = (IMovePointFeedback)m_pFeedback;
                    pGeometry = pPointMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is ILineMovePointFeedback)
                {
                    ILineMovePointFeedback pLineMove = (ILineMovePointFeedback)m_pFeedback;
                    pGeometry = pLineMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }
                else if (m_pFeedback is IPolygonMovePointFeedback)
                {
                    IPolygonMovePointFeedback pPolyMove = (IPolygonMovePointFeedback)m_pFeedback;
                    pGeometry = pPolyMove.Stop();
                    UpdateFeature(m_pEditFeature, pGeometry);
                }

                m_pFeedback = null;
//				m_pSelectionTracker = null;
                IActiveView pActiveView = (IActiveView)m_pMap;
                pActiveView.Refresh();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
            }
        }
        private void EditMouseUp(IPoint pPnt)
        {
            IPolygon       pPolyResult;
            IPolyline      pPolylineResult;
            IFeatureCursor pFeatureCursor;
            IFeature       pFeature;
            IFeatureLayer  pFeatLyr = m_EngineEditLayers.TargetLayer;

            //检查编辑的地物
            if (m_editDispFeed != null)
            {
                switch (m_pHitElem.Geometry.GeometryType)
                {
                case esriGeometryType.esriGeometryLine:
                case esriGeometryType.esriGeometryPolyline:
                    pPolylineResult = m_polylineMvPtFeed.Stop();
                    //作有效性检查
                    if ((pPolylineResult != null))
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolylineResult;

                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolylineResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        EditVertexClass.ShowAllVertex(pFeatLyr);
                    }
                    break;

                case esriGeometryType.esriGeometryPolygon:
                case esriGeometryType.esriGeometryEnvelope:
                    //得到反馈的结果
                    pPolyResult = m_polyMvPtFeed.Stop();
                    //作有效性检查
                    if (pPolyResult != null)
                    {
                        //更新元素
                        m_pHitElem.Geometry = pPolyResult;
                        //获取选中的地物
                        pFeatureCursor = MapManager.GetSelectedFeatures(pFeatLyr);
                        if (pFeatureCursor == null)
                        {
                            return;
                        }
                        pFeature = pFeatureCursor.NextFeature();
                        m_EngineEditor.StartOperation();
                        //更新要素形状
                        pFeature.Shape = pPolyResult;
                        pFeature.Store();
                        //停止编辑
                        m_EngineEditor.StopOperation("MoveVertex");
                        if (pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolygon ||
                            pFeature.Shape.GeometryType == esriGeometryType.esriGeometryPolyline)
                        {
                            EditVertexClass.ShowAllVertex(pFeatLyr);
                        }
                    }
                    IFeature pTempParcel;
                    //定义存储多边形要素的局部变量
                    IPoint pDestPoint;
                    //定义节点移动的目标位置
                    pDestPoint = pPnt;
                    IZAware pZAware = pDestPoint as IZAware;
                    pZAware.ZAware = true;
                    pDestPoint.Z   = 0;
                    //所有包含该节点的多边形都进行操作
                    for (int i = 0; i <= EditVertexClass.m_featArray.Count - 1; i++)
                    {
                        pTempParcel = EditVertexClass.m_featArray.get_Element(i) as IFeature;
                        //记录节点序号
                        int pIndex = 0;
                        pIndex = EditVertexClass.GetVertexIndex(m_fromPoint, pTempParcel.Shape);
                        if (!(pIndex == -2))
                        {
                            ITopologicalOperator pTopoOpt         = default(ITopologicalOperator);
                            IPolygon             pPolygon         = default(IPolygon);
                            IPointCollection     pPolygonPointCol = default(IPointCollection);
                            pPolygonPointCol = pTempParcel.ShapeCopy as IPointCollection;
                            pPolygonPointCol.UpdatePoint(pIndex, pDestPoint);
                            pPolygon = pPolygonPointCol as IPolygon;
                            pPolygon.Close();
                            pTopoOpt = pPolygon as ITopologicalOperator;
                            pTopoOpt.Simplify();
                            pTempParcel.Shape = pPolygon;
                            pTempParcel.Store();
                        }
                    }
                    EditVertexClass.m_featArray.RemoveAll();
                    break;
                }

                //释放内存
                m_polyMvPtFeed     = null;
                m_polylineMvPtFeed = null;
                m_editDispFeed     = null;
                m_pHitElem         = null;
                //刷新地图
                m_activeView.Refresh();
            }
        }