示例#1
0
        private void cbxPaperSize_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (IsLoaded)
            {
                // When the page size combobox is changed then we update the PagePrinterLayer to reflect the changes
                PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];
                PagePrinterLayer          pagePrinterLayer          = (PagePrinterLayer)printerInteractiveOverlay.PrinterLayers["PageLayer"];

                string selectText = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
                if (selectText.StartsWith("ANSI A"))
                {
                    pagePrinterLayer.PageSize = PrinterPageSize.AnsiA;
                }
                else if (selectText.StartsWith("ANSI B"))
                {
                    pagePrinterLayer.PageSize = PrinterPageSize.AnsiB;
                }
                else if (selectText.StartsWith("ANSI C"))
                {
                    pagePrinterLayer.PageSize = PrinterPageSize.AnsiC;
                }
                else if (selectText.StartsWith("ANSI D"))
                {
                    pagePrinterLayer.PageSize = PrinterPageSize.AnsiD;
                }
                else if (selectText.StartsWith("ANSI E"))
                {
                    pagePrinterLayer.PageSize = PrinterPageSize.AnsiE;
                }

                Map1.Refresh();
            }
        }
        private void SetupMapWithBlankPage()
        {
            // Setup the map unit, you want to always use feet or meters for the printer layout map.
            mapView.MapUnit = GeographyUnit.Meter;

            // Here we create the default zoom levels for the sample.  We have pre-created a PrinterZoomLevelSet
            // That pre-defines commonly used zoom levels based on percentages of zoom
            mapView.ZoomLevelSet = new PrinterZoomLevelSet(mapView.MapUnit, PrinterHelper.GetPointsPerGeographyUnit(mapView.MapUnit));

            // Here we set the background color to gray so there is contrast with the white page
            mapView.Background = System.Windows.Media.Brushes.White;

            // Create the PrinterInteractiveOverlay to contain all of the PrinterLayers.
            // The interactive overlay allows the layers to be interacted with
            PrinterInteractiveOverlay printerOverlay = new PrinterInteractiveOverlay();

            mapView.InteractiveOverlays.Add("PrintPreviewOverlay", printerOverlay);
            mapView.InteractiveOverlays.MoveToBottom("PrintPreviewOverlay");

            // Create the PagePrinterLayer which shows the page boundary and is the area the user will
            // arrange all of the other layer on top of.
            PagePrinterLayer pagePrinterLayer = new PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait);

            pagePrinterLayer.Open();
            pagePrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColors.LightGray, 1), GeoBrushes.White);
            printerOverlay.PrinterLayers.Add("PageLayer", pagePrinterLayer);

            // Get the pages extent, slightly scale it up, and then set that as the default current extent
            mapView.CurrentExtent = pagePrinterLayer.GetPosition().GetBoundingBox();

            // Set the minimum sscale of the map to the last zoom level
            mapView.MinimumScale = mapView.ZoomLevelSet.ZoomLevel20.Scale;
        }
        private RectangleShape GetPageBoundingBox(PrintingUnit unit)
        {
            // This helper method gets the pages bounding box in the unit requested
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = (PagePrinterLayer)printerInteractiveOverlay.PrinterLayers["PageLayer"];

            return(pagePrinterLayer.GetPosition(unit));;
        }
示例#4
0
        private void btnToBitmap_Click(object sender, RoutedEventArgs e)
        {
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;

            // Create a bitmap that is the size of the pages bounding box.  The page by default is in points unit
            // system which is very similar to pixels so that ampping is nice.
            GeoImage bitmap = null;

            try
            {
                bitmap = new GeoImage((int)pagePrinterLayer.GetBoundingBox().Width, (int)pagePrinterLayer.GetBoundingBox().Height);

                // Create a GeoCanvas and start the drawing
                GeoCanvas gdiPlusGeoCanvas = GeoCanvas.CreateDefaultGeoCanvas();
                gdiPlusGeoCanvas.BeginDrawing(bitmap, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);

                // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
                // except for the PagePrinterLayer
                Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();
                foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
                {
                    printerLayer.IsDrawing = true;
                    if (!(printerLayer is PagePrinterLayer))
                    {
                        printerLayer.Draw(gdiPlusGeoCanvas, labelsInAllLayers);
                    }
                    printerLayer.IsDrawing = false;
                }

                // End the drawing
                gdiPlusGeoCanvas.EndDrawing();

                //Save the resulting bitmap to a file and open the file to show the user
                string filename = "PrintingResults.bmp";
                bitmap.Save(filename);
                Process.Start("explorer.exe", filename);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " " + ex.StackTrace, "Exception");
            }
            finally
            {
                if (bitmap != null)
                {
                    bitmap.Dispose();
                }
            }
        }
 protected override void DrawTileCore(GeoCanvas geoCanvas)
 {
     base.DrawTileCore(geoCanvas);
     if (gridLayer != null)
     {
         PagePrinterLayer pagePrinterLayer = PrinterLayers.OfType <PagePrinterLayer>().FirstOrDefault();
         if (pagePrinterLayer != null)
         {
             if (!gridLayer.IsOpen)
             {
                 gridLayer.Open();
             }
             gridLayer.SetPosition(pagePrinterLayer.GetPosition());
             gridLayer.Draw(geoCanvas, new Collection <SimpleCandidate>());
         }
     }
 }
