代码改变世界

ArcEngine中同时高亮和闪烁多个要素的用户控件代码

  愤怒的青蛙  阅读(2061)  评论(3编辑  收藏  举报

ArcEngine中同时闪烁多个要素的用户控件代码关键点:

对IArray、IFeature.ShapeCopy、HookHelperClass以及IHookActions.DoActionOnMultiple的正确使用。 代码如下:

1
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
 
namespace AgsTester
{
    /// <summary>
    /// 本用户控件上需要放一个地图控件
    /// </summary>
    public partial class FlashMutiGeometry : UserControl
    {
        public FlashMutiGeometry()
        {
            InitializeComponent();
        }
 
        /// <summary>
        /// 加载地图
        /// </summary>
        /// <param name="pathMap"></param>
        public void LoadMap(string pathMap)
        {
            axMapControl1.LoadMxFile(pathMap);
        }
 
        /// <summary>
        /// 以村为单位过滤显示
        /// </summary>
        /// <param name="where">查询条件</param>
        public void FilterLayer(string where)
        {
            IFeatureLayer flyr = (IFeatureLayer)axMapControl1.get_Layer(0);
            IFeatureClass fcls = flyr.FeatureClass;
 
            IQueryFilter queryFilter = new QueryFilterClass();
            queryFilter.WhereClause = where;
 
            // 缩放到选择结果集,并高亮显示
            ZoomToSelectedFeature(flyr, queryFilter);
 
            //闪烁选中得图斑
            IFeatureCursor featureCursor = fcls.Search(queryFilter, true);
            FlashPolygons(featureCursor);
        }
 
        /// <summary>
        /// 缩放到选择结果集,并高亮显示
        /// </summary>
        /// <param name="pFeatureLyr"></param>
        /// <param name="pQueryFilter"></param>
        private void ZoomToSelectedFeature(IFeatureLayer pFeatureLyr, IQueryFilter pQueryFilter)
        {
            #region 高亮显示查询到的要素集合
 
            //符号边线颜色
            IRgbColor pLineColor = new RgbColor();
            pLineColor.Red = 255;
            ILineSymbol ilSymbl = new SimpleLineSymbolClass();
            ilSymbl.Color = pLineColor;
            ilSymbl.Width = 5;
 
            //定义选中???素的符号为红色
            ISimpleFillSymbol ipSimpleFillSymbol = new SimpleFillSymbol();
            ipSimpleFillSymbol.Outline = ilSymbl;
            RgbColor pFillColor = new RgbColor();
            pFillColor.Green = 60;
            ipSimpleFillSymbol.Color = pFillColor;
            ipSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal;
 
            //选取要素集
            IFeatureSelection pFtSelection = pFeatureLyr as IFeatureSelection;
            pFtSelection.SetSelectionSymbol = true;
            pFtSelection.SelectionSymbol = (ISymbol)ipSimpleFillSymbol;
            pFtSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
 
            #endregion
 
            ISelectionSet pSelectionSet = pFtSelection.SelectionSet;
            //居中显示选中要素
            IEnumGeometry pEnumGeom = new EnumFeatureGeometry();
            IEnumGeometryBind pEnumGeomBind = pEnumGeom as IEnumGeometryBind;
            pEnumGeomBind.BindGeometrySource(null, pSelectionSet);
            IGeometryFactory pGeomFactory = new GeometryEnvironmentClass();
            IGeometry pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom);
 
            axMapControl1.ActiveView.Extent = pGeom.Envelope;
            axMapControl1.ActiveView.Refresh();
        }
 
        /// <summary>
        /// 闪烁选中得图斑
        /// </summary>
        /// <param name="featureCursor"></param>
        private void FlashPolygons(IFeatureCursor featureCursor)
        {
            IArray geoArray = new ArrayClass();
            IFeature feature = null;
            while ((feature = featureCursor.NextFeature()) != null)
            {
                //feature是循环外指针,所以必须用ShapeCopy
                geoArray.Add(feature.ShapeCopy);
            }
 
            //通过IHookActions闪烁要素集合
            HookHelperClass m_pHookHelper = new HookHelperClass();
            m_pHookHelper.Hook = axMapControl1.Object;
            IHookActions hookActions = (IHookActions)m_pHookHelper;
 
            hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsPan);
            //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsGraphic);
            //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsZoom);
            Application.DoEvents();
            m_pHookHelper.ActiveView.ScreenDisplay.UpdateWindow();
 
            hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsFlash);
        }
    }
}

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
点击右上角即可分享
微信分享提示