/// <summary>
/// 添加到注记图层
/// </summary>
/// <param name="pFeatCls">注记图层</param>
/// <param name="pGeometry">插入的位置:一般是一个IPoint</param>
/// <returns></returns>
protected bool InsertAnnoFea(IFeatureClass pFeatCls, IGeometry pGeometry)
{
IFeatureClass annocls = pFeatCls;
IDataset pDataset = annocls as IDataset;
ITransactions pTransactions = pDataset.Workspace as ITransactions;
pTransactions.StartTransaction();
IFDOGraphicsLayerFactory pFDOGLFactory = new FDOGraphicsLayerFactoryClass();
ILayer tmpLayer = pFDOGLFactory.OpenGraphicsLayer(pDataset.Workspace as IFeatureWorkspace, annocls.FeatureDataset, pDataset.Name);
IFDOGraphicsLayer pFDOGLayer = tmpLayer as IFDOGraphicsLayer;
IElementCollection pElementColl = new ElementCollectionClass();
pFDOGLayer.BeginAddElements();
ITextElement pTextElement = AnnoUtil.MakeTextElement(text, dHSize, rgbColor, sHFont, dHAngle) as ITextElement;
IElement pElement = pTextElement as IElement;
pElement.Geometry = pGeometry;
pElementColl.Add(pElement, 0);
pFDOGLayer.DoAddElements(pElementColl, 0);
pFDOGLayer.EndAddElements();
pElementColl.Clear();
pTransactions.CommitTransaction();
return true;
}
方法二 通过IAnnotationFeature来实现
/// <summary>
/// 添加到注记图层
/// </summary>
/// <param name="pFeatCls">注记图层</param>
/// <param name="pGeometry">插入的位置:一般是一个IPoint</param>
/// <returns></returns>
protected bool InsertAnnoFea2(IFeatureClass pFeatCls, IGeometry pGeometry)
{
IFeatureClass annocls = pFeatCls;
IWorkspace workspace = ((IDataset)annocls).Workspace;
IWorkspaceEdit workspaceEdit = workspace as IWorkspaceEdit;
bool startEdit = workspaceEdit.IsBeingEdited();
if (!startEdit)
{
workspaceEdit.StartEditing(false);
}
workspaceEdit.StartEditOperation();
ITextElement pTextElement = AnnoUtil.MakeTextElement(text, dHSize, rgbColor, sHFont, dHAngle) as ITextElement;
IElement pElement = pTextElement as IElement;
pElement.Geometry = pGeometry;
IFeature pFeature = annocls.CreateFeature();
IAnnotationFeature pAnnoFeature = pFeature as IAnnotationFeature;
pAnnoFeature.Annotation = pElement;
pFeature.Store();
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
return true;
}