ArcGIS实现移动整个对象

点、线、包络线、多边形整体移动方法相同,也是相应的改变接口和类(MovePointFeedBack、MoveLineFeedBack、MovePolygonFeedBack和MoveEnvelopeFeedBack)
 private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
        {
            IPoint pPt = new PointClass();
            pPt.PutCoords(e.mapX, e.mapY);
            pActiveView=axMapControl1.ActiveView;
 
            double dist = pActiveView.Extent.Width / 100;
            pHitElement = getElement(pPt, dist);
 
            IGeometry pGeometry;
            if (pHitElement != null)
            {
                pGeometry = pHitElement.Geometry;
                if (pGeometry.GeometryType == esriGeometryType.esriGeometryPolyline)
                {
                    pDispLayFeedBack = new MoveLineFeedbackClass();
                    pDispLayFeedBack.Display = pActiveView.ScreenDisplay;
 
                    IMoveLineFeedback pMoveLineFeed;
                    pMoveLineFeed = pDispLayFeedBack as IMoveLineFeedback;
                    pMoveLineFeed.Start(pGeometry as IPolyline, pPt);
                }
            }
        }
        private IElement getElement(IPoint pPt, double dist)
        {
            IEnumElement pEnumElement;
            IElement pEle;
            pGraphicsContainer = axMapControl1.ActiveView as IGraphicsContainer;
            pEnumElement = pGraphicsContainer.LocateElements(pPt, dist);
            if (pEnumElement != null)
            {
                pEle = pEnumElement.Next();
                while (pEle != null)
                {
                    if (pEle.Geometry.GeometryType == esriGeometryType.esriGeometryPolyline)
                    {
                        return pEle;
                    }
                    pEle = pEnumElement.Next();
                }
            }
            return null;
        }
        private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
        {
            IPoint pPt;
            pPt = new PointClass();
            pPt.PutCoords(e.mapX, e.mapY);
            pDispLayFeedBack.MoveTo(pPt);
        }
 
        private void axMapControl1_OnMouseUp(object sender, IMapControlEvents2_OnMouseUpEvent e)
        {
            IGeometry pGeom = null;
            IGeometry pGeomEles;
            if (pHitElement != null)
            {
                pGeomEles = pHitElement.Geometry;
                if (pGeomEles.GeometryType == esriGeometryType.esriGeometryPolyline)
                {
                    IMoveLineFeedback pMvLnFeed;
                    pMvLnFeed = pDispLayFeedBack as IMoveLineFeedback;
                    pGeom = pMvLnFeed.Stop();
                }
                pHitElement.Geometry = pGeom;
                IActiveView pActiveView = axMapControl1.ActiveView;
                IGraphicsContainer pGraphicsContainer = pActiveView as IGraphicsContainer;
                pGraphicsContainer.UpdateElement(pHitElement);
                pActiveView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);
            }
        }
posted @ 2011-09-26 22:57  iskyoole  阅读(1754)  评论(0)    收藏  举报