arcgis engine实现查询要素同时闪烁代码
时间: 2023-07-30 18:11:37 浏览: 129
同时闪烁多个要素代码(ArcEngine).doc
ArcGIS Engine 可以用 C# 或 VB.NET 编写代码,实现查询要素并同时闪烁的效果。以下是一个示例代码:
```csharp
private void FlashFeature(IFeature feature, IMapControl3 mapControl)
{
// 获取要素的几何图形
IGeometry geometry = feature.Shape;
// 创建一个闪烁符号
ISymbol symbol = new SimpleMarkerSymbolClass();
((ISimpleMarkerSymbol)symbol).Color = getRGB(255, 0, 0);
((ISimpleMarkerSymbol)symbol).Style = esriSimpleMarkerStyle.esriSMSCircle;
((ISimpleMarkerSymbol)symbol).Outline = true;
((ISimpleMarkerSymbol)symbol).OutlineSize = 1;
// 创建一个闪烁效果
IFlashGeometry flashGeometry = new FlashGeometryClass();
flashGeometry.Geometry = geometry;
flashGeometry.Symbol = symbol;
// 将闪烁效果加入到地图控件中
IActiveView activeView = mapControl.ActiveView;
activeView.ScreenDisplay.StartDrawing(0, (short)esriScreenCache.esriNoScreenCache);
flashGeometry.Start(activeView.ScreenDisplay);
// 等待一段时间
System.Threading.Thread.Sleep(500);
// 停止闪烁效果
flashGeometry.Stop();
activeView.ScreenDisplay.FinishDrawing();
}
private IRgbColor getRGB(int r, int g, int b)
{
IRgbColor color = new RgbColorClass();
color.Red = r;
color.Green = g;
color.Blue = b;
return color;
}
private void QueryAndFlashFeature(IMapControl3 mapControl, IQueryFilter queryFilter)
{
// 获取地图图层
IEnumLayer enumLayer = mapControl.Map.get_Layers(null, true);
ILayer layer = null;
while ((layer = enumLayer.Next()) != null)
{
// 判断图层是否为要素图层
IFeatureLayer featureLayer = layer as IFeatureLayer;
if (featureLayer == null) continue;
// 查询要素
IFeatureCursor featureCursor = featureLayer.Search(queryFilter, false);
IFeature feature = null;
while ((feature = featureCursor.NextFeature()) != null)
{
// 闪烁要素
FlashFeature(feature, mapControl);
}
}
}
private void btnQuery_Click(object sender, EventArgs e)
{
// 创建查询过滤器
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "CITY_NAME = '北京'";
// 查询并闪烁要素
QueryAndFlashFeature(axMapControl1, queryFilter);
}
```
在这个代码中,`FlashFeature` 方法用于将一个要素闪烁。`QueryAndFlashFeature` 方法用于查询符合条件的要素,并将它们闪烁。在 `btnQuery_Click` 事件中,我们创建了一个查询过滤器,查询城市名称为“北京”的要素,并将它们闪烁。
阅读全文