利用IIdentify接口实现点选和矩形…

IIdentify接口定义了获得要素图层单个要素的属性的捷径方法。它有一个Identify方法,返回一个IArray数组对象。
将下列代码放入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 }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值