Map3D中获取地图中心及Zoom到新的中心点

如题,不更改当前比例尺,把指定点Zoom到地图中心。

 

        Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

        [CommandMethod("ZoomCenter")]
        public void ZoomCenter()
        {
            AcMapMap map = AcMapMap.GetCurrentMap();
            MgEnvelope mapExtent = map.GetMapExtent();

            double centerX = mapExtent.LowerLeftCoordinate.X + mapExtent.Width / 2;
            double centerY = mapExtent.LowerLeftCoordinate.Y + mapExtent.Height / 2;

            ed.WriteMessage("center:"+centerX.ToString()+","+centerY.ToString()+"\n");

            Point3d centerPt;
            PromptPointOptions ppo = new PromptPointOptions("Click on map to zoom center:");
            PromptPointResult ppr = ed.GetPoint(ppo);
            if (ppr.Status == PromptStatus.OK)
            {
                centerPt = ppr.Value;

                MgEnvelope newExtent = new MgEnvelope(centerPt.X - mapExtent.Width / 2,
                                                                    centerPt.Y - mapExtent.Height / 2,
                                                                    centerPt.X + mapExtent.Width / 2,
                                                                    centerPt.Y + mapExtent.Height / 2);

                map.ZoomToExtent(newExtent);
            }

        }

 


Related Posts Plugin for WordPress, Blogger...