/// <summary> /// Adds map element to the new layout. /// </summary> /// <param name="mapScale">The map scale.</param> /// <param name="extents">The extents.</param> private void AddMapElement(int mapScale, IEnvelope extents) { var map = _context.Map; var mapElement = new LayoutMap(); mapElement.Initialize(map, View.LayoutControl); mapElement.IsMain = true; mapElement.TileProvider = _context.Map.TileProvider; mapElement.LocationF = new PointF(PrintingConstants.DefaultMapOffset, PrintingConstants.DefaultMapOffset); mapElement.DrawTiles = map.Tiles.Visible; // calc the necessary size in paper coordinates GeoSize size; if (map.GetGeodesicSize(extents, out size)) { mapElement.SizeF = LayoutScaleHelper.CalcMapSize(mapScale, size, extents.Width / extents.Height); mapElement.Envelope = extents.Clone(); mapElement.Initialized = true; View.LayoutControl.AddToLayout(mapElement); View.LayoutControl.UpdateLayout(); View.LayoutControl.ZoomFitToScreen(); } }
/// <summary> /// Calculates canvas size in pixels. /// </summary> private bool CalculateCanvasSize(out SizeF size) { size = default(SizeF); var extents = View.MapExtents; GeoSize geoSize; if (!_context.Map.GetGeodesicSize(extents, out geoSize)) { return(false); } if (!NumericHelper.Equal(View.MapScale, 0.0)) { size = LayoutScaleHelper.CalcMapSize(View.MapScale, geoSize, extents.Width / extents.Height); } return(true); }
/// <summary> /// Called when fit to page is clicked. /// </summary> private void FitToPage() { GeoSize geoSize; if (_context.Map.GetGeodesicSize(View.MapExtents, out geoSize)) { var size = GetUsablePaperSize(); if (size == default(SizeF)) { return; } size.Width -= PrintingConstants.DefaultMapOffset * 2; size.Height -= PrintingConstants.DefaultMapOffset * 2; // let's adjust the size according to XY ratio, // since geodesic scale may differ along the axis double ratio = size.Width / size.Height; double ratio2 = View.MapExtents.Width / View.MapExtents.Height; if (ratio > ratio2) { size.Width /= (float)(ratio / ratio2); } else if (ratio < ratio2) { size.Height /= (float)(ratio2 / ratio); } double val = LayoutScaleHelper.CalcMapScale(geoSize, size, Enums.ScaleType.Average); int scale = Convert.ToInt32(val); if (scale == 0) { // it's probably an empty map, but let's display something all the same scale = 1; } View.PopulateScales(scale); } }