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; using System.Drawing; namespace PostTest.Test { public partial class Temp : 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); //Map1.CurrentExtent = RectangleShape.ScaleUp(pagePrinterLayer.GetPosition(), 10).GetBoundingBox(); pagePrinterLayer.Close(); } private void GetPostDataScaled() { string connectString = "Server=localhost;User Id=postgres;Password=one;DataBase=my__db;"; RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); PostgreSqlFeatureLayer postgreLayer = new PostgreSqlFeatureLayer(connectString, "iringa_reg", "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; dataGridPrinterLayer.DataTable = new DataTable(); dataGridPrinterLayer.DataTable.Columns.Add("reg_name"); dataGridPrinterLayer.DataTable.Columns.Add("dist_name"); dataGridPrinterLayer.DataTable.Columns.Add("wrd_name"); dataGridPrinterLayer.DataTable.Columns.Add("vill_name"); int cn = 0; foreach (Feature feature in features) { cn++; if (cn < 11) { 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)); MapPrinterLayer mapPrinterLayer = new MapPrinterLayer(); mapPrinterLayer.MapUnit = GeographyUnit.Meter; mapPrinterLayer.Open(); LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer(); //Setup the text and the font.. labelPrinterLayer.Text = "Population > 70 Million"; labelPrinterLayer.Font = new GeoFont("Arial", 10, DrawingFontStyles.Bold); labelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black); labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText; // Set the labels position so that is it centered on the page one inch from the top PointShape labelCenter = new PointShape(); labelCenter.X = pageBoundingbox.UpperRightPoint.X - pageBoundingbox.Width / 2; labelCenter.Y = pageBoundingbox.UpperLeftPoint.Y - .5; labelPrinterLayer.SetPosition(5, 1, labelCenter, PrintingUnit.Inch); dataGridPrinterLayer.SetPosition(8, 2.5, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y - 4, PrintingUnit.Inch); mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch); mapPrinterLayer.Layers.Add(postgreLayer); PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)Map1.StaticOverlay.Layers["PageLayer"]; pagePrinterLayer.Open(); Map1.ZoomLevelSet = GetCustomZoomLevelSet(); Map1.CurrentExtent = pagePrinterLayer.GetBoundingBox(); ; LayerOverlay dynamicOverlay111 = new LayerOverlay(); dynamicOverlay111.IsBaseOverlay = false; dynamicOverlay111.Name = "All Property"; dynamicOverlay111.TileType = TileType.SingleTile; dynamicOverlay111.Layers.Add("_region", mapPrinterLayer); 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); LayerOverlay dynamicOverlay55p = new LayerOverlay(); dynamicOverlay55p.IsBaseOverlay = false; dynamicOverlay55p.Name = "Grid"; dynamicOverlay55p.TileType = TileType.SingleTile; dynamicOverlay55p.Layers.Add("_grid", labelPrinterLayer); Map1.CustomOverlays.Add(dynamicOverlay55p); } private ZoomLevelSet GetCustomZoomLevelSet() { ZoomLevelSet zoomLevelSet = new ZoomLevelSet(); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(3000)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(2800)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(2600)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(2400)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(2200)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(150)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(75)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(3.50)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(1.50)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.7)); zoomLevelSet.CustomZoomLevels.Add(new ZoomLevel(0.1)); return zoomLevelSet; } private RectangleShape GetPageBoundingBox(PrintingUnit unit) { PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)Map1.StaticOverlay.Layers["PageLayer"]; return pagePrinterLayer.GetPosition(unit); } private ZoomLevel GeAreatZoomLevel(double scale, AreaStyle areaStyle) { ZoomLevel zoomLevel = new ZoomLevel(scale); zoomLevel.DefaultAreaStyle = areaStyle; return zoomLevel; } } }