AE要素闪烁的两种方法
1 using System; 2 using System.Collections.Generic; 3 using System.ComponentModel; 4 using System.Data; 5 using System.Drawing; 6 using System.Linq; 7 using System.Text; 8 using System.Windows.Forms; 9 using ESRI.ArcGIS.Carto; 10 using ESRI.ArcGIS.Geodatabase; 11 using ESRI.ArcGIS.Geometry; 12 using ESRI.ArcGIS.Display; 13 14 namespace Test_FieldsQuery 15 { 16 public partial class Form1 : Form 17 { 18 public Form1() 19 { 20 InitializeComponent(); 21 } 22 23 private void Form1_Load(object sender, EventArgs e) 24 { 25 axMapControl1.LoadMxFile("数据\\Asia.mxd"); 26 } 27 28 private void button1_Click(object sender, EventArgs e) 29 { 30 ILayer pLayer = axMapControl1.get_Layer(0); 31 IFeatureLayer pFeatureLayer = pLayer as IFeatureLayer; 32 IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass; 33 34 IQueryFilter pQueryFilter = new QueryFilterClass(); 35 pQueryFilter.WhereClause = "POPULATION > 5000000"; 36 37 IFeatureCursor pFeatureCursor = pFeatureClass.Search(pQueryFilter, false); 38 IFeature pFeature = pFeatureCursor.NextFeature(); 39 while (pFeature != null) 40 { 41 //第一种方法 42 this.axMapControl1.FlashShape(pFeature.Shape, 2, 1000,CreateSimpleSymbol(pFeature.Shape.GeometryType)); 43 //或者 44 this.axMapControl1.FlashShape(pFeature.Shape, 2, 1000,Type.Missing); 45 //第二种方法 46 //FlashGeometry(pFeature.Shape, 3, 300); 47 pFeature = pFeatureCursor.NextFeature(); 48 } 49 } 50 51 /// <summary> 52 /// 闪烁指定要素IGeometry 53 /// </summary> 54 /// <param name="geometry">要素</param> 55 /// <param name="flashCount">闪烁次数</param> 56 /// <param name="interval">每次闪烁的时间</param> 57 private void FlashGeometry(IGeometry geometry, int flashCount, int interval) 58 { 59 IScreenDisplay display = axMapControl1.ActiveView.ScreenDisplay; 60 ISymbol symbol = CreateSimpleSymbol(geometry.GeometryType); 61 display.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache); display.SetSymbol(symbol); 62 for (int i = 0; i < flashCount; i++) 63 { 64 switch (geometry.GeometryType) 65 { 66 case esriGeometryType.esriGeometryPoint: 67 display.DrawPoint(geometry); 68 break; 69 case esriGeometryType.esriGeometryMultipoint: 70 display.DrawMultipoint(geometry); 71 break; 72 case esriGeometryType.esriGeometryPolyline: 73 display.DrawPolyline(geometry); 74 break; 75 case esriGeometryType.esriGeometryPolygon: 76 display.DrawPolygon(geometry); 77 break; 78 } 79 System.Threading.Thread.Sleep(interval); 80 } 81 display.FinishDrawing(); 82 } 83 /// <summary> 84 /// 根据几何类型创建闪烁符号 85 /// </summary> 86 /// <param name="geometryType">要素几何类型</param> 87 /// <returns>ISymbol</returns> 88 private ISymbol CreateSimpleSymbol(esriGeometryType geometryType) 89 { 90 ISymbol symbol = null; 91 switch (geometryType) 92 { 93 case esriGeometryType.esriGeometryPoint: 94 case esriGeometryType.esriGeometryMultipoint: 95 ISimpleMarkerSymbol markerSymbol = new SimpleMarkerSymbolClass(); 96 markerSymbol.Color = getRGB(0, 0, 255); 97 markerSymbol.Size = 10; 98 symbol = markerSymbol as ISymbol; 99 break; 100 case esriGeometryType.esriGeometryPolyline: 101 case esriGeometryType.esriGeometryPath: 102 ISimpleLineSymbol lineSymbol = new SimpleLineSymbolClass(); 103 lineSymbol.Color = getRGB(0, 0, 255); 104 lineSymbol.Width = 10; 105 symbol = lineSymbol as ISymbol; 106 break; 107 case esriGeometryType.esriGeometryPolygon: 108 case esriGeometryType.esriGeometryRing: 109 ISimpleFillSymbol fillSymbol = new SimpleFillSymbolClass(); 110 fillSymbol.Color = getRGB(0, 0, 255); 111 symbol = fillSymbol as ISymbol; 112 break; 113 } 114 symbol.ROP2 = esriRasterOpCode.esriROPNotXOrPen; 115 return symbol; 116 } 117 private IColor getRGB(int i, int j, int k) 118 { 119 IRgbColor rgb = new RgbColorClass(); 120 rgb.Red = i; 121 rgb.Green = j; 122 rgb.Blue = k; 123 return rgb; 124 } 125 } 126 }