How to convert labels to map annotation for a single layer


Converting labels to map annotation for a single layer

This document demonstrates how to use the ConvertLabelsToAnnotation class to change a label for a single layer to map annotation. The ConvertLabelsToAnnotation class is a coarse-grained object that encapsulates the logic needed to perform this conversion. This class works with maps labeled with Maplex and the standard label engine.
The map reference passed into the function must be activated on a window. Check the IsMapActivated property on IActiveView to determine if the map is activated. Typically the map is activated unless it is opened via MapDocument or MapReader.
[Java]
static void convertLabelsToAnnotationSingleLayerMapAnno(IMap map, int layerIndex)
    throws Exception{
    IConvertLabelsToAnnotation convertLabToAnno = new ConvertLabelsToAnnotation();
    ITrackCancel trackCancel = new CancelTracker();
    //Change global level options for the conversion by sending in different parameters to the next line.
    convertLabToAnno.initialize(map, esriAnnotationStorageType.esriMapAnnotation,
        esriLabelWhichFeatures.esriVisibleFeatures, true, trackCancel, null);
    ILayer layer = map.getLayer(layerIndex);
    IGeoFeatureLayer geoFeatureLayer = (IGeoFeatureLayer)layer;
    if (geoFeatureLayer != null){
        IFeatureClass featClass = geoFeatureLayer.getFeatureClass();
        //Add the layer information to the converter object. Specify the parameters of the output annotation feature class here as well.
        convertLabToAnno.addFeatureLayer(geoFeatureLayer, geoFeatureLayer.getName() 
            + "_Anno", null, null, false, false, false, false, false, "");
        //Do the conversion.
        convertLabToAnno.convertLabels();
        //Turn off labeling for the layer converted.
        geoFeatureLayer.setDisplayAnnotation(false);
        //Refresh the map to update the display.
        IActiveView activeView = (IActiveView)map;
        activeView.refresh();
    }
}






Development licensingDeployment licensing
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine