基于ArcGIS Engine地图操作的基本功能实现

1)移动地图代码
axMapControl1.Pan();
2)拉框放大地图代码
axMapControl1.Extent = axMapControl1.TrackRectangle();
3)拉框缩小地图代码
double newMapExtentWidth;
                double newMapExtentHeight;
                double newMapExtentXmin;
                double newMapExtentYmin;
                double newMapExtentXmax;
                double newMapExtentYmax;
                double zoomInWidthFactor;
                double zoomInHeightFactor;
                IEnvelope pDrawRectangle;
                IEnvelope pNewEnvelope;
                IEnvelope pCurrentExtent;
                pDrawRectangle = axMapControl1.TrackRectangle();
                pNewEnvelope = new EnvelopeClass();
                pCurrentExtent = axMapControl1.Extent;
                if (pDrawRectangle.IsEmpty ==false)
                {
                 if ((pDrawRectangle.Width != 0) &&(pDrawRectangle.Height!=0))
                    {
                zoomInWidthFactor = pCurrentExtent.Width / pDrawRectangle.Width;
                zoomInHeightFactor = pCurrentExtent.Height / pDrawRectangle.Height;
                newMapExtentWidth = pCurrentExtent.Width * zoomInWidthFactor;
                newMapExtentHeight = pCurrentExtent.Height * zoomInHeightFactor;
                newMapExtentXmin = pCurrentExtent.XMin - (pDrawRectangle.XMin - pCurrentExtent.XMin) * zoomInWidthFactor;
                newMapExtentYmin = pCurrentExtent.YMin - (pDrawRectangle.YMin - pCurrentExtent.YMin) *zoomInHeightFactor;
                newMapExtentXmax = newMapExtentXmin + newMapExtentWidth;
                newMapExtentYmax = newMapExtentYmin + newMapExtentHeight;
                pNewEnvelope.PutCoords(newMapExtentXmin, newMapExtentYmin, newMapExtentXmax, newMapExtentYmax);
                    }
                }
                axMapControl1.Extent = pNewEnvelope;
4)中心放大地图代码
IEnvelope pEnvelope;
pEnvelope = axMapControl1.Extent;
pEnvelope.Expand(0.5, 0.5, true);
axMapControl1.Extent = pEnvelope;
5)中心缩小地图代码
   IEnvelope pEnvelope;
   pEnvelope = axMapControl1.Extent;
   pEnvelope.Expand(2, 2, true);
   axMapControl1.Extent = pEnvelope;
6)全图显示
axMapControl1.Extent = axMapControl1.FullExtent;
7)历史视图切换代码
①前一视图代码
if(axMapControl1.ActiveView.ExtentStack.CanUndo())
  {
    axMapControl1.ActiveView.ExtentStack.Undo();
  }
②后一视图代码
if(axMapControl1.ActiveView.ExtentStack.CanRedo())
  {
    axMapControl1.ActiveView.ExtentStack.Redo();
  }

移动地图和放大缩小会遇到从按钮开始的情况采用以下的办法解决

int x = 0;
private void fun()
        {
            if (x == 3)
            {
                axMapControl1.Extent = axMapControl1.TrackRectangle();
            }
            if (x == 2)
            {
                axMapControl1.Pan();
            }
            if (x == 5)
            {
                double newMapExtentWidth;
                double newMapExtentHeight;
                double newMapExtentXmin;
                double newMapExtentYmin;
                double newMapExtentXmax;
                double newMapExtentYmax;
                double zoomInWidthFactor;
                double zoomInHeightFactor;
                IEnvelope pDrawRectangle;
                IEnvelope pNewEnvelope;
                IEnvelope pCurrentExtent;
                pDrawRectangle = axMapControl1.TrackRectangle();
                pNewEnvelope = new EnvelopeClass();
                pCurrentExtent = axMapControl1.Extent;
                if (pDrawRectangle.IsEmpty == false)
                {
                    if ((pDrawRectangle.Width != 0) && (pDrawRectangle.Height != 0))
                    {
                        zoomInWidthFactor = pCurrentExtent.Width / pDrawRectangle.Width;
                        zoomInHeightFactor = pCurrentExtent.Height / pDrawRectangle.Height;
                        newMapExtentWidth = pCurrentExtent.Width * zoomInWidthFactor;
                        newMapExtentHeight = pCurrentExtent.Height * zoomInHeightFactor;
                        newMapExtentXmin = pCurrentExtent.XMin - (pDrawRectangle.XMin - pCurrentExtent.XMin) * zoomInWidthFactor;
                        newMapExtentYmin = pCurrentExtent.YMin - (pDrawRectangle.YMin - pCurrentExtent.YMin) * zoomInHeightFactor;
                        newMapExtentXmax = newMapExtentXmin + newMapExtentWidth;
                        newMapExtentYmax = newMapExtentYmin + newMapExtentHeight;
                        pNewEnvelope.PutCoords(newMapExtentXmin, newMapExtentYmin, newMapExtentXmax, newMapExtentYmax);
                    }
                }
                axMapControl1.Extent = pNewEnvelope;
            }
        }
private void button2_Click(object sender, EventArgs e)
        {
            x = 3;
           
        }

        private void button3_Click(object sender, EventArgs e)
        {  
            x = 5;
            


  • 3
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值