【ArcEngine标注和注记】- 使用TextElment绘制标注
转自 博客园 http://www.cnblogs.com/LoveLyre/archive/2011/09/10/2173310.html
//使用TextElment绘制标注, fieldName为要绘制的属性
public static void AddLable(AxMapControl axMapControl, ILayer layer, string fieldName)
{
IRgbColor pColor = new RgbColorClass()
{
Red = 255,
Blue = 0,
Green = 0
};
IFontDisp pFont = new StdFont()
{
Name = “宋体”,
Size = 5
} as IFontDisp;
ITextSymbol pTextSymbol = new TextSymbolClass()
{
Color = pColor,
Font = pFont,
Size = 11
};
IGraphicsContainer pGraContainer = axMapControl.Map as IGraphicsContainer;
//遍历要标注的要素
IFeatureLayer pFeaLayer = layer as IFeatureLayer;
IFeatureClass pFeaClass = pFeaLayer.FeatureClass;
IFeatureCursor pFeatCur = pFeaClass.Search(null, false);
IFeature pFeature = pFeatCur.NextFeature();
int index = pFeature.Fields.FindField(fieldName);//要标注的字段的索引
IEnvelope pEnv = null;
ITextElement pTextElment = null;
IElement pEle = null;
while (pFeature != null)
{
//使用地理对象的中心作为标注的位置
pEnv = pFeature.Extent;
IPoint pPoint = new PointClass();
pPoint.PutCoords(pEnv.XMin + pEnv.Width * 0.5, pEnv.YMin + pEnv.Height * 0.5);
pTextElment = new TextElementClass()
{
Symbol = pTextSymbol,
ScaleText = true,
Text = pFeature.get_Value(index).To\String()
};
pEle = pTextElment as IElement;
pEle.Geometry = pPoint;
//添加标注
pGraContainer.AddElement(pEle, 0);
pFeature = pFeatCur.NextFeature();
}
(axMapControl.Map as IActiveView).PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, axMapControl.Extent);
}
转载自:https://blog.csdn.net/Fuyouche/article/details/8618868