private void NoteFeatures()
{
int index = _featureLayer.FeatureClass.FindField("BSM");//要标注的字段的索引
if (index <= -1) return;
if (_textElementsAll.Count > 0)
{
_textElementsAll.ForEach(x => _pGraphicsContainer.DeleteElement(x));
}
_textElementsAll = new List<IElement>();
if (CurrentGridItem.FeatureIds == null) return;
foreach (var id in CurrentGridItem.FeatureIds)
{
IFeature feature = _featureLayer.FeatureClass.GetFeature(id.featureid);
_MapCtrl.Map.SelectFeature(_featureLayer, feature);
//备注要素
IRgbColor pColor = new RgbColorClass()
{
Red = 255,
Blue = 0,
Green = 0
};
ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color = pColor,
Size = 11
};
//使用地理对象的中心作为标注的位置
IEnvelope pEnv = feature.Extent;
IPoint pPoint = new PointClass();
pPoint.PutCoords(pEnv.XMin + pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5);
ITextElement pTextElment = new TextElementClass()
{
Symbol = pTextSymbol,
ScaleText = true,
Text = feature.get_Value(index).ToString()
};
IElement pEle = pTextElment as IElement;
pEle.Geometry = pPoint;
_textElementsAll.Add(pEle);
//添加标注
_pGraphicsContainer.AddElement(pEle, 0);
}
(_MapCtrl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, _MapCtrl.Extent);
}