zoukankan      html  css  js  c++  java
  • ArcEngine中同时闪烁多个要素的用户控件代码

    关键点:

    对IArray、IFeature.ShapeCopy、HookHelperClass以及IHookActions.DoActionOnMultiple的正确使用。

    代码如下:

    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);
            }
        }
    }

    截图如下:

    image

    image

  • 相关阅读:
    为什么一段时间后网站后台自动退出 php中session过期时间设置
    php中的$_GET如何获取带有“#”的参数
    让页面在打开时自动刷新
    MySQL关联left join 条件on与where不同
    图形上下文的栈操作(保存和恢复)
    图形上下文的矩阵操作(平移-缩放-旋转)
    Quartz2D内存管理
    文字绘制-图片绘制-水印绘制思路
    UIBezierPath-完善曲线
    UIBezierPath-绘制基本图形
  • 原文地址:https://www.cnblogs.com/flyingfish/p/1667533.html
Copyright © 2011-2022 走看看