AnsweredAssumed Answered

ArcObjects Maplex label placement

Question asked by canadajebus on Jan 21, 2015

Hi, I am trying to change some label placement properties of my feature layers I am adding to my map.  I am using ArcObjects c# and using ArcMap 10.2.2.  I am using Maplex, the map is already set to that labeling engine.

 

Here is my code.  Everything works except the label placement properties.  All other parts such as adding the label classes works.  No errors occur, it simply doesn't change any of the placement options.  I've tried other properties, the ones BackgroundLabel and RepeatLabel were just a couple I was testing with.

 

 

 // Label the layer
 {
     // Turn on labeling
     geoFeatureLayer.DisplayAnnotation = true;


     // The labels symbol
     IFormattedTextSymbol textSymbol = new TextSymbolClass();
     textSymbol.Color = color;
     textSymbol.Size = 24;
     textSymbol.Font = OLE.GetIFontDispFromFont(new Font("Arial", 24, FontStyle.Regular)) as stdole.IFontDisp;


     // The labels placement
     IMaplexOverposterLayerProperties maplexOverposterLayerProperties = new MaplexOverposterLayerPropertiesClass();
     maplexOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPolygon;
     maplexOverposterLayerProperties.PolygonPlacementMethod = esriMaplexPolygonPlacementMethod.esriMaplexStraightInPolygon;
     maplexOverposterLayerProperties.BackgroundLabel = false;
     maplexOverposterLayerProperties.RepeatLabel = true;




     // My Class 1
     ILabelEngineLayerProperties2 labelEngineLayerPropertiesMC1 = new MaplexLabelEngineLayerPropertiesClass();
     IAnnotateLayerProperties annotateLayerPropertiesMC1 = (IAnnotateLayerProperties)labelEngineLayerPropertiesMC1;
     annotateLayerPropertiesMC1.Class = "My Class 1";
     labelEngineLayerPropertiesMC1.Expression = "[myfield]";
     labelEngineLayerPropertiesMC1.Symbol = textSymbol;
     labelEngineLayerPropertiesMC1.OverposterLayerProperties = (IOverposterLayerProperties)maplexOverposterLayerProperties;


     // My Class 2
     ILabelEngineLayerProperties2 labelEngineLayerPropertiesMC2 = new MaplexLabelEngineLayerPropertiesClass();
     IAnnotateLayerProperties annotateLayerPropertiesMC2 = (IAnnotateLayerProperties)labelEngineLayerPropertiesMC2;
     annotateLayerPropertiesMC2.Class = "My Class 2";
     labelEngineLayerPropertiesMC2.Expression = "[myfield]";
     labelEngineLayerPropertiesMC2.Symbol = textSymbol;
     labelEngineLayerPropertiesMC2.OverposterLayerProperties = (IOverposterLayerProperties)maplexOverposterLayerProperties;


     // Create the collection of label classes
     IAnnotateLayerPropertiesCollection annotateLayerPropertiesCollection = geoFeatureLayer.AnnotationProperties;


     // Remove the default class
     IAnnotateLayerProperties annotateLayerPropertiesDefault;
     IElementCollection iec;
     annotateLayerPropertiesCollection.QueryItem(0, out annotateLayerPropertiesDefault, out iec, out iec);
     annotateLayerPropertiesCollection.Remove(annotateLayerPropertiesDefault);


     // Add the new classes
     annotateLayerPropertiesCollection.Add(annotateLayerPropertiesMC1);
     annotateLayerPropertiesCollection.Add(annotateLayerPropertiesMC2);


 }

Outcomes