Hi Guys,
I have code dynamically generate the legend.
Working well with 2.5
In 2.6, the spacing seem to be issue.
What is the changes in 2.6 related to layout tool legend objects?
I am using usual approach like create legend and changing font from the CIMLegend from definition.
Legend resultLegend = LayoutElementFactory.Instance.CreateLegend(activeLayoutView.Layout, leg_env, activedMapFrame);
Below is the screenshot, left is 2.6, right is 2.5
Any Idea? @UmaHarano @Wolf
Solved! Go to Solution.
Hi Guys,
I managed to solve this issue.
The problem is at generating the text symbol.
Have to add the following properties to make spacing work properly in 2.6 and 2.7.
destinationTextSymbol.LetterWidth = 100;
destinationTextSymbol.WordSpacing = 100;
destinationTextSymbol.Kerning = true;
destinationTextSymbol.Ligatures = true;
destinationTextSymbol.FontType = FontType.TTOpenType;
destinationTextSymbol.ExtrapolateBaselines = true;
destinationTextSymbol.HaloSize = 1;
Best Regards,
Than
Hi Guys,
I managed to solve this issue.
The problem is at generating the text symbol.
Have to add the following properties to make spacing work properly in 2.6 and 2.7.
destinationTextSymbol.LetterWidth = 100;
destinationTextSymbol.WordSpacing = 100;
destinationTextSymbol.Kerning = true;
destinationTextSymbol.Ligatures = true;
destinationTextSymbol.FontType = FontType.TTOpenType;
destinationTextSymbol.ExtrapolateBaselines = true;
destinationTextSymbol.HaloSize = 1;
Best Regards,
Than
Hi,
I am also trying to customize my legend. Your solution is to use destinationTextSymbol in controlling the text properties in the legend. Can you please elaborate a bit on this solution?
The following is my code for creating a legend. But after that, I am confused on HOW and WHERE to insert CIMTextSymbol reference such as your destinationTextSymbol. Can you please help me with that? Thanks.
Coordinate2D llLegend = new Coordinate2D(10, 10);
Coordinate2D urLegend = new Coordinate2D(100, 50);
Envelope leg_env = EnvelopeBuilder.CreateEnvelope(llLegend, urLegend);
LayoutElementFactory.Instance.CreateLegend(layout, leg_env, mfElm);
Hi @GyanendraGurung ,
Here is the code snippet, the destinationTextSymbol is the variable actually,
Sorry, I didn't post full set of code earlier.
Let me know when you got issue,
//Separate method
public void FormatDefaultArialTextSymbol(CIMTextSymbol sourceTextSymbol, CIMTextSymbol destinationTextSymbol, string FontStyleName, double fontSize, double height)
{
destinationTextSymbol.CopyFrom(sourceTextSymbol);
destinationTextSymbol.FontStyleName = FontStyleName;
destinationTextSymbol.FontFamilyName = "Arial";
destinationTextSymbol.Height = height;
destinationTextSymbol.SetSize(fontSize);
destinationTextSymbol.ExtrapolateBaselines = false;
destinationTextSymbol.VerticalAlignment = VerticalAlignment.Center;
destinationTextSymbol.BillboardMode3D = BillboardMode.None;
destinationTextSymbol.Symbol3DProperties = new CIM3DSymbolProperties()
{
DominantSizeAxis3D = DominantSizeAxis.Z,
ScaleY = 0,
ScaleZ = 0,
RotationOrder3D = RotationOrder.XYZ
};
//from 2.6 - word spacing and letter width are required to set and ,need to be 100
destinationTextSymbol.LetterWidth = 100;
destinationTextSymbol.WordSpacing = 100;
destinationTextSymbol.Kerning = true;
destinationTextSymbol.Ligatures = true;
destinationTextSymbol.FontType = FontType.TTOpenType;
destinationTextSymbol.ExtrapolateBaselines = true;
destinationTextSymbol.HaloSize = 1;
}
/// actual code
//Get layout and map frame first
LayoutView activeLayoutView = LayoutView.Active;
MapFrame activedMapFrame = activeLayoutView.ActiveMapFrame;
ProgressorSource ps = new ProgressorSource("Adding Legend...");
QueuedTask.Run(() =>
{
Console.WriteLine("Create legend area");
//Search for a style project item by name
StyleProjectItem arcgis_2dStyle = Project.Current.GetItems<StyleProjectItem>().First(si => si.Name == "ArcGIS 2D");
Envelope mapFrameExtent = (activedMapFrame.GetDefinition() as CIMMapFrame).Frame.Extent;
double xmin = mapFrameExtent.XMax - (mapFrameExtent.Width / 4);
double bufferX = mapFrameExtent.Width * 0.01;
double bufferY = mapFrameExtent.Height * 0.01;//1%
double xmax = mapFrameExtent.XMax - bufferX;
double ymax = mapFrameExtent.YMax - bufferY;
double ymin = mapFrameExtent.YMin + bufferY;
Envelope leg_env = EnvelopeBuilder.CreateEnvelope(xmin, ymin, xmax, ymax);
Legend resultLegend = LayoutElementFactory.Instance.CreateLegend(activeLayoutView.Layout, leg_env, activedMapFrame);
CIMLegend legendDef = resultLegend.GetDefinition() as CIMLegend;
legendDef.Title = "Legend";
legendDef.ShowTitle = true;
SymbolStyleItem paragraph = arcgis_2dStyle.SearchSymbols(StyleItemType.TextSymbol, "Paragraph").FirstOrDefault();
CIMTextSymbol aParaSymbol = paragraph.Symbol as CIMTextSymbol;
FormatDefaultArialTextSymbol(aParaSymbol, (legendDef.TitleSymbol.Symbol as CIMTextSymbol), "Bold",12,8);
legendDef.AutoAdd = true;
legendDef.AutoFonts = true;
legendDef.AutoVisibility = true;
legendDef.FittingStrategy = LegendFittingStrategy.AdjustColumnsAndSize;
ps.Message = "Adding Legend - Formatting Text";
foreach (CIMLegendItem legItem in legendDef.Items)
{
FormatDefaultArialTextSymbol(aParaSymbol, (legItem.HeadingSymbol.Symbol as CIMTextSymbol), "Regular",8, 8);
FormatDefaultArialTextSymbol(aParaSymbol, (legItem.LabelSymbol.Symbol as CIMTextSymbol), "Regular",8, 8);
FormatDefaultArialTextSymbol(aParaSymbol, (legItem.DescriptionSymbol.Symbol as CIMTextSymbol), "Regular",8, 8);
FormatDefaultArialTextSymbol(aParaSymbol, (legItem.LayerNameSymbol.Symbol as CIMTextSymbol), "Bold", 9, 8);
FormatDefaultArialTextSymbol(aParaSymbol, (legItem.GroupLayerNameSymbol.Symbol as CIMTextSymbol), "Bold", 9, 8);
legItem.AutoVisibility = true;
}
resultLegend.SetName("Legend");
resultLegend.SetDefinition(legendDef);
}, ps.Progressor);