Add an Annotation FeatureClass to MapControl with ArcObjects

3603
0
11-26-2015 10:22 PM

Add an Annotation FeatureClass to MapControl with ArcObjects

Instructions provided describe how to add an Annotation FeatureClass to MapControl with ArcObjects.

To do this, you use the IAnnotationLayerFactory interface with its method, OpenAnnotationLayer(). This method opens an annotation feature class and returns a layer for it. (This interface comes from FDOGraphicsLayerFactory class)

This method takes:

  • the workspace of annotation class (IFeatureWorkspace)
  • the feature dataset contains annotation class (IFeatureDataset)
  • the name of annotation class (type string)

We receive a layer type IAnnotationLayer. You just cast this layer to IFeatureLayer and after that you add it to MapControl ( with method AddLayer() of IMapControl3 or IMapControl4).

My example:

Suppose that I have got myFeatureWorkspace (IFeatureWorkspace), myFeatureDataset (IFeatureDataset), myAnnotationName (string) and myMapControl (IMapControl4) objects. The codes like this:

IFeatureClass myFeatureClass = myFeatureWorkspace .OpenFeatureClass(myAnnotationName );

  //if this featureclass is annotation class

if (myFeatureClass .FeatureType == esriFeatureType.esriFTAnnotation)

{

  IAnnotationLayerFactory annotationLayerFactory = new FDOGraphicsLayerFactoryClass();

  IAnnotationLayer annotationLayer = annotationLayerFactory.OpenAnnotationLayer(myFeatureWorkspace myFeatureDataset , myAnnotationName );

  IFeatureLayer feaLayer = new FeatureLayerClass();

                                   //cast to IFeatureLayer

  feaLayer = annotationLayer as IFeatureLayer;

  feaLayer.Name = myAnnotationName; //optional

  myMapControl .AddLayer(feaLayer, 0);

}

Thank you.

Kim Tho Pham,

Ho Chi Minh City, Vietnam.

Version history
Last update:
‎11-26-2015 10:22 PM
Updated by:
Contributors