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));; }
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>()); } } }