private bool CreateLayerInLegend(PdfContentByte content, Configuration.MapTabRow mapTab, List<CommonLayer> layerList, LegendProperties properties, CommonLayer layer, float indent)
{
if (!layerList.Contains(layer))
{
return false;
}
float layerHeight = GetLayerHeightInLegend(layerList, properties, layer);
if (properties.CurrentY < properties.Height && properties.CurrentY - layerHeight < 0)
{
if (properties.CurrentColumn == properties.NumColumns)
{
return true;
}
properties.CurrentX += properties.ColumnWidth + properties.ColumnSpacing;
properties.CurrentY = properties.Height;
properties.CurrentColumn += 1;
}
int numClasses = GetNumClasses(layer);
Configuration.LayerRow configLayer = mapTab.GetMapTabLayerRows().Where(o => String.Compare(o.LayerRow.LayerName, layer.Name, true) == 0).Select(o => o.LayerRow).FirstOrDefault();
string layerName = configLayer != null && !configLayer.IsDisplayNameNull() ? configLayer.DisplayName : layer.Name;
// write the layer name
if (layer.Type == CommonLayerType.Group || numClasses > 1)
{
properties.CurrentY -= properties.FontSize;
string name = layerName;
try
{
while (content.GetEffectiveStringWidth(name, false) > properties.ColumnWidth - indent)
{
name = name.Substring(0, name.Length - 1);
}
}
catch { }
content.BeginText();
content.SetFontAndSize(properties.BaseFont, properties.FontSize);
content.SetRGBColorFill(0, 0, 0);
content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, name, properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
content.EndText();
}
if (layer.Type == CommonLayerType.Group)
{
properties.CurrentY -= properties.LayerSpacing;
foreach (CommonLayer childLayer in layer.Children)
{
CreateLayerInLegend(content, mapTab, layerList, properties, childLayer, indent + 1.5f * properties.FontSize);
}
}
else
{
properties.CurrentY -= properties.ClassSpacing;
foreach (CommonLegendGroup legendGroup in layer.Legend.Groups)
{
foreach (CommonLegendClass legendClass in legendGroup.Classes)
{
if (!legendClass.ImageIsTransparent)
{
properties.CurrentY -= properties.SwatchHeight;
MemoryStream stream = new MemoryStream(legendClass.Image);
System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(stream);
float w = properties.SwatchHeight * bitmap.Width / bitmap.Height;
iTextSharp.text.Image image = iTextSharp.text.Image.GetInstance(legendClass.Image);
image.SetAbsolutePosition(properties.OriginX + properties.CurrentX + indent, properties.OriginY + properties.CurrentY - properties.SwatchHeight * 0.1f);
image.ScaleAbsolute(w, properties.SwatchHeight);
content.AddImage(image);
string label = numClasses > 1 ? legendClass.Label : layerName;
try
{
while (content.GetEffectiveStringWidth(label, false) > properties.ColumnWidth - properties.SwatchWidth - properties.ClassSpacing)
{
label = label.Substring(0, label.Length - 1);
}
}
catch { }
content.BeginText();
content.SetFontAndSize(properties.BaseFont, properties.FontSize);
content.SetRGBColorFill(0, 0, 0);
content.ShowTextAligned(PdfContentByte.ALIGN_LEFT, label, properties.OriginX + properties.CurrentX + indent + properties.SwatchWidth + properties.ClassSpacing, properties.OriginY + properties.CurrentY + (properties.SwatchHeight - properties.FontSize) / 2, 0);
content.EndText();
properties.CurrentY -= properties.ClassSpacing;
}
}
}
properties.CurrentY -= properties.LayerSpacing - properties.ClassSpacing;
}
return false;
}