ThinkGeo.com    |     Documentation    |     Premium Support

Using BingMap with printing

Hi,

I need to use bingMap or googleMap in print (PrinterInteractiveOverlay).

Is there any sample for this ?



thanks

Hi Maryam,



I think the below codes should be fit for you:


private void DisplayMap_Load(object sender, EventArgs e)
{
    winformsMap1.MapUnit = GeographyUnit.Meter;
    winformsMap1.BackgroundOverlay.BackgroundBrush = new GeoSolidBrush(GeoColor.GeographicColors.ShallowOcean);
 
    PrinterInteractiveOverLay printerOverlay = new PrinterInteractiveOverLay();
    winformsMap1.InteractiveOverlays.Add(“PrintPreviewOverlay”, printerOverlay);
    winformsMap1.InteractiveOverlays.MoveToBottom(“PrintPreviewOverlay”);
 
    PagePrinterLayer pagePrinterLayer = new PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait);
    pagePrinterLayer.Open();
    printerOverlay.PrinterLayers.Add(“PageLayer”, pagePrinterLayer);
 
    AddMapLayer();
 
    winformsMap1.CurrentExtent = RectangleShape.ScaleUp(pagePrinterLayer.GetPosition(), 10).GetBoundingBox();
    winformsMap1.Refresh();
}
 
private void AddMapLayer()
{
    // Create the MapPrinterLayer and set the position
    MapPrinterLayer mapPrinterLayer = new MapPrinterLayer();
    mapPrinterLayer.MapUnit = GeographyUnit.Meter;
    mapPrinterLayer.MapExtent = new RectangleShape(-13939426.6371, 6701997.4056, -7812401.86, 2626987.386962);
    mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1));
    mapPrinterLayer.Open();
 
    RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch);
    mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch);
 
    mapPrinterLayer.Layers.Add(new GoogleMapsLayer());
 
    // Add the MapPrinterLayer to the PrinterInteractiveOverlay
    PrinterInteractiveOverLay printerInteractiveOverLay = (PrinterInteractiveOverLay)winformsMap1.InteractiveOverlays[“PrintPreviewOverlay”];
    printerInteractiveOverLay.PrinterLayers.Add(“MapLayer”, mapPrinterLayer);
}
 
private RectangleShape GetPageBoundingBox(PrintingUnit unit)
{
    // This helper method gets the pages bounding box in the unit requested
    PrinterInteractiveOverLay printerInteractiveOverLay = (PrinterInteractiveOverLay)winformsMap1.InteractiveOverlays[“PrintPreviewOverlay”];
    PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)printerInteractiveOverLay.PrinterLayers[“PageLayer”];
    return pagePrinterLayer.GetPosition(unit); ;
}

The result should be look like this if everything goes well.





Hope it helps.

Regards,

Troy

Hi,

Your answer really helped me .



thanks a lot .

Hi Maryam, 
  
 Good to hear it works for you. 
 If any other queries, don’t hesitate to let us know. 
  
 Regards, 
 Troy