English

How To: Add coverage annotation as ArcMap layer using VBA

Summary

The ICoverageAnnotationLayer interface can be associated with an IFeatureLayer that is set using the ClassByName property of an IFeatureClassContainer.

Procedure

  1. Use a WorkspaceFactory object to create a pointer to the location of the data. Each data model requires its own type of WorkspaceFactory object. Consult the Geodatabase object model diagram for the various types.

    '++ Create a pointer to the data's workspace:
    Dim pWorkspaceFact As IWorkspaceFactory
    Set pWorkspaceFact = New ArcInfoWorkspaceFactory
    Dim pWorkspace As IWorkspace
    Set pWorkspace = pWorkspaceFact.OpenFromFile("c:\geodata\covers", 0)
    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace = pWorkspace

  2. Open the dataset by pointing a FeatureDataset object at the workspace's OpenFeatureDataset method.

    Dim pDataset As IFeatureDataset
    Set pDataset = pFeatureWorkspace.OpenFeatureDataset("covername")

  3. Create a pointer to the desired annotation feature class of the dataset using an IFeatureClassContainer with the ClassByName property.

    Dim pFeatureClassContainer As IFeatureClassContainer
    Set pFeatureClassContainer = pFeatureDataset
    Dim pFeatureClass As IFeatureClass
    Set pFeatureClass = pFeatureClassContainer.ClassByName ("annotation.subclass")

  4. Create a new instance of an ICoverageAnnotationLayer object and associate it with an IFeatureLayer object.

    Dim pCoverageAnnotationLayer As ICoverageAnnotationLayer
    Set pCoverageAnnotationLayer = New CoverageAnnotationLayer
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = pCoverageAnnotationLayer

  5. Set the IFeatureLayer object's FeatureClass method to the annotation subclass referenced by ClassByName property above.

    Set pFeatureLayer.FeatureClass = pFeatureClass
    pFeatureLayer.Name = "Feature class name"
    pFeatureLayer.Visible = True

  6. Add the layer to ArcMap with the IMap:AddLayer method.

    Dim pMxDocument As IMxDocument
    Set pMxDocument = ThisDocument
    pMxDocument.FocusMap.AddLayer pFeatureLayer

Related Information