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方法还有下面写法。
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 } } |
作 者:marvelousone
首发日期:2017-12-14 17:57
文章出处:https://www.cnblogs.com/marvelousone/p/8039031.html
关于博主:前端萌新
支持博主:留步扫个码,右侧领红包打赏~~
转载博客:如果您觉得本文有帮助,请带上署名和本文地址随意转载 | 仅供学习交流,严禁商业用途!
版权声明:自由转载-非商用-非衍生-保持署名(
创意共享3.0许可证
)
公众号:关注一下也是支持~不会打扰您
恰饭小广告区
阿里云优惠链接
阿里云国内短信套餐包活动
阿里云新人活动
ECS老用户福利
【推荐】100%开源!大型工业跨平台软件C++源码提供,建模,组态!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】Flutter适配HarmonyOS 5知识地图,实战解析+高频避坑指南
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· .NET程序启动就报错,如何截获初期化时的问题json
· 理解 C# 中的各类指针
· C#多线程编程精要:从用户线程到线程池的效能进化论
· 如何反向绘制出 .NET程序 异步方法调用栈
· 领域驱动设计实战:聚合根设计与领域模型实现
· DeepSeek+Coze实战:从0到1搭建小红书图文改写智能体(喂饭级教程)
· 【SQL周周练】一千条数据需要做一天,怎么用 SQL 处理电表数据(如何动态构造自然月)
· 如何医治一条慢SQL?
· springAI实现一个MCP-Server
· trae开发的win10端口占用检测工具