I currently have a basic shapefile that's a map of the United States. It has the name of the states, populations, and other pieces of information that I can get the names of via the following code:

IFeatureLayer myFeatureLayer = myLayer as IFeatureLayer;
IFeatureClass myFeatureClass = myFeatureLayer.FeatureClass;

For(int I = 0; I < myFeatureClass.Fields.FieldCount; i++)
IField field = myFeatureClass.Fields.get_Field(i);

The first field in the featureClass (after FID and the shape) is STATE_NAME which obviously is the name of each state.

If I do the following:

IGeoFeatureLayer geoLayer = myLayer as IGeoFeatureLayer;
geoLayer.displayAnnotation = true;

The states are now labeled; however, what I'd like is the ability to show different labels. I know from my looping through the featureclass Field count there are properties such as population and elevation. How do I change the AnnotationProperties to have it display that information instead of the default?

  • need to change title to reflect question (as shown in bold). – Kirk Kuykendall Feb 16 '11 at 21:51

its set in properties.Expression ...

public void annotateLayer(ILayer thisLayer, String geocode, double minScale, double maxScale, bool annotationsOn, bool showMapTips, RgbColor annotationLabelColor)
   IGeoFeatureLayer geoLayer = thisLayer as IGeoFeatureLayer;
   if (geoLayer != null)
        geoLayer.DisplayAnnotation = annotationsOn;
        IAnnotateLayerPropertiesCollection propertiesColl = geoLayer.AnnotationProperties;
        IAnnotateLayerProperties labelEngineProperties = new LabelEngineLayerProperties() as IAnnotateLayerProperties;
        IElementCollection placedElements = new ElementCollectionClass();
        IElementCollection unplacedElements = new ElementCollectionClass();
        propertiesColl.QueryItem(0, out labelEngineProperties, out placedElements, out unplacedElements);
        ILabelEngineLayerProperties lpLabelEngine = labelEngineProperties as ILabelEngineLayerProperties;
        lpLabelEngine.Expression = geocode;
        lpLabelEngine.Symbol.Color = annotationLabelColor; 
        labelEngineProperties.AnnotationMinimumScale = minScale;
        labelEngineProperties.AnnotationMaximumScale = maxScale; 
        IFeatureLayer thisFeatureLayer = thisLayer as IFeatureLayer;
        IDisplayString displayString = thisFeatureLayer as IDisplayString;
        IDisplayExpressionProperties properties = displayString.ExpressionProperties;
        properties.Expression = geocode; //example: "[OWNER_NAME] & vbnewline & \"$\" & [TAX_VALUE]";
        thisFeatureLayer.ShowTips = showMapTips;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.