ArcGis Engine 开发随笔
考虑以arcgis engin 为基础开发arcmap类似功能,以arcgis engine提供的mapcontrol为基础!
首先实现地图的基础操作功能,如放大缩小编辑等。
先说放大和缩小吧。考虑放大缩小时实质上就是改变当前地图控件的Extent,重点是改变当前控件Extent的过程。
在地铁上拉一个矩形框,然后根据矩形框的Envelop修改当前地图的Extent,我这里使用INewEnvelopeFeedback作为画矩形框的展示。
具体操作通过对地图的鼠标down,move,up事件编程。
代码如下:

1 private INewEnvelopeFeedback m_feedBack;
2 private IPoint m_point;
3 private Boolean m_isMouseDown;
4
5 public override void OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
6 {
7 IActiveView activeView = _map.ActiveView;
8
9 m_point = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
10
11 m_isMouseDown = true;
12
13 }
14 public override void OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
15 {
16 if (!m_isMouseDown) return;
17
18 //Get the focus map
19 IActiveView pActiveView = _map.ActiveView ;
20
21 //Start an envelope feedback
22 if (m_feedBack == null)
23 {
24 m_feedBack = new NewEnvelopeFeedbackClass();
25 m_feedBack.Display = pActiveView.ScreenDisplay;
26 m_feedBack.Start(m_point);
27 }
28
29 //Move the envelope feedback
30 m_feedBack.MoveTo(pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x,e.y));
31
32 }
33 public override void OnMouseUp(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseUpEvent e)
34 {
35 if (!m_isMouseDown) return;
36
37 //Get the focus map
38 IActiveView pActiveView = _map.ActiveView;
39
40 //If an envelope has not been tracked
41 IEnvelope pEnvelope;
42
43 if (m_feedBack == null)
44 {
45 //Zoom in from mouse click
46 pEnvelope = pActiveView.Extent;
47 pEnvelope.Expand(0.5, 0.5, true);
48 pEnvelope.CenterAt(m_point);
49 }
50 else
51 {
52 //Stop the envelope feedback
53 pEnvelope = m_feedBack.Stop();
54
55 //Exit if the envelope height or width is 0
56 if (pEnvelope.Width == 0 || pEnvelope.Height == 0)
57 {
58 m_feedBack = null;
59 m_isMouseDown = false;
60 }
61 }
62 //Set the new extent
63 pActiveView.Extent = pEnvelope;
64 //Refresh the active view
65 pActiveView.Refresh();
66 m_feedBack = null;
67 m_isMouseDown = false;
68
69 }
这是实现放大时的代码。
其实代码很简单,我就不做解释了,缩小的代码基本和放大的代码相差不多,只是最后需要对Envelope做重新的计算,我是按照当前地图的现实范围与拉框的现实范围反比获得新的Envelope做的。
第一次写博客希望对朋友们能有所帮助。