using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; using System.Collections.ObjectModel; using PdfSharp.Pdf; using System.Drawing.Printing; using PdfSharp; using System.Diagnostics; using System.Data; namespace PostTest.Test { public partial class post_test : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (!Page.IsPostBack) { Map1.MapTools.Logo.Enabled = false; Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")); Map1.MapUnit = GeographyUnit.Meter; PrepareCanvas(); GetPostDataScaled(); } } } private void PrepareCanvas() { PagePrinterLayer pagePrinterLayer = new PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait); pagePrinterLayer.Open(); Map1.StaticOverlay.Layers.Add("PageLayer", pagePrinterLayer); } private void GetPostDataScaled() { string connectString = "Server=localhost;User Id=abc;Password=home;DataBase=my_db;"; PostgreSqlFeatureLayer postgreLayer = new PostgreSqlFeatureLayer(connectString, "iringa_region", "gid"); InMemoryFeatureLayer mapShapeLayer = new InMemoryFeatureLayer(); mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.FillSolidBrush.Color = GeoColor.FromArgb(150, 60, 180, 60); mapShapeLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle.OutlinePen.Color = GeoColor.GeographicColors.DeepOcean; mapShapeLayer.ZoomLevelSet.CustomZoomLevels.Add(GeAreatZoomLevel(20, AreaStyles.County1)); postgreLayer.Open(); RectangleShape _boundingbox = postgreLayer.FeatureSource.GetBoundingBox(); Collection features = postgreLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns); postgreLayer.Close(); DataGridPrinterLayer dataGridPrinterLayer = new DataGridPrinterLayer(); dataGridPrinterLayer.TextFont = new GeoFont("Arial", 8); dataGridPrinterLayer.TextHorizontalAlignment = TextHorizontalAlignment.Left; RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); dataGridPrinterLayer.SetPosition(8, 2.5, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y - 4, PrintingUnit.Inch); dataGridPrinterLayer.DataTable = new DataTable(); dataGridPrinterLayer.DataTable.Columns.Add("reg_name"); dataGridPrinterLayer.DataTable.Columns.Add("dst_name"); dataGridPrinterLayer.DataTable.Columns.Add("wrd_name"); dataGridPrinterLayer.DataTable.Columns.Add("vill_name"); foreach (Feature feature in features) { dataGridPrinterLayer.DataTable.Rows.Add(new object[4] { feature.ColumnValues["reg_name"], feature.ColumnValues["dist_name"], feature.ColumnValues["ward_name"], feature.ColumnValues["vill_name"] }); } postgreLayer.ZoomLevelSet.CustomZoomLevels.Add(GeAreatZoomLevel(30, AreaStyles.Country1)); postgreLayer.ZoomLevelSet.CustomZoomLevels.Add(GeAreatZoomLevel(15, AreaStyles.CreateSimpleAreaStyle(GeoColor.StandardColors.LightBlue, GeoColor.SimpleColors.PaleGreen))); postgreLayer.ZoomLevelSet.CustomZoomLevels.Add(GeAreatZoomLevel(20, AreaStyles.County1)); Map1.ZoomLevelSet = GetCustomZoomLevelSet(); Map1.CurrentExtent = _boundingbox; LayerOverlay dynamicOverlay111 = new LayerOverlay(); dynamicOverlay111.IsBaseOverlay = false; dynamicOverlay111.Name = "All Property"; dynamicOverlay111.TileType = TileType.SingleTile; dynamicOverlay111.Layers.Add("_region", postgreLayer); Map1.CustomOverlays.Add(dynamicOverlay111); LayerOverlay dynamicOverlay55 = new LayerOverlay(); dynamicOverlay55.IsBaseOverlay = false; dynamicOverlay55.Name = "Grid"; dynamicOverlay55.TileType = TileType.SingleTile; dynamicOverlay55.Layers.Add("_grid", dataGridPrinterLayer); Map1.CustomOverlays.Add(dynamicOverlay55); } private ZoomLevelSet GetCustomZoomLevelSet() { ZoomLevelSet zoomLevelSet = new ZoomLevelSet(); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(30)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(28)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(26)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(24)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(22)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(1.5)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.75)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.350)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.150)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.07)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.01)); return zoomLevelSet; } private ZoomLevel GeAreatZoomLevel(double scale, AreaStyle areaStyle) { ZoomLevel zoomLevel = new ZoomLevel(scale); zoomLevel.DefaultAreaStyle = areaStyle; return zoomLevel; } private PageSize GetPdfPageSize(PrinterPageSize pageSize) { PageSize pdfPageSize = PageSize.Letter; switch (pageSize) { case PrinterPageSize.AnsiA: pdfPageSize = PageSize.Letter; break; case PrinterPageSize.AnsiB: pdfPageSize = PageSize.Ledger; break; case PrinterPageSize.AnsiC: pdfPageSize = PageSize.A2; break; case PrinterPageSize.AnsiD: pdfPageSize = PageSize.A1; break; case PrinterPageSize.AnsiE: pdfPageSize = PageSize.A0; break; case PrinterPageSize.Custom: throw new NotSupportedException(); default: throw new NotSupportedException(); } return pdfPageSize; } private 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 RectangleShape GetPageBoundingBox(PrintingUnit unit) { PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)Map1.StaticOverlay.Layers["PageLayer"]; return pagePrinterLayer.GetPosition(unit); } } }