将下列代码放入MouseDown事件中,可以实现点选或者矩形选择要素。
1
IMap pMap;
2
IPoint pPoint;
3
pMap = axMapControl1.Map;
4
pPoint = axMapControl1.ToMapPoint(e.x, e.y);
5
6
IIdentify pIdentify;
7
pIdentify = (IIdentify)pMap.get_Layer(0);
8
9
IArray pIDArray;
10
IFeatureIdentifyObj pFeatIdObj;
11
IIdentifyObj pIdObj;
12
//点选
13
IEnvelope pEnv=new EnvelopeClass();
14
pEnv =axMapControl1.ActiveView.Extent;
15
pEnv.Height= 100;
16
pEnv.Width = 100;
17
pEnv.CenterAt(pPoint);
18
pIDArray = pIdentify.Identify(pEnv);
19
//矩形选择
20
//IEnvelope testIRectangleElement;
21
//testIRectangleElement = axMapControl1.TrackRectangle();
22
//pIDArray = pIdentify.Identify(testIRectangleElement);
23
//i = pIDArray.Count;
24
if (pIDArray != null)
25 {
26 for (int i = 0; i <= pIDArray.Count; i++)
27 {
28 pFeatIdObj = (IFeatureIdentifyObj)pIDArray.get_Element(i);
29 pIdObj = (IIdentifyObj)pFeatIdObj;
30 pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay);
31 //消息显示查询目标的信息
32 MessageBox.Show("Layer:" + pIdObj.Layer.Name + "Feature:" + pIdObj.Name);
33 }
34 }
35
else
36 {
37 MessageBox.Show("No feature identified.");
38 }
39
40
}
41
42
43
44
(部分代码来自ESRI中国社区)
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 for (int i = 0; i <= pIDArray.Count; i++)
27 {
28 pFeatIdObj = (IFeatureIdentifyObj)pIDArray.get_Element(i);
29 pIdObj = (IIdentifyObj)pFeatIdObj;
30 pIdObj.Flash(axMapControl1.ActiveView.ScreenDisplay);
31 //消息显示查询目标的信息
32 MessageBox.Show("Layer:" + pIdObj.Layer.Name + "Feature:" + pIdObj.Name);
33 }
34 }
35

36 {
37 MessageBox.Show("No feature identified.");
38 }
39

40

41

42

43

44
