2

I am trying to display annotations for single features. I know it is possible to display annotations for layers, and for that entire map, but I would like to display them based on a SINGLE selected feature. example:-

I have a layer called A that is visible on the map, so all the features in it are visible. Now I select a feature, and want to display the annotation for that particular feature not the whole layer; how is this possible?

In my code I am doing this but for the entire layer, but I want it for a single feature, any ideas?

Here is my code which is a method that displays annotations for STRUCTURE features:

public static void ToggleXyLabelVisibility(IApplication application,ISchematicLayer layer, ISchematicFeature slctdFtr =null) {
        var doc = application.Document as IMxDocument;
        if (doc != null) {
      // display annotation for the entire layer if no features are selected
            if (slctdFtr == null) {
                var compLayer = layer as ICompositeLayer;
                if (compLayer != null) {
                    for (int i = 0; i < compLayer.Count; i++) {
                        var geoflay = compLayer.Layer[i] as IGeoFeatureLayer;
                        if (geoflay != null) {
                            for (int j = 0; j < geoflay.AnnotationProperties.Count; j++) {
                                var annotationProperties = geoflay.AnnotationProperties;
                                IElementCollection col1;
                                IElementCollection col2;
                                IAnnotateLayerProperties properties;
                                annotationProperties.QueryItem(j, out properties, out col1, out col2);
                                if (string.Equals(properties.Class, Locationlabel,
                                    StringComparison.CurrentCultureIgnoreCase)) {
                                    properties.DisplayAnnotation = !properties.DisplayAnnotation;

                                }
                            }
                        }
                    }
                }
             }
            // if features are selected, then display it for those selected features only
            else {
            // CODE GOES HERE WHICH I CAN'T FIGURE OUT HOW TO DO
            }
            doc.ActiveView.Refresh();
        }
    }
  • 1
    Did you try setting IAnnotateLayerProperties.LabelWhichFeatures to esriSelectedFeatures ? – Kirk Kuykendall Jun 3 '15 at 15:57
  • here is what I did if (string.Equals(properties.Class, Locationlabel, StringComparison.CurrentCultureIgnoreCase)) { if(slctStr !=null) properties.LabelWhichFeatures=esriWhichFeature.esriSelectedFeatures properties.DisplayAnnotation = !properties.DisplayAnnotation; } But nothing changes, it applies to all the features not the selected ones – ZZZ Jun 4 '15 at 13:15
1

Set IAnnotateLayerProperties.LabelWhichFeatures to esriSelectedFeatures Try this!

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

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.