指定要素高亮

指定要素高亮

arcEngine开发中,经常面临一个情况,就是查询到一个要素或指定一个要素的id,去让这个要素高亮,其实实现这个功能很简单,只不过基于arcEngine二次开发,需要熟悉它的官方文档才能找到这个方法,这里简单记录一下

思路

不管是什么方法,都需要利用用户传递的参数查到这个要素,如用户传来一个唯一属性,用户指定某个查询条件等,这里情况太多,不多说,这里简单说一下拿到要素之后的操作

  • 清除上一次的高亮
    • 再进行这次高亮前,先清除上次的高亮
  • 给高亮自定义一个高亮颜色
  • 指定要高亮的要素
  • 定位到高亮位置(可选)
  • 刷新地图

方式一 (IFeatureSelection)方式

​ 该类有一个select集合,通过追加要素到这个集合,再下次刷新时,会将集合里的要素高亮,同时,这个集合提供了添加和清除方法。

  private void button1_Click(object sender, EventArgs e)
        {
			int randomNumbers = 0;  
        	IFeatureLayer featureLayer = 				 (IFeatureLayer)this.axMapControl1.Map.get_Layer(randomNumbers);
        IFeatureClass featureClass = featureLayer.FeatureClass;
        IActiveView activeView = (IActiveView)this.axMapControl1.Map;
        
        // 获取当前活动视图中的地图对象
        IMap map = activeView.FocusMap;

        // 清除地图上的所有选择
        map.ClearSelection();

        //随机生成一个OID,0-100之间,模拟
        Random random = new Random();
        int randomNumber = random.Next(10);  // 生成一个介于 0 和 100(包括 0 和 100)之间的随机整数

        //根据oid找到要素
        IFeature f = featureClass.GetFeature(randomNumber);

        //获取地图上的IFeatureSelection接口
        IFeatureSelection featureSelection = (IFeatureSelection)featureLayer;

        // 清除先前的选择
        featureSelection.Clear();
        IRgbColor color = new RgbColorClass();
        color.Red = 255;
        featureSelection.SelectionColor = color;

        // 选择指定的要素
        featureSelection.Add(f);
       
        //定位的方法
        // 获取要素的几何图形
        IGeometry featureGeometry = f.ShapeCopy;

        // 获取 IEnvelope 接口,用于获取要素范围
        IEnvelope envelope = featureGeometry.Envelope;
        // 将视图焦点设置为要素范围的中心点
        this.axMapControl1.Extent = envelope;

        // 获取地图的 IActiveView 接口并刷新视图
       
        activeView.Refresh();
    }`

`

方式二 (SelectByShape)方式

`

       private void button1_Click(object sender, EventArgs e)

        {

            IFeatureLayer featureLayer = (IFeatureLayer)this.axMapControl1.Map.get_Layer(0);

            IFeatureClass featureClass = featureLayer.FeatureClass;

       Random random = new Random();
        int randomNumber = random.Next(10);  

        IFeature f = featureClass.GetFeature(randomNumber);
        IGeometry featureGeometry = f.ShapeCopy
        IEnvelope envelope = featureGeometry.Envelope;

        this.axMapControl1.Extent = envelope;

        ISelectionEnvironment selectionEnv = new SelectionEnvironment();
        IRgbColor color = new RgbColorClass();
        color.Red = 255;
        selectionEnv.DefaultColor = color;

        this.axMapControl1.Map.SelectByShape(featureGeometry, selectionEnv, false);
        this.axMapControl1.Refresh(esriViewDrawPhase.esriViewForeground, null, null);
       
    }

20231211_141056

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

问也去

创作不易,感谢支持

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值