James, no problem.
1) here is the code to I'm using to create legend in MapControl:
private void DrawThematicItems(GeoCanvas canvas, FeatureLayer layer, float xOffset, float yOffset, GeoFont font)
{
GdiPlusGeoCanvas legendCanvas = new GdiPlusGeoCanvas();
Bitmap legendBitmap = null;
int themeIndent = 10;
ValueStyle valueStyle = (ValueStyle)layer.ZoomLevelSet.ZoomLevel01.CustomStyles[1];
foreach (ValueItem vi in valueStyle.ValueItems)
{
try
{
legendBitmap = new Bitmap((int)legendIconWidth, (int)legendIconHeight);
legendCanvas.BeginDrawing(legendBitmap, new RectangleShape(0, legendIconWidth, legendIconHeight, 0), GeographyUnit.DecimalDegree);
vi.DefaultAreaStyle.DrawSample(legendCanvas);
legendCanvas.Flush();
DrawingRectangleF layerRectangle = canvas.MeasureText(string.IsNullOrEmpty(vi.Value)? "(não informado)" : vi.Value, font);
if (canvas is GdiPlusGeoCanvas)
{
((GdiPlusGeoCanvas)canvas).DrawScreenImageWithoutScaling(legendBitmap, themeIndent + xOffset, yOffset + layerRectangle.Height / 2, DrawingLevel.LevelOne, 0, 0, 0);
}
DrawText(canvas, themeIndent + xOffset + layerRectangle.Width / 2 + 12, yOffset + layerRectangle.Height / 2, font, vi.Value);
// Update y offset.
yOffset += (legendIconHeight + 2);
}
finally
{
legendCanvas.EndDrawing();
if (legendBitmap != null)
{
legendBitmap.Dispose();
legendBitmap = null;
}
}
}
}
2) This is the code that prints to the PdfGeoCanvas:
private void bPrint_ItemClick(object sender, ItemClickEventArgs e)
{
PdfSharp.Pdf.PdfDocument document = new PdfSharp.Pdf.PdfDocument();
PdfSharp.Pdf.PdfPage page = document.AddPage();
PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas();
Collection<SimpleCandidate> labelsInLayers = new Collection<SimpleCandidate>();
pdfGeoCanvas.BeginDrawing(page, ExtentHelper.GetDrawingExtent(Map.CurrentExtent,
(float)(page.Width.Point), (float)(page.Height.Point)), GeographyUnit.Meter);
foreach (Layer layer in GISHelper.Overlay.Layers)
{
layer.Open();
layer.Draw(pdfGeoCanvas, labelsInLayers);
layer.Close();
pdfGeoCanvas.Flush();
}
if (LegendInMap.EditValue.ToString() == "Apenas na Impressão")
CreateLegend();
for (int i = 0; i < Map.AdornmentOverlay.Layers.Count; i++)
{
if ((Map.AdornmentOverlay.Layers.Name != "Legend") || (LegendInMap.EditValue.ToString() != "Nunca"))
{
Map.AdornmentOverlay.Layers.Open();
Map.AdornmentOverlay.Layers.Draw(pdfGeoCanvas, labelsInLayers);
Map.AdornmentOverlay.Layers.Close();
pdfGeoCanvas.Flush();
}
}