add AnnotationLayer to map

354
1
Jump to solution
06-04-2014 02:52 AM
SusannSchmidt
New Contributor III
I have a FileGeoDatabase with a AnnotationFeatureClass (within 3 AnnotationClasses) that I programmatically want to load to my map. First I load the FeatureClass in order to get some Informations and then while creating the AnnotationLayer an error occurs. I've used some code from the Esri-help, but what could be wrong?
Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");                         IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);                         ws = workspaceFactory.OpenFromFile(pGdbSource.Dir + "\\" + pGdbSource.File, 0);                                  if (ws != null)                 {                         IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)ws;                         IFeatureLayer featureLayer = new FeatureLayerClass();                         string FCName = (pGdbSource.BrowseName != "") ? pGdbSource.BrowseName : pGdbSource.ItemName;                         featureLayer.FeatureClass = featureWorkspace.OpenFeatureClass(FCName);                         ILayer layer = (ILayer)featureLayer;                         if ((featureLayer.FeatureClass.FeatureType == esriFeatureType.esriFTAnnotation) &&                             (featureLayer is FeatureLayerClass))                         {                             // Get the GeometryDef from the feature class's shape field.                             String shapeFieldName = featureLayer.FeatureClass.ShapeFieldName;                             int shapeFieldIndex = featureLayer.FeatureClass.FindField(shapeFieldName);                             IFields fields = featureLayer.FeatureClass.Fields;                             IField shapeField = fields.get_Field(shapeFieldIndex);                             IGeometryDef geometryDef = shapeField.GeometryDef;                              IAnnotateLayerPropertiesCollection annotateLayerPropsCollection = (featureLayer as FeatureLayerClass).AnnotationProperties;                              // Create a graphics layer scale object.                             IGraphicsLayerScale graphicsLayerScale = new GraphicsLayerScaleClass();                             try                             {                                 graphicsLayerScale.ReferenceScale = mxDocument.ActiveView.FocusMap.MapScale;                             }                             catch (Exception ex) { graphicsLayerScale.ReferenceScale = 0.0; }                             graphicsLayerScale.Units = mxDocument.ActiveView.FocusMap.MapUnits;                              // Create the overposter properties for the standard label engine.                             IOverposterProperties overposterProperties = new BasicOverposterPropertiesClass();                              ISymbolCollection symbolCollection = new SymbolCollectionClass();                             ISymbolCollection2 symbolCollection2 = (ISymbolCollection2)symbolCollection;                              // Create the annotation layer factory.                             IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass();                              IDataset pDataset = (featureLayer as FeatureLayerClass) as IDataset;                              // Create the annotation feature class and an annotation layer for it.                             IAnnotationLayer annotationLayer = annotationLayerFactory.CreateAnnotationLayer                                 (featureWorkspace, pDataset as IFeatureDataset, FCName,                                  geometryDef, null,                                 annotateLayerPropsCollection, graphicsLayerScale, symbolCollection, false,                                 false, false, true, overposterProperties, "configKeyword");                              // Get the feature class from the feature layer.                             featureLayer = (IFeatureLayer)annotationLayer;


Thanks for any suggestions!
0 Kudos
1 Solution

Accepted Solutions
SusannSchmidt
New Contributor III
Sorry for answering my own question.

It's not so difficult as it seems. I just have to use the OpenAnnotationLayer-method of the FDOGraphicsLayerFactoryClass to get my layerobject:

IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass(); IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(featureWorkspace, null, FCName);

View solution in original post

0 Kudos
1 Reply
SusannSchmidt
New Contributor III
Sorry for answering my own question.

It's not so difficult as it seems. I just have to use the OpenAnnotationLayer-method of the FDOGraphicsLayerFactoryClass to get my layerobject:

IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass(); IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(featureWorkspace, null, FCName);
0 Kudos