zoukankan      html  css  js  c++  java
  • C# AE放大缩小地图全局显示功能

    基于ArcGIS Base Command模板放大缩小

    [地址]http://blog.csdn.net/eof_2011/article/details/8014075

     既能拉框也能点击放大缩小,原作者写的非常好收藏了。

    基于ESRI.ArcGIS.Controls命名空间

    这种esriControlsMousePointer方式实现的放大缩小只能拉框不能点击

    放大

    //写在功能按钮中
    axMapControl1.MousePointer=esriControlsMousePointer.esriPointerZoomIn;
    flag= a number //以flag number来判断 //写在OnMouseDown之类的事件中 下同
    IEnvelope pEnvelope
    = axMapControl1.TrackRectangle(); axMapControl1.Extent = pEnvelope ;

    缩小

     axMapControl1.MousePointer = esriControlsMousePointer.esriPointerZoomOut;
    
    pEnvelope
    = axMapControl1.TrackRectangle(); pEnvelope = axMapControl1.Extent; pEnvelope .Expand(2, 2, true); axMapControl1.Extent = pEnvelope ;

    漫游

    axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
    
    pEnvelope
    = axMapControl1.Extent; axMapControl1.Pan();

    全局显示

    axMapControl1.Extent = axMapControl1.FullExtent;

    Tips:

    可以根据flag来if判断写何种类型操作之后的代码

     基于IEnvolope的Expand方法

    这种方法只能拉框放大

     private void Zoom_Out(AxMapControl map) 
     {
         var _map = axMapControl1;
         _map.Extent = _map.FullExtent;
         IEnvelope pEnvelope = null;
         pEnvelope = _map.Extent;
         pEnvelope.Expand(0.5, 0.5, true);
         _map.Extent = pEnvelope;
         //_map.MousePointer = esriControlsMousePointer.esriPointerDefault; 
         _map.ActiveView.Refresh();
     }
    
    //ZoomIn放大
     private void Zoom_In()
     {
         IActiveView pAtView = axMapControl1.ActiveView;
         IPoint centerPoint = new PointClass();
         centerPoint.PutCoords((pAtView.Extent.XMin + pAtView.Extent.XMax) * 2, (pAtView.Extent.YMax + pAtView.Extent.YMin) * 2);
         IEnvelope pEnvlope = pAtView.Extent;
         pEnvlope.Expand(1.5, 1.5, true); 与放大的区别在于参数不同
         pAtView.Extent.CenterAt(centerPoint);
         pAtView.Extent = pEnvlope;
         pAtView.Refresh();
    
     }

     基于IEnvolope的Expand方法还有下面写法。

    //这些写在放大按钮事件里
    Property.axMapControl.CurrentTool = null;
    pMouseOperate = "ZoomIn";
    Property.axMapControl.MousePointer = esriControlsMousePointer.esriPointerZoomIn;
    //同理 缩小的
     mainMapControl.CurrentTool = null;
    pMouseOperate = "ZoomOut";
    mainMapControl.MousePointer = esriControlsMousePointer.esriPointerZoomOut;
    
    //这些方法axMapControl中鼠标按下事件中
    //屏幕坐标点转化为地图坐标点
    pPointPt = (mainMapControl.Map as IActiveView).ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
    
    if (e.button == 1)
    {
    	IActiveView pActiveView = mainMapControl.ActiveView;
    	IEnvelope pEnvelope = new EnvelopeClass();
    
    	switch (pMouseOperate)
    	{
    		#region 拉框放大
    
    		case "ZoomIn":
    			pEnvelope = mainMapControl.TrackRectangle();
    			//如果拉框范围为空则返回
    			if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0)
    			{
    				return;
    			}
    			//如果有拉框范围,则放大到拉框范围
    			pActiveView.Extent = pEnvelope;
    			pActiveView.Refresh();
    			break;
    
    			#endregion
    
    		#region 拉框缩小
    
    		case "ZoomOut":
    			pEnvelope = mainMapControl.TrackRectangle();
    
    			//如果拉框范围为空则退出
    			if (pEnvelope == null || pEnvelope.IsEmpty || pEnvelope.Height == 0 || pEnvelope.Width == 0)
    			{
    				return;
    			}
    				//如果有拉框范围,则以拉框范围为中心,缩小倍数为:当前视图范围/拉框范围
    			else
    			{
    				double dWidth = pActiveView.Extent.Width*pActiveView.Extent.Width/pEnvelope.Width;
    				double dHeight = pActiveView.Extent.Height*pActiveView.Extent.Height/pEnvelope.Height;
    				double dXmin = pActiveView.Extent.XMin -
    							   ((pEnvelope.XMin - pActiveView.Extent.XMin)*pActiveView.Extent.Width/
    								pEnvelope.Width);
    				double dYmin = pActiveView.Extent.YMin -
    							   ((pEnvelope.YMin - pActiveView.Extent.YMin)*pActiveView.Extent.Height/
    								pEnvelope.Height);
    				double dXmax = dXmin + dWidth;
    				double dYmax = dYmin + dHeight;
    				pEnvelope.PutCoords(dXmin, dYmin, dXmax, dYmax);
    			}
    			pActiveView.Extent = pEnvelope;
    			pActiveView.Refresh();
    			break;
    
    			#endregion
    	}
    }
    

      


  • 相关阅读:
    python spark 求解最大 最小 平均
    python spark 求解最大 最小 平均 中位数
    我的spark python 决策树实例
    python spark 随机森林入门demo
    python spark 决策树 入门demo
    php 使用curl发起https请求
    awk调用shell命令的两种方法:system与print
    js 中 setTimeout()的用法
    Linux里AWK中split函数的用法
    awk substr()函数
  • 原文地址:https://www.cnblogs.com/marvelousone/p/8039031.html
Copyright © 2011-2022 走看看