方法一:
主要是使用了ISymbolCollectionElement接口设置了Feature的各种属性
IGeometry pointGeometry 这个几何对象应该是一个IPoint;
esriTextHorizontalAlignment 与 esriTextVerticalAlignment指示这个point在Annotation元素(一个面Polygon)的哪个位置,借此确定放置位置。
ISymbolCollectionElement或者IFormattedTextSymbol还有更多的属性可以设置(本文不做补充)
但是此方法没法设置文本标注的旋转角(方法二可以)
public void CreateAnnotationFeature(IGeometry pointGeometry,string text,string fontName,double fontSize,esriTextHorizontalAlignment horizontalAlignment,
esriTextVerticalAlignment verticalAlignment)
{
IFeature feature = featureClass.CreateFeature();
ISymbolCollectionElement symbolCollectionElement = new TextElementClass();
symbolCollectionElement.FontName = fontName;
symbolCollectionElement.Size = fontSize;
symbolCollectionElement.Text = text;
symbolCollectionElement.HorizontalAlignment = horizontalAlignment;
symbolCollectionElement.VerticalAlignment = verticalAlignment;
symbolCollectionElement.Geometry = pointGeometry;
IElement element = symbolCollectionElement as IElement;
IAnnotationFeature2 annotationFeature2 = feature as IAnnotationFeature2;
annotationFeature2.Annotation =element;
annotationFeature2.Status = esriAnnotationStatus.esriAnnoStatusPlaced;
feature.Store();
}
方法二:
主要使用IFormattedTextSymbol接口的方案
这种方法可以设置的参数好像多一些 fmtTextSymb.Angle 这个就是旋转角 传入的参数为角度
private void AddAnno(IFeatureClass featClass, IPoint pt, string textString)
{
IFeature feature = featClass.CreateFeature();
var annoClass = featClass.Extension as IAnnoClass;
IFontDisp font = new StdFontClass() as IFontDisp;
font.Name = "Arial";
font.Bold = true;
// font.Size = 30;
// load in some reasonable default values..
IFormattedTextSymbol fmtTextSymb = new TextSymbolClass();
fmtTextSymb.Font = font;
fmtTextSymb.Size = 30;
fmtTextSymb.VerticalAlignment = esriTextVerticalAlignment.esriTVABottom;
fmtTextSymb.HorizontalAlignment = esriTextHorizontalAlignment.esriTHALeft;
fmtTextSymb.Angle = 0;
fmtTextSymb.CharacterSpacing = 100;
fmtTextSymb.CharacterWidth = 100;
fmtTextSymb.FlipAngle = 90;
fmtTextSymb.Leading = 0;
fmtTextSymb.WordSpacing = 100;
fmtTextSymb.Text = textString; // my special text value..
ITextElement textElement = new TextElementClass();
textElement.Symbol = fmtTextSymb;
textElement.Text = textString;
IElement element = textElement as IElement;
element.Geometry = pt;
(feature as IAnnotationFeature2).Annotation = element;
feature.Store();
}
}