实现MapObject放大,缩小,平移,全图常用功能

在axMap1的MouseDownEvent事件里加入下面代码

代码
          MapObjects2.Rectangle rect;     //范围
            switch (axMap1.MousePointer)
            {
                //放大
                case MapObjects2.MousePointerConstants.moZoomIn:
                    {                        
                        rect 
= axMap1.TrackRectangle(); //得到鼠标拖动范围
                        
if (rect == null || rect.Width < 0.00005 || rect.Height < 0.00005)  //如果选择区域很小,可以认为是 单击、点选
                        {
                            rect 
= axMap1.Extent;
                            rect.ScaleRectangle(
0.5);   //设置放大比例
                        }
                        axMap1.Extent 
= rect;
                        
break;
                    }

                
//缩小 
                case MapObjects2.MousePointerConstants.moZoomOut:
                    {
                        MapObjects2.Rectangle Tempr;
                        Tempr 
= axMap1.Extent;
                        rect 
= axMap1.TrackRectangle();
                        
double NewSR;
                        
if (rect == null || rect.Width < 0.00005 || rect.Height < 0.00005)
                        {
                            
if (axMap1.Extent.Width / rect.Width > axMap1.Extent.Height / rect.Height)
                            {
                                NewSR 
= axMap1.Extent.Height / rect.Height;
                            }
                            
else
                            {
                                NewSR 
= axMap1.Extent.Width / rect.Width;
                            }
                            Tempr.ScaleRectangle(NewSR);
                        }
                        
else
                        {
                            Tempr.ScaleRectangle(
2.0);   //设置缩小比率
                        }
                        axMap1.Extent 
= Tempr;
                        
break;
                    }
                
//漫游 
                case MapObjects2.MousePointerConstants.moPan:
                    {
                        axMap1.Pan();
                        
break;
                    }
           .
           .
           .

 

这里要设置下鼠标的状态,比如在放大按钮的单击事件下加入:

axMap1.MousePointer = MapObjects2.MousePointerConstants.moZoomIn;   //放大,改变鼠标状态

 

全图:

axMap1.Extent = axMap1.FullExtent;

 

 

posted @ 2010-03-01 12:35  云天  阅读(699)  评论(0编辑  收藏  举报