示例#6
0
        private void btnToPrintPreview_Click(object sender, RoutedEventArgs e)
        {
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;

            PrintDialog   printDialog   = new PrintDialog();
            PrintDocument printDocument = new PrintDocument();

            printDocument.DefaultPageSettings.Landscape = true;
            if (pagePrinterLayer.Orientation == PrinterOrientation.Portrait)
            {
                printDocument.DefaultPageSettings.Landscape = false;
            }

            printDocument.DefaultPageSettings.PaperSize = GetPrintPreviewPaperSize(pagePrinterLayer);

            PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();

            printerGeoCanvas.DrawingArea = printDocument.DefaultPageSettings.Bounds;
            printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit);

            // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
            // except for the PagePrinterLayer
            Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();

            foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
            {
                printerLayer.IsDrawing = true;
                if (!(printerLayer is PagePrinterLayer))
                {
                    printerLayer.Draw(printerGeoCanvas, labelsInAllLayers);
                }
                printerLayer.IsDrawing = false;
            }

            printerGeoCanvas.Flush();

            System.Windows.Forms.PrintPreviewDialog printPreviewDialog = new System.Windows.Forms.PrintPreviewDialog();
            printPreviewDialog.Document = printDocument;
            System.Windows.Forms.DialogResult dialogResult = printPreviewDialog.ShowDialog();
        }
示例#7
0
        private void cbxOrientation_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            // When the orientation combobox is changed then we update the PagePrinterLayer to reflect the changes
            if (this.IsLoaded)
            {
                PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)Map1.InteractiveOverlays["PrintPreviewOverlay"];
                PagePrinterLayer          pagePrinterLayer          = (PagePrinterLayer)printerInteractiveOverlay.PrinterLayers["PageLayer"];

                string selectText = ((ComboBoxItem)e.AddedItems[0]).Content.ToString();
                if (selectText.ToUpper() == "LANDSCAPE")
                {
                    pagePrinterLayer.Orientation = PrinterOrientation.Landscape;
                }
                else if (selectText.ToUpper() == "PORTRAIT")
                {
                    pagePrinterLayer.Orientation = PrinterOrientation.Portrait;
                }

                Map1.Refresh();
            }
        }
示例#8
0
        public static PaperSize GetPrintPreviewPaperSize(PagePrinterLayer pagePrinterLayer)
        {
            PaperSize printPreviewPaperSize = new PaperSize("AnsiA", 850, 1100);

            switch (pagePrinterLayer.PageSize)
            {
            case PrinterPageSize.AnsiA:
                printPreviewPaperSize = new PaperSize("AnsiA", 850, 1100);
                break;

            case PrinterPageSize.AnsiB:
                printPreviewPaperSize = new PaperSize("AnsiB", 1100, 1700);
                break;

            case PrinterPageSize.AnsiC:
                printPreviewPaperSize = new PaperSize("AnsiC", 1700, 2200);
                break;

            case PrinterPageSize.AnsiD:
                printPreviewPaperSize = new PaperSize("AnsiD", 2200, 3400);
                break;

            case PrinterPageSize.AnsiE:
                printPreviewPaperSize = new PaperSize("AnsiE", 3400, 4400);
                break;

            case PrinterPageSize.Custom:
                printPreviewPaperSize = new PaperSize("Custom Size", (int)pagePrinterLayer.CustomWidth, (int)pagePrinterLayer.CustomHeight);
                break;

            default:
                break;
            }

            return(printPreviewPaperSize);
        }
        private void btnPrint_Click(object sender, RoutedEventArgs e)
        {
            PrinterInteractiveOverlay printerInteractiveOverlay = (PrinterInteractiveOverlay)mapView.InteractiveOverlays["PrintPreviewOverlay"];
            PagePrinterLayer          pagePrinterLayer          = printerInteractiveOverlay.PrinterLayers["PageLayer"] as PagePrinterLayer;

            PrintDocument printDocument = new PrintDocument();

            printDocument.DefaultPageSettings.Landscape = true;
            if (pagePrinterLayer.Orientation == PrinterOrientation.Portrait)
            {
                printDocument.DefaultPageSettings.Landscape = false;
            }

            printDocument.DefaultPageSettings.PaperSize = new PaperSize("AnsiA", 850, 1100);

            PrinterGeoCanvas printerGeoCanvas = new PrinterGeoCanvas();

            printerGeoCanvas.DrawingArea = new Rectangle(0, 0, Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Width), Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Height));
            printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), mapView.MapUnit);

            // Loop through all of the PrintingLayer in the PrinterInteractiveOverlay and print all of the
            // except for the PagePrinterLayer
            Collection <SimpleCandidate> labelsInAllLayers = new Collection <SimpleCandidate>();

            foreach (PrinterLayer printerLayer in printerInteractiveOverlay.PrinterLayers)
            {
                printerLayer.IsDrawing = true;
                if (!(printerLayer is PagePrinterLayer))
                {
                    printerLayer.Draw(printerGeoCanvas, labelsInAllLayers);
                }
                printerLayer.IsDrawing = false;
            }

            printerGeoCanvas.EndDrawing();
        }