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

    关键点:

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

    代码如下:

    001 using System;
    002 using System.Collections.Generic;
    003 using System.ComponentModel;
    004 using System.Drawing;
    005 using System.Data;
    006 using System.Linq;
    007 using System.Text;
    008 using System.Windows.Forms;
    009 using ESRI.ArcGIS.Geodatabase;
    010 using ESRI.ArcGIS.Carto;
    011 using ESRI.ArcGIS.Display;
    012 using ESRI.ArcGIS.Geometry;
    013 using ESRI.ArcGIS.Controls;
    014 using ESRI.ArcGIS.esriSystem;
    015   
    016 namespace AgsTester
    017 {
    018     /// <summary>
    019     /// 本用户控件上需要放一个地图控件
    020     /// </summary>
    021     public partial class FlashMutiGeometry : UserControl
    022     {
    023         public FlashMutiGeometry()
    024         {
    025             InitializeComponent();
    026         }
    027   
    028         /// <summary>
    029         /// 加载地图
    030         /// </summary>
    031         /// <param name="pathMap"></param>
    032         public void LoadMap(string pathMap)
    033         {
    034             axMapControl1.LoadMxFile(pathMap);
    035         }
    036   
    037         /// <summary>
    038         /// 以村为单位过滤显示
    039         /// </summary>
    040         /// <param name="where">查询条件</param>
    041         public void FilterLayer(string where)
    042         {
    043             IFeatureLayer flyr = (IFeatureLayer)axMapControl1.get_Layer(0);
    044             IFeatureClass fcls = flyr.FeatureClass;
    045   
    046             IQueryFilter queryFilter = new QueryFilterClass();
    047             queryFilter.WhereClause = where;
    048   
    049             // 缩放到选择结果集,并高亮显示
    050             ZoomToSelectedFeature(flyr, queryFilter);
    051   
    052             //闪烁选中得图斑
    053             IFeatureCursor featureCursor = fcls.Search(queryFilter, true);
    054             FlashPolygons(featureCursor);
    055         }
    056   
    057         /// <summary>
    058         /// 缩放到选择结果集,并高亮显示
    059         /// </summary>
    060         /// <param name="pFeatureLyr"></param>
    061         /// <param name="pQueryFilter"></param>
    062         private void ZoomToSelectedFeature(IFeatureLayer pFeatureLyr, IQueryFilter pQueryFilter)
    063         {
    064             #region 高亮显示查询到的要素集合
    065   
    066             //符号边线颜色
    067             IRgbColor pLineColor = new RgbColor();
    068             pLineColor.Red = 255;
    069             ILineSymbol ilSymbl = new SimpleLineSymbolClass();
    070             ilSymbl.Color = pLineColor;
    071             ilSymbl.Width = 5;
    072   
    073             //定义选中要素的符号为红色
    074             ISimpleFillSymbol ipSimpleFillSymbol = new SimpleFillSymbol();
    075             ipSimpleFillSymbol.Outline = ilSymbl;
    076             RgbColor pFillColor = new RgbColor();
    077             pFillColor.Green = 60;
    078             ipSimpleFillSymbol.Color = pFillColor;
    079             ipSimpleFillSymbol.Style = esriSimpleFillStyle.esriSFSForwardDiagonal;
    080   
    081             //选取要素集
    082             IFeatureSelection pFtSelection = pFeatureLyr as IFeatureSelection;
    083             pFtSelection.SetSelectionSymbol = true;
    084             pFtSelection.SelectionSymbol = (ISymbol)ipSimpleFillSymbol;
    085             pFtSelection.SelectFeatures(pQueryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
    086   
    087             #endregion
    088   
    089             ISelectionSet pSelectionSet = pFtSelection.SelectionSet;
    090             //居中显示选中要素
    091             IEnumGeometry pEnumGeom = new EnumFeatureGeometry();
    092             IEnumGeometryBind pEnumGeomBind = pEnumGeom as IEnumGeometryBind;
    093             pEnumGeomBind.BindGeometrySource(null, pSelectionSet);
    094             IGeometryFactory pGeomFactory = new GeometryEnvironmentClass();
    095             IGeometry pGeom = pGeomFactory.CreateGeometryFromEnumerator(pEnumGeom);
    096   
    097             axMapControl1.ActiveView.Extent = pGeom.Envelope;
    098             axMapControl1.ActiveView.Refresh();
    099         }
    100   
    101         /// <summary>
    102         /// 闪烁选中得图斑
    103         /// </summary>
    104         /// <param name="featureCursor"></param>
    105         private void FlashPolygons(IFeatureCursor featureCursor)
    106         {
    107             IArray geoArray = new ArrayClass();
    108             IFeature feature = null;
    109             while ((feature = featureCursor.NextFeature()) != null)
    110             {
    111                 //feature是循环外指针,所以必须用ShapeCopy
    112                 geoArray.Add(feature.ShapeCopy);
    113             }
    114   
    115             //通过IHookActions闪烁要素集合
    116             HookHelperClass m_pHookHelper = new HookHelperClass();
    117             m_pHookHelper.Hook = axMapControl1.Object;
    118             IHookActions hookActions = (IHookActions)m_pHookHelper;
    119   
    120             hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsPan);
    121             //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsGraphic);
    122             //hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsZoom);
    123             Application.DoEvents();
    124             m_pHookHelper.ActiveView.ScreenDisplay.UpdateWindow();
    125   
    126             hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsFlash);
    127         }
    128     }
    129 }

    截图如下:

    image

    image

    来自http://www.cnblogs.com/flyingfish/archive/2010/02/11/1667533.html

  • 相关阅读:
    bcftools 为 vcf 文件建索引及合并 vcf 文件
    Linux 替换^M字符方法
    shell 字符串分割方法简介
    shell 数组介绍及相关操作
    Annovar 信息注释
    C++ string与数值的转换
    C/C++ 删除文件 remove函数
    关于内核转储(core dump)的设置方法
    mac下nginx安装
    linux独有的sendfile系统调用--“零拷贝,高效”
  • 原文地址:https://www.cnblogs.com/gisoracle/p/1866484.html
Copyright © 2011-2022 走看看