AO+C#鹰眼功能实现——(一) (拖动功能未实现)

实现关键两点:
1.保持两个显示控件的一致性。
2.绘制鹰眼窗口显示方框。

窗体包括两个Mapcontrol,几个按钮

源代码如下:(部分代码参考ESRI中国论坛相关帖子)
Code
  1using System;
  2using System.Collections.Generic;
  3using System.ComponentModel;
  4using System.Data;
  5using System.Drawing;
  6using System.Text;
  7using System.Windows.Forms;
  8using ESRI.ArcGIS.Carto;
  9using ESRI.ArcGIS.Controls;
 10using ESRI.ArcGIS.Geometry;
 11using ESRI.ArcGIS.Display;
 12
 13namespace WindowsApplication1
 14{
 15    public partial class Form1 : Form
 16    {
 17        public Form1()
 18        {
 19            InitializeComponent();
 20            
 21        }

 22
 23        private void buttonOpen_Click(object sender, EventArgs e)
 24        {
 25            //加载MXD文件
 26
 27            IMapDocument pMapDocument = new MapDocumentClass();
 28            OpenFileDialog Open = new OpenFileDialog();
 29
 30            Open.Title = "Select File";
 31            Open.Filter = "Document File(.mxd)|*.mxd";
 32
 33            Open.ShowDialog();
 34
 35            string strFullPath = Open.FileName;
 36            if (strFullPath == ""return;
 37
 38            pMapDocument.Open(strFullPath, "");
 39            for (int i = 0; i <= pMapDocument.MapCount - 1; i++)
 40            {
 41                //一个IMapDocument对象中可能有多个Map对象,遍历每个map对象
 42                axMapControl1.Map = pMapDocument.get_Map(i);
 43
 44            }

 45            axMapControl1.Refresh();
 46
 47        }

 48
 49        private void buttonExit_Click(object sender, EventArgs e)
 50        {
 51            Application.Exit();
 52        }

 53
 54        private void axMapControl1_OnMouseDown(object sender, IMapControlEvents2_OnMouseDownEvent e)
 55        {
 56            if (e.button == 2)
 57            {
 58                //右键局部放大,后面应该有个局部刷新CtlRefresh,未搞定
 59                axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPageZoomIn;
 60                axMapControl1.Extent = axMapControl1.TrackRectangle();
 61            }

 62            else if (e.button == 1)
 63            {
 64                //左键移动,也应有局部刷新
 65                axMapControl1.MousePointer = esriControlsMousePointer.esriPointerPan;
 66                axMapControl1.Pan();
 67            }

 68        }

 69
 70        private void buttonResize_Click(object sender, EventArgs e)
 71        {
 72            //还原初始大小
 73            axMapControl1.Extent = axMapControl1.FullExtent;
 74        }

 75
 76        private void axMapControl1_OnMapReplaced(object sender, IMapControlEvents2_OnMapReplacedEvent e)
 77        {
 78            IMap pMap;
 79            pMap = this.axMapControl1.Map;
 80            int i;
 81            this.axMapControl2.Map.ClearLayers();
 82            this.axMapControl2.ActiveView.Refresh();
 83
 84            for (i = 0; i <= pMap.LayerCount - 1; i++)
 85            {
 86                this.axMapControl2.Map.AddLayer(pMap.get_Layer(pMap.LayerCount - 1 - i));
 87            }

 88        }

 89
 90        private void axMapControl1_OnExtentUpdated(object sender, IMapControlEvents2_OnExtentUpdatedEvent e)
 91        {
 92            // 得到新范围
 93
 94            IEnvelope pEnv = (IEnvelope)e.newEnvelope;
 95
 96
 97            IGraphicsContainer pGra = axMapControl2.Map as IGraphicsContainer;
 98
 99            IActiveView pAv = pGra as IActiveView;
100
101            //在绘制前,清除axMapControl2中的任何图形元素
102
103            pGra.DeleteAllElements();
104
105
106            IRectangleElement pRectangleEle = new RectangleElementClass();
107
108            IElement pEle = pRectangleEle as IElement;
109
110            pEle.Geometry = pEnv;
111
112
113            //设置鹰眼图中的红线框
114
115            IRgbColor pColor = new RgbColorClass();
116
117            pColor.Red = 255;
118
119            pColor.Green = 0;
120
121            pColor.Blue = 0;
122
123            pColor.Transparency = 255;
124
125            //产生一个线符号对象
126
127            ILineSymbol pOutline = new SimpleLineSymbolClass();
128
129            pOutline.Width = 2;
130
131            pOutline.Color = pColor;
132
133
134            //设置颜色属性
135
136            pColor = new RgbColorClass();
137
138            pColor.Red = 255;
139
140            pColor.Green = 0;
141
142            pColor.Blue = 0;
143
144            pColor.Transparency = 0;
145
146            //设置填充符号的属性
147
148            IFillSymbol pFillSymbol = new SimpleFillSymbolClass();
149
150            pFillSymbol.Color = pColor;
151
152            pFillSymbol.Outline = pOutline;
153
154
155            IFillShapeElement pFillShapeEle = pEle as IFillShapeElement;
156
157            pFillShapeEle.Symbol = pFillSymbol;
158
159            pGra.AddElement((IElement)pFillShapeEle, 0);
160
161            pAv.PartialRefresh(esriViewDrawPhase.esriViewGraphics, nullnull);
162
163
164        }

165
166    }

167}

168

转载于:https://www.cnblogs.com/secenes/archive/2008/05/15/1198933.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值