ArcObjects C# - Use Maplex

2550
6
Jump to solution
03-08-2016 01:35 AM
NicolasFaget1
New Contributor III

Hi everyone,

I have a problem with the use of Maplex in C#. I have to create symbology on Layer. Everything is working except maplex properties.

My need is to add a separator ('-') on "label stacking properties".

My code :

// The labels placement 

IMaplexOverposterLayerProperties maplexOverposterLayerProperties = new MaplexOverposterLayerPropertiesClass();

maplexOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;                           

maplexOverposterLayerProperties.PointPlacementMethod = esriMaplexPointPlacementMethod.esriMaplexNorthOfPoint;

maplexOverposterLayerProperties.CanTruncateLabel = false;

maplexOverposterLayerProperties.CanStackLabel = true;

maplexOverposterLayerProperties.LabelStackingProperties.AddSeparator("-", true, false, true);

...

ILabelEngineLayerProperties2 pLabelEngineLayerProps = (ILabelEngineLayerProperties2)pAnnoLayerProps;

pLabelEngineLayerProps.Symbol = pTextSymbol;

pLabelEngineLayerProps.OverposterLayerProperties = (IOverposterLayerProperties)maplexOverposterLayerProperties;

pLabelEngineLayerProps.Expression = "[" + strFieldName + "]";

IActiveView m_ActiveView = pMapDoc.ActiveView;

m_ActiveView.Refresh();

There is no error in the execution but the separator is not added.

Do you have an idea of the problem ?

Thanks in advance

Reply
0 Kudos
1 Solution

Accepted Solutions
NicolasFaget1
New Contributor III

Yeah it works ! Thank you very much Jon !

the good code :

// The labels placement 

IMaplexLabelStackingProperties objLabelStackingProperties = new MaplexLabelStackingProperties();

objLabelStackingProperties.AddSeparator("-", true, false, true);

IMaplexOverposterLayerProperties maplexOverposterLayerProperties = new MaplexOverposterLayerPropertiesClass();

maplexOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;                           

maplexOverposterLayerProperties.PointPlacementMethod = esriMaplexPointPlacementMethod.esriMaplexNorthOfPoint;

maplexOverposterLayerProperties.CanTruncateLabel = false;

maplexOverposterLayerProperties.CanStackLabel = true;

maplexOverposterLayerProperties.LabelStackingProperties = objLabelStackingProperties;

View solution in original post

Reply
0 Kudos
6 Replies
JonMorris2
Occasional Contributor II

Where is the part of your code where the label properties are added to the feature layer? Where does pAnnoLayerProps come from?

If you make changes to the label properties object they are not automatically propogated back to the layer. You need to add them again. If you have a reference to the layer as IGeoFeatureLayer you can do something like

pGeoFeatureLayer.AnnotationProperties = (IAnnotateLayerPropertiesCollection) pLabelEngineLayerProps;

Reply
0 Kudos
NicolasFaget1
New Contributor III

Thank you for your help.

my full code :

// The labels placement 

IMaplexOverposterLayerProperties maplexOverposterLayerProperties = new MaplexOverposterLayerPropertiesClass();

maplexOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;                           

maplexOverposterLayerProperties.PointPlacementMethod = esriMaplexPointPlacementMethod.esriMaplexNorthOfPoint;

maplexOverposterLayerProperties.CanTruncateLabel = false;

maplexOverposterLayerProperties.CanStackLabel = true;

maplexOverposterLayerProperties.LabelStackingProperties.AddSeparator("-", true, false, true);

//Font Style

ITextSymbol pTextSymbol = new TextSymbolClass();

pTextSymbol.Font = CreateDefaultFontDisp();

IRgbColor arcColor = new RgbColor();

arcColor.Red = 13;

arcColor.Green = 75;

arcColor.Blue = 151;

pTextSymbol.Color = arcColor;

//Execution

IGeoFeatureLayer pGeoFeatureLayer = (IGeoFeatureLayer)pLayer;

IAnnotateLayerPropertiesCollection pAnnoLayerPropsColl = pGeoFeatureLayer.AnnotationProperties;     

pGeoFeatureLayer.DisplayAnnotation = true;                           

IAnnotateLayerProperties pAnnoLayerProps;

IElementCollection iec;

pAnnoLayerPropsColl.QueryItem(0, out pAnnoLayerProps, out iec, out iec);

ILabelEngineLayerProperties2 pLabelEngineLayerProps = (ILabelEngineLayerProperties2)pAnnoLayerProps;

pLabelEngineLayerProps.Symbol = pTextSymbol;

pLabelEngineLayerProps.OverposterLayerProperties = (IOverposterLayerProperties)maplexOverposterLayerProperties;

pLabelEngineLayerProps.Expression = "[" + strFieldName + "]";           

IActiveView m_ActiveView = pMapDoc.ActiveView;

m_ActiveView.Refresh();

Reply
0 Kudos
JonMorris2
Occasional Contributor II

I think you just need to add

     pGeoFeatureLayer.AnnotationProperties = pAnnoLayerPropsColl;

below the line

     pLabelEngineLayerProps.Expression = "[" + strFieldName + "]";

Reply
0 Kudos
NicolasFaget1
New Contributor III

It still does not nork.

In debug mode, after the addseparator method, the number is still 2 separators (2 by default).

I don't understand why.

Reply
0 Kudos
JonMorris2
Occasional Contributor II

Sorry, I'm just doing this off the top of my head. Have you tried creating a IMaplexLabelStackingProperties object, adding separators, then adding it back into the overposter layer properties?

Reply
0 Kudos
NicolasFaget1
New Contributor III

Yeah it works ! Thank you very much Jon !

the good code :

// The labels placement 

IMaplexLabelStackingProperties objLabelStackingProperties = new MaplexLabelStackingProperties();

objLabelStackingProperties.AddSeparator("-", true, false, true);

IMaplexOverposterLayerProperties maplexOverposterLayerProperties = new MaplexOverposterLayerPropertiesClass();

maplexOverposterLayerProperties.FeatureType = esriBasicOverposterFeatureType.esriOverposterPoint;                           

maplexOverposterLayerProperties.PointPlacementMethod = esriMaplexPointPlacementMethod.esriMaplexNorthOfPoint;

maplexOverposterLayerProperties.CanTruncateLabel = false;

maplexOverposterLayerProperties.CanStackLabel = true;

maplexOverposterLayerProperties.LabelStackingProperties = objLabelStackingProperties;

View solution in original post

Reply
0 Kudos