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
Solved! Go to Solution.
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;
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;
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();
I think you just need to add
pGeoFeatureLayer.AnnotationProperties = pAnnoLayerPropsColl;
below the line
pLabelEngineLayerProps.Expression = "[" + strFieldName + "]";
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.
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?
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;