要素闪烁,首先是要找到要素,然后调用IMapControl. FlashShape方法实现闪烁。
查找要素时,要用到IQueryFilter 接口,定义查询条件。然后调用IDisplayTable.SearchDisplayTable方法查询到
IFeatureCursor 要素游标对象,现在就可以调用IFeatureCursor .NextFeature()方法得到要素。
当有多个要素时,可以调用ITopologicalOperator.Union实现组合要素。
/// <summary>
/// 闪烁指定的巡查单元
/// </summary>
/// <param name="arrayList">巡查单元ID数组</param>
private void FlashCell(ArrayList arrayList)
{
if ((arrayList == null) || (arrayList.Count == 0)) return;
if (activeView == null)
{
activeView = this.MapControl.ActiveView.FocusMap as IActiveView;
}
//定义图层
IFeatureLayer pFeatureLayer = new FeatureLayerClass();
//网格图层不能为空
if (m_BgFeatureLayer == null) return;
pFeatureLayer = m_BgFeatureLayer;
//IGeoFeatureLayer对象
IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)pFeatureLayer;
//IQueryFilter对象,过滤条件。
IQueryFilter pQueryFilter;
//IDisplayTable对象,显示表
IDisplayTable pDisplayTable = pGeoFeatureLayer as IDisplayTable;
pQueryFilter = new QueryFilterClass();
//where条件语句
StringBuilder strFilter = new StringBuilder();
for (int i = 0; i < arrayList.Count; i++)
{
//巡查单元ID
string cellId = arrayList[i].ToString();
strFilter.Append(UiConst.BGCODE +" = '"+cellId +"' ");
if (i < arrayList.Count-1)
{
strFilter.Append(" OR ");
}
}
pQueryFilter.WhereClause = strFilter.ToString();
//IFeatureCursor对象
IFeatureCursor pFeatureCursor = pDisplayTable.SearchDisplayTable(pQueryFilter, false) as IFeatureCursor;
//IFeature对象,要素对象。
IFeature pFeature = pFeatureCursor.NextFeature();
//IGeometry对象,图形对象
IGeometry pGeo = new PolygonClass();
//IFields对象,字段对象
IFields pFields = pFeatureCursor.Fields;
//字段索引
int fieldIndex = pFields.FindField(UiConst.BGCODE);
//填充样式
ISimpleFillSymbol pFillsy;
pFillsy = new SimpleFillSymbolClass();
//pFillsy.Color = GetRgbColor(125, 60, 60);
pFillsy.Style = esriSimpleFillStyle.esriSFSCross;
//ITopologicalOperator对象
ITopologicalOperator topologicalOperator = new PolygonClass();
//中心点
IPoint pPoint = new PointClass();
if (pFeature != null)
{
topologicalOperator = pFeature.Shape as ITopologicalOperator;
if (!topologicalOperator.IsSimple)
{
topologicalOperator.Simplify();
}
}
pFeature = pFeatureCursor.NextFeature();
while (pFeature != null)
{
//组合所有的要素
pGeo = (IGeometry)topologicalOperator.Union(pFeature.Shape as IGeometry);
topologicalOperator = pGeo as ITopologicalOperator;
pFeature = pFeatureCursor.NextFeature();
}
if (pGeo != null)
{
//放大地图
//多边形
IPolygon pPolygon = pGeo as IPolygon;
//IArea,区域
IArea pArea = pPolygon as IArea;
//点
pPoint = pArea.Centroid;
if (pPoint != null)
{
this.ChangeEnvelope(pPoint, 0.06, 0.06);
Application.DoEvents();
}
MapControl.FlashShape(pGeo, 15, 300, pFillsy);
//样式
object symbol = pFillsy;
MapControl.DrawShape(pGeo, ref symbol);
Application.DoEvents();
}
}