C# AE放大缩小地图全局显示功能

posted @   marvelousone  阅读(3431)  评论(0)    收藏  举报

基于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方法还有下面写法。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//这些写在放大按钮事件里
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
    }
}

  

 

编辑推荐:
· .NET程序启动就报错,如何截获初期化时的问题json
· 理解 C# 中的各类指针
· C#多线程编程精要:从用户线程到线程池的效能进化论
· 如何反向绘制出 .NET程序 异步方法调用栈
· 领域驱动设计实战:聚合根设计与领域模型实现
阅读排行:
· DeepSeek+Coze实战:从0到1搭建小红书图文改写智能体(喂饭级教程)
· 【SQL周周练】一千条数据需要做一天,怎么用 SQL 处理电表数据(如何动态构造自然月)
· 如何医治一条慢SQL?
· springAI实现一个MCP-Server
· trae开发的win10端口占用检测工具
点击右上角即可分享
微信分享提示

喜欢请打赏

扫描二维码打赏

先送你一个公交红包啦~