ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
ThinkGeo Cloud
ThinkGeo UI Controls
ThinkGeo Open Source
Help and Support
External Resources
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Sample.aspx.cs" Inherits="CSSamples.Samples.Sample" %> <%@ Register Assembly="WebEdition" Namespace="ThinkGeo.MapSuite.WebEdition" TagPrefix="cc1" %> <%@ Register Src="Footer.ascx" TagName="Footer" TagPrefix="uc1" %> <%@ Register Src="Banner.ascx" TagName="Banner" TagPrefix="uc2" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <link href="Resources/css.css" rel="stylesheet" type="text/css" /> <title>Display a Simple Map - Map Suite Web Sample application</title> </head> <body> <form id="form1" runat="server"> <table border="0" cellpadding="0" cellspacing="0" style="width: 100%;"> <tr> <td> <uc2:Banner ID="Header1" runat="server" /> </td> </tr> <tr> <td align="center"> <div id="MapContainer"> <div id="MapControlerBox"> <div> <asp:Label ID="ControlLabel" type="text" runat="server">Instructions</asp:Label> </div> <div> <asp:Label ID="ControlDescription" type="text" runat="server">This sample shows how to do the print preview</asp:Label> </div> <div id="ControlPanel"> <asp:Label ID="labPageSize" runat="server">Paper Size:</asp:Label> <asp:DropDownList ID="lisSize" runat="server" Width="180px" ClientIDMode="Static" AutoPostBack="true" OnSelectedIndexChanged="lisSize_SelectedIndexChanged"> <asp:ListItem>ANSI A- 8.5 x 11 (A4)</asp:ListItem> <asp:ListItem>ANSI B- 11 x 17 (A3)</asp:ListItem> <asp:ListItem>ANSI C- 17 x 22 (A2)</asp:ListItem> <asp:ListItem>ANSI D- 22 x 34 (A1)</asp:ListItem> <asp:ListItem>ANSI E- 34 x 44 (A0)</asp:ListItem> </asp:DropDownList> <asp:Label ID="labOrentation" runat="server">Orientation</asp:Label> <asp:DropDownList ID="lisOrientation" runat="server" Width="180px" AutoPostBack="true" ClientIDMode="Static" OnSelectedIndexChanged="lisOrientation_SelectedIndexChanged"> <asp:ListItem>Portrait</asp:ListItem> <asp:ListItem>Landscape</asp:ListItem> </asp:DropDownList> <asp:Label ID="labPercentage" runat="server">Percentage</asp:Label> <asp:DropDownList ID="lisPercentage" runat="server" AutoPostBack="true" Width="180px" ClientIDMode="Static" OnSelectedIndexChanged="lisPercentage_SelectedIndexChanged"> <asp:ListItem>5%</asp:ListItem> <asp:ListItem>10%</asp:ListItem> <asp:ListItem>20%</asp:ListItem> <asp:ListItem>30%</asp:ListItem> <asp:ListItem>40%</asp:ListItem> <asp:ListItem Selected="True">50%</asp:ListItem> <asp:ListItem>60%</asp:ListItem> <asp:ListItem>70%</asp:ListItem> <asp:ListItem>80%</asp:ListItem> <asp:ListItem>90%</asp:ListItem> <asp:ListItem>100%</asp:ListItem> <asp:ListItem>110%</asp:ListItem> <asp:ListItem>120%</asp:ListItem> <asp:ListItem>150%</asp:ListItem> <asp:ListItem>200%</asp:ListItem> <asp:ListItem>300%</asp:ListItem> <asp:ListItem>400%</asp:ListItem> <asp:ListItem>500%</asp:ListItem> <asp:ListItem>600%</asp:ListItem> <asp:ListItem>700%</asp:ListItem> <asp:ListItem>800%</asp:ListItem> </asp:DropDownList> </div> <div id="ControlPanel2"> <div> <asp:Label ID="labExport" type="text" runat="server" Text="Export:" /> </div> <asp:Button ID="btnToBitmap" Width="100px" runat="server" Text="To Bitmap" OnClick="btnToBitmap_Click" /> <asp:Button ID="btnToPDF" Width="100px" runat="server" Text="To PDF" OnClick="btnToPDF_Click" /> <asp:Button ID="btnToPrinter" Width="100px" runat="server" Text="To Printer" OnClick="btnToPrinter_Click" /> </div> <div id="ControlPanel3"> <div> <asp:Label ID="labPan" type="text" runat="server" Text="Pan around the map:" /> </div> <div id="ZoomList"> <asp:Button ID="btnZoomIn" Width="70px" runat="server" Text="ZoomIn" OnClick="btnZoomIn_Click" /> <asp:Button ID="btnZoomOut" Width="70px" runat="server" Text="ZoomOut" OnClick="btnZoomOut_Click" /> </div> <div id="PanList1"> <asp:Button ID="btnPanNorth" Width="30px" runat="server" Text="N" OnClick="btnPan_Click" /> </div> <div id="PanList2"> <asp:Button ID="btnPanWest" Width="30px" runat="server" Text="W" OnClick="btnPan_Click" /> <asp:Button ID="btnPanEast" Width="30px" runat="server" Text="E" OnClick="btnPan_Click" /> </div> <div id="PanList3"> <asp:Button ID="btnPanSouth" Width="30px" runat="server" Text="S" OnClick="btnPan_Click" /> </div> </div> </div> <div id="MapAddTool"> <div> <asp:Label ID="AddToolsLabel" type="text" runat="server">Instructions</asp:Label> </div> <div id="AddToolBox"> <div id="normal"> <asp:Label ID="ToolDescription" type="text" runat="server">Tools</asp:Label> </div> <div id="AddBox"> <div id="ImageButton1"> <asp:ImageButton ID="btnAddLabel" runat="server" Height="25px" ImageUrl="~/Resources/_Label.png" Width="100px" OnClick="btnAddContrl_Click" /> </div> <div id="ImageButton2"> <asp:ImageButton ID="btnAddImage" runat="server" Height="25px" ImageUrl="~/Resources/iamge.png" Width="100px" OnClick="btnAddContrl_Click" /> </div> <div id="ImageButton3"> <asp:ImageButton ID="btnAddScaleLine" runat="server" Height="25px" ImageUrl="~/Resources/scale_line.png" Width="100px" OnClick="btnAddContrl_Click" /> </div> <div id="ImageButton4"> <asp:ImageButton ID="btnAddScaleBar" runat="server" Height="25px" ImageUrl="~/Resources/scale_Bar.png" Width="100px" OnClick="btnAddContrl_Click" /> </div> <div id="ImageButton5"> <asp:ImageButton ID="btnAddGrid" runat="server" Height="25px" ImageUrl="~/Resources/grid.png" Width="100px" OnClick="btnAddContrl_Click" /> </div> </div> </div> </div> <div id="MapBox"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <cc1:Map ID="Map1" runat="server" Height="100%" Width="100%"> </cc1:Map> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnToBitmap" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnToPDF" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnToPrinter" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnZoomIn" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnZoomOut" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnPanNorth" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnPanWest" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnPanEast" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnPanSouth" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="lisSize" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="lisOrientation" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="lisPercentage" EventName="SelectedIndexChanged" /> <asp:AsyncPostBackTrigger ControlID="btnAddLabel" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnAddImage" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnAddScaleLine" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnAddScaleBar" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="btnAddGrid" EventName="Click" /> </Triggers> </asp:UpdatePanel> </div> </div> </td> </tr> <tr> <td> <uc1:Footer ID="Footer1" runat="server" /> </td> </tr> </table> </form> </body> <script type="text/javascript"> function doRefresh() { <%=ClientScript.GetPostBackEventReference(UpdatePanel1, "") %>; } function resizeElementHeight() { var height = 0; var width = 0; var body = window.document.body; if (window.innerHeight) { height = window.innerHeight; } else if (body.parentElement.clientHeight) { height = body.parentElement.clientHeight; } else if (body && body.clientHeight) { height = body.clientHeight; } if (window.innerWidth) { width = window.innerWidth; } else if (body.parentElement.clientWidth) { width = body.parentElement.clientWidth; } else if (body && body.clientWidth) { width = body.clientWidth; } document.getElementById('MapContainer').style.width = (width - 40) + 'px'; document.getElementById('MapContainer').style.height = (height - 170) + 'px'; containerWidth = document.getElementById('MapContainer').style.width; containerHeight = document.getElementById('MapContainer').style.height; if (width - 40 > 1050) { document.getElementById('MapBox').style.width = (width - 444) + 'px'; } else { document.getElementById('MapBox').style.width = '646px'; } if ((height - 170) > 550) { document.getElementById('MapBox').style.height = (height - 170) + 'px'; document.getElementById('MapControlerBox').style.height = (height - 170) + 'px'; document.getElementById('MapAddTool').style.height = (height - 170) + 'px'; } else { document.getElementById('MapBox').style.height = '550px'; document.getElementById('MapControlerBox').style.height = '550px'; document.getElementById('MapAddTool').style.height = '550px'; } if(alreadyrun){ doRefresh(); alreadyrun=0; } } var alreadyrun = 0 if (document.addEventListener) document.addEventListener("DOMContentLoaded", function () { alreadyrun = 1; resizeElementHeight() }, false) else if (document.all && !window.opera) { document.write('<script type="text/javascript" id="contentloadtag" defer="defer" src="javascript:void(0)"><\/script>') var contentloadtag = document.getElementById("contentloadtag") contentloadtag.onreadystatechange = function () { if (this.readyState == "complete") { alreadyrun = 1 resizeElementHeight() } } } window.onload = function () { setTimeout("if (!alreadyrun) resizeElementHeight()", 0); } window.onresize=function() { setTimeout("if (!alreadyrun) resizeElementHeight()", 0); } </script> </html>
using System; using System.Collections.ObjectModel; using System.Data; using System.Diagnostics; using System.Drawing; using System.Drawing.Printing; using System.Text; using System.Web.UI; using System.Web.UI.WebControls; using PdfSharp; using PdfSharp.Pdf; using ThinkGeo.MapSuite.Core; using ThinkGeo.MapSuite.WebEdition; namespace CSSamples.Samples { public partial class Sample : System.Web.UI.Page { #region add PrinterLayer Elements protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { SetupMapWithBlankPage(); AddMapLayer(); AddTitleLayer(); } } private void SetupMapWithBlankPage() { Map1.MapTools.Logo.Enabled = false; Map1.MapBackground.BackgroundBrush = new GeoSolidBrush(GeoColor.FromHtml("#E5E3DF")); Map1.MapUnit = GeographyUnit.Meter; PagePrinterLayer pagePrinterLayer = new PagePrinterLayer(PrinterPageSize.AnsiA, PrinterOrientation.Portrait); pagePrinterLayer.Open(); Map1.ZoomLevelSet = new PrinterZoomLevelSet(Map1.MapUnit, PrinterHelper.GetPointsPerGeographyUnit(Map1.MapUnit)); Map1.CurrentExtent = pagePrinterLayer.GetBoundingBox(); Map1.CurrentScale = PrinterHelper.GetPointsPerGeographyUnit(Map1.MapUnit) * 2; LayerOverlay printerInteractiveOverlay = new LayerOverlay(); printerInteractiveOverlay.Name = "PageOverlay"; printerInteractiveOverlay.Layers.Add("PageLayer", pagePrinterLayer); Map1.CustomOverlays.Add(printerInteractiveOverlay); pagePrinterLayer.Close(); } private void AddMapLayer() { RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); ShapeFileFeatureLayer worldMapLayer = new ShapeFileFeatureLayer(MapPath(@"~\SampleData\Countries02.shp")); worldMapLayer.FeatureSource.Projection = new Proj4Projection(Proj4Projection.GetDecimalDegreesParametersString(), Proj4Projection.GetGoogleMapParametersString()); worldMapLayer.FeatureSource.Projection.Open(); worldMapLayer.Open(); Collection<Feature> features = worldMapLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns); worldMapLayer.ZoomLevelSet.ZoomLevel01.DefaultAreaStyle = AreaStyles.Country1; worldMapLayer.ZoomLevelSet.ZoomLevel01.ApplyUntilZoomLevel = ApplyUntilZoomLevel.Level20; MapPrinterLayer mapPrinterLayer = new MapPrinterLayer(); mapPrinterLayer.BackgroundMask = new AreaStyle(new GeoPen(GeoColor.StandardColors.Black, 1)); mapPrinterLayer.MapUnit = GeographyUnit.Meter; mapPrinterLayer.MapExtent = worldMapLayer.GetBoundingBox(); worldMapLayer.Close(); mapPrinterLayer.SetPosition(8, 7, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y + 1, PrintingUnit.Inch); mapPrinterLayer.Layers.Add(worldMapLayer); LayerOverlay printerInteractiveOverlay = GetPageOverlay(); printerInteractiveOverlay.Layers.Add("mapPrinterLayer", mapPrinterLayer); } private void AddTitleLayer() { RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer(); labelPrinterLayer.Text = "Population > 70 Million"; labelPrinterLayer.Font = new GeoFont("Arial", 10, DrawingFontStyles.Bold); labelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black); labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.AutoSizeText; 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); LayerOverlay printerInteractiveOverlay = GetPageOverlay(); printerInteractiveOverlay.Layers.Add("title", labelPrinterLayer); } private void AddGridLayer() { RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); DataGridPrinterLayer dataGridPrinterLayer = new DataGridPrinterLayer(); dataGridPrinterLayer.TextFont = new GeoFont("Arial", 8); dataGridPrinterLayer.TextHorizontalAlignment = TextHorizontalAlignment.Left; dataGridPrinterLayer.DataTable = new DataTable(); dataGridPrinterLayer.DataTable.Columns.Add("FIPS_CNTRY"); dataGridPrinterLayer.DataTable.Columns.Add("CNTRY_NAME"); dataGridPrinterLayer.DataTable.Columns.Add("LONG_NAME"); dataGridPrinterLayer.DataTable.Columns.Add("POP_CNTRY"); ShapeFileFeatureLayer postgreLayer = (((MapPrinterLayer)GetPageOverlay().Layers["mapPrinterLayer"]).Layers[0]) as ShapeFileFeatureLayer; postgreLayer.Open(); RectangleShape _boundingbox = postgreLayer.FeatureSource.GetBoundingBox(); Collection<Feature> features = postgreLayer.QueryTools.GetAllFeatures(ReturningColumnsType.AllColumns); postgreLayer.Close(); int pageSize = 0; foreach (Feature feature in features) { if (pageSize < 11 && int.Parse(feature.ColumnValues["POP_CNTRY"]) > 70000000) { pageSize++; dataGridPrinterLayer.DataTable.Rows.Add(new object[4] { feature.ColumnValues["FIPS_CNTRY"], feature.ColumnValues["CNTRY_NAME"], feature.ColumnValues["LONG_NAME"], feature.ColumnValues["POP_CNTRY"] }); } } dataGridPrinterLayer.SetPosition(8, 2.5, pageBoundingbox.GetCenterPoint().X, pageBoundingbox.GetCenterPoint().Y - 4, PrintingUnit.Inch); LayerOverlay printerInteractiveOverlay = GetPageOverlay(); if (printerInteractiveOverlay.Layers.Contains("grid")) { string script = @"alert('We have added a data grid!');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } else { printerInteractiveOverlay.Layers.Add("grid", dataGridPrinterLayer); } } private void AddLogoImage() { GeoImage compassGeoImage = new GeoImage(MapPath(@"~\SampleData\Compass.png")); ImagePrinterLayer imagePrinterLayer = new ImagePrinterLayer(compassGeoImage); RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); imagePrinterLayer.SetPosition(.75, .75, pageBoundingbox.GetCenterPoint().X + 3.5, pageBoundingbox.GetCenterPoint().Y - 2.0, PrintingUnit.Inch); LayerOverlay printerInteractiveOverlay = GetPageOverlay(); if (printerInteractiveOverlay.Layers.Contains("logo")) { string script = @"alert('We have added an image!');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } else { printerInteractiveOverlay.Layers.Add("logo", imagePrinterLayer); } } private void AddScaleLineLayer() { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); MapPrinterLayer mapPrinterLayer = (MapPrinterLayer)printerInteractiveOverlay.Layers["mapPrinterLayer"]; ScaleLinePrinterLayer scaleLinePrinterLayer = new ScaleLinePrinterLayer(mapPrinterLayer); scaleLinePrinterLayer.MapUnit = GeographyUnit.Meter; RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); scaleLinePrinterLayer.SetPosition(1.25, .25, pageBoundingbox.GetCenterPoint().X - 3.25, pageBoundingbox.GetCenterPoint().Y - 2.25, PrintingUnit.Inch); if (printerInteractiveOverlay.Layers.Contains("ScaleLineLayer")) { string script = @"alert('We have added a scale line!');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } else { printerInteractiveOverlay.Layers.Add("ScaleLineLayer", scaleLinePrinterLayer); } } private void AddLabelLayer() { StringBuilder noteSpace = new StringBuilder(); noteSpace.Append("Notes: "); for (int i = 0; i < 160; i++) { noteSpace.Append("_ "); } LabelPrinterLayer labelPrinterLayer = new LabelPrinterLayer(); labelPrinterLayer.Text = noteSpace.ToString(); labelPrinterLayer.Font = new GeoFont("Arial", 14, DrawingFontStyles.Regular); labelPrinterLayer.TextBrush = new GeoSolidBrush(GeoColor.StandardColors.Black); labelPrinterLayer.PrinterWrapMode = PrinterWrapMode.WrapText; RectangleShape pageBoundingbox = GetPageBoundingBox(PrintingUnit.Inch); double noteSpaceWidth = 3.6; labelPrinterLayer.SetPosition(noteSpaceWidth, 2, pageBoundingbox.LowerLeftPoint.X + 0.25 + noteSpaceWidth / 2 + 4.3, pageBoundingbox.LowerLeftPoint.Y + 1.5, PrintingUnit.Inch); LayerOverlay printerInteractiveOverLay = GetPageOverlay(); if (printerInteractiveOverLay.Layers.Contains("label")) { string script = @"alert('We have added a label!');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } else { printerInteractiveOverLay.Layers.Add("label", labelPrinterLayer); } } #endregion #region Helper Methods private LayerOverlay GetPageOverlay() { foreach (var item in Map1.CustomOverlays) { if (item.Name == "PageOverlay") { return (item as LayerOverlay); } } return null; } private RectangleShape GetPageBoundingBox(PrintingUnit unit) { PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)GetPageOverlay().Layers["PageLayer"]; return pagePrinterLayer.GetPosition(unit); } 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; } #endregion #region Export Buttons protected void btnToBitmap_Click(object sender, EventArgs e) { PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)(GetPageOverlay().Layers["PageLayer"]); Bitmap bitmap = null; try { pagePrinterLayer.Open(); bitmap = new Bitmap((int)pagePrinterLayer.GetBoundingBox().Width, (int)pagePrinterLayer.GetBoundingBox().Height); GdiPlusGeoCanvas gdiPlusGeoCanvas = new GdiPlusGeoCanvas(); gdiPlusGeoCanvas.BeginDrawing(bitmap, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit); Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>(); foreach (Layer item in GetPageOverlay().Layers) { PrinterLayer printerLayer = (PrinterLayer)item; printerLayer.Open(); printerLayer.IsDrawing = true; if (!(printerLayer is PagePrinterLayer)) { printerLayer.Draw(gdiPlusGeoCanvas, labelsInAllLayers); } printerLayer.IsDrawing = false; printerLayer.Close(); } gdiPlusGeoCanvas.EndDrawing(); pagePrinterLayer.Close(); string filename = MapPath(@"~\SampleData\PrintingResults.bmp"); bitmap.Save(filename); Process.Start(filename); } catch (Exception ex) { string script = @"alert('" + ex.Message + " " + ex.StackTrace + "');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } finally { if (bitmap != null) { bitmap.Dispose(); } GetPageOverlay().Redraw(); } } protected void btnToPDF_Click(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); PagePrinterLayer pagePrinterLayer = printerInteractiveOverlay.Layers["PageLayer"] as PagePrinterLayer; PdfDocument pdfDocument = null; PdfPage pdfPage = null; try { pdfDocument = new PdfDocument(); pdfPage = pdfDocument.AddPage(); pdfPage.Orientation = pagePrinterLayer.Orientation == PrinterOrientation.Portrait ? PageOrientation.Portrait : PageOrientation.Landscape; pdfPage.Size = GetPdfPageSize(pagePrinterLayer.PageSize); PdfGeoCanvas pdfGeoCanvas = new PdfGeoCanvas(); pagePrinterLayer.Open(); pdfGeoCanvas.BeginDrawing(pdfPage, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit); pagePrinterLayer.Close(); Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>(); foreach (Layer item in printerInteractiveOverlay.Layers) { PrinterLayer printerLayer = item as PrinterLayer; printerLayer.Open(); printerLayer.IsDrawing = true; if (!(printerLayer is PagePrinterLayer)) { printerLayer.Draw(pdfGeoCanvas, labelsInAllLayers); } printerLayer.IsDrawing = false; printerLayer.Close(); } pdfGeoCanvas.EndDrawing(); string filename = MapPath(@"~\SampleData\PrintingResults.pdf"); pdfDocument.Save(filename); Process.Start(filename); } catch (Exception ex) { string script = @"alert('" + ex.Message + " " + ex.StackTrace + "');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } finally { if (pdfDocument != null) { pdfDocument.Dispose(); } printerInteractiveOverlay.Redraw(); } } protected void btnToPrinter_Click(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); PagePrinterLayer pagePrinterLayer = printerInteractiveOverlay.Layers["PageLayer"] as PagePrinterLayer; 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 = new Rectangle(0, 0, Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Width), Convert.ToInt32(printDocument.DefaultPageSettings.PrintableArea.Height)); pagePrinterLayer.Open(); printerGeoCanvas.BeginDrawing(printDocument, pagePrinterLayer.GetBoundingBox(), Map1.MapUnit); pagePrinterLayer.Close(); Collection<SimpleCandidate> labelsInAllLayers = new Collection<SimpleCandidate>(); foreach (Layer item in printerInteractiveOverlay.Layers) { PrinterLayer printerLayer = item as PrinterLayer; printerLayer.Open(); printerLayer.IsDrawing = true; if (!(printerLayer is PagePrinterLayer)) { printerLayer.Draw(printerGeoCanvas, labelsInAllLayers); } printerLayer.IsDrawing = false; printerLayer.Close(); } printerGeoCanvas.EndDrawing(); printerInteractiveOverlay.Redraw(); } #endregion #region Pan & Zoom Buttons protected void btnZoomIn_Click(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerInteractiveOverlay.Layers["mapPrinterLayer"])); if (!mapPrinterLayer.IsOpen) { mapPrinterLayer.Open(); } ZoomLevelSet zoomLevelSet = new ZoomLevelSet(); double newScale = ZoomLevelSet.GetLowerZoomLevelScale(ExtentHelper.GetScale(mapPrinterLayer.MapExtent, (float)mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.MapUnit), zoomLevelSet); mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height); printerInteractiveOverlay.Redraw(); } protected void btnZoomOut_Click(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerInteractiveOverlay.Layers["mapPrinterLayer"])); if (!mapPrinterLayer.IsOpen) { mapPrinterLayer.Open(); } ZoomLevelSet zoomLevelSet = new ZoomLevelSet(); double newScale = ZoomLevelSet.GetHigherZoomLevelScale(ExtentHelper.GetScale(mapPrinterLayer.MapExtent, (float)mapPrinterLayer.GetBoundingBox().Width, mapPrinterLayer.MapUnit), zoomLevelSet); mapPrinterLayer.MapExtent = ExtentHelper.ZoomToScale(newScale, mapPrinterLayer.MapExtent, mapPrinterLayer.MapUnit, (float)mapPrinterLayer.GetBoundingBox().Width, (float)mapPrinterLayer.GetBoundingBox().Height); printerInteractiveOverlay.Redraw(); } protected void btnPan_Click(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); MapPrinterLayer mapPrinterLayer = ((MapPrinterLayer)(printerInteractiveOverlay.Layers["mapPrinterLayer"])); if (sender == btnPanNorth) { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Up, 30); } else if (sender == btnPanWest) { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Left, 30); } else if (sender == btnPanEast) { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Right, 30); } else if (sender == btnPanSouth) { mapPrinterLayer.MapExtent = ExtentHelper.Pan(mapPrinterLayer.MapExtent, PanDirection.Down, 30); } printerInteractiveOverlay.Redraw(); } #endregion #region Combo Boxes & ContextMenu protected void lisSize_SelectedIndexChanged(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)printerInteractiveOverlay.Layers["PageLayer"]; string selectText = lisSize.SelectedItem.Text; 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; printerInteractiveOverlay.Redraw(); } protected void lisOrientation_SelectedIndexChanged(object sender, EventArgs e) { LayerOverlay printerInteractiveOverlay = GetPageOverlay(); PagePrinterLayer pagePrinterLayer = (PagePrinterLayer)printerInteractiveOverlay.Layers["PageLayer"]; string selectText = lisOrientation.SelectedItem.Text; if (selectText.ToUpper() == "LANDSCAPE") { pagePrinterLayer.Orientation = PrinterOrientation.Landscape; } else if (selectText.ToUpper() == "PORTRAIT") { pagePrinterLayer.Orientation = PrinterOrientation.Portrait; } printerInteractiveOverlay.Redraw(); } protected void lisPercentage_SelectedIndexChanged(object sender, EventArgs e) { String zoomString = lisPercentage.SelectedItem.Text; double currentZoom = Double.Parse(zoomString.Replace("%", "")); Map1.CurrentScale = PrinterHelper.GetPointsPerGeographyUnit(Map1.MapUnit) / (currentZoom / 100); LayerOverlay printerInteractiveOverlay = GetPageOverlay(); printerInteractiveOverlay.Redraw(); } #endregion #region ToolBox protected void btnAddContrl_Click(object sender, ImageClickEventArgs e) { ImageButton btn = sender as ImageButton; if (btn == btnAddLabel) { AddLabelLayer(); } else if (btn == btnAddImage) { AddLogoImage(); } else if (btn == btnAddScaleLine) { AddScaleLineLayer(); } else if (btn == btnAddScaleBar) { string script = @"alert('Not Implemented!');"; ScriptManager.RegisterStartupScript(this, this.GetType(), "alertForm", script, true); } else if (btn == btnAddGrid) { AddGridLayer(); } LayerOverlay printerInteractiveOverlay = GetPageOverlay(); printerInteractiveOverlay.Redraw(); } #endregion } }
//------------------------------------------------------------------------------ // <auto-generated> // This code was generated by a tool. // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. // </auto-generated> //------------------------------------------------------------------------------ namespace CSSamples.Samples { public partial class Sample { /// <summary> /// Head1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.HtmlControls.HtmlHead Head1; /// <summary> /// form1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.HtmlControls.HtmlForm form1; /// <summary> /// Header1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::Banner Header1; /// <summary> /// ControlLabel control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label ControlLabel; /// <summary> /// ControlDescription control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label ControlDescription; /// <summary> /// labPageSize control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label labPageSize; /// <summary> /// lisSize control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.DropDownList lisSize; /// <summary> /// labOrentation control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label labOrentation; /// <summary> /// lisOrientation control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.DropDownList lisOrientation; /// <summary> /// labPercentage control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label labPercentage; /// <summary> /// lisPercentage control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.DropDownList lisPercentage; /// <summary> /// labExport control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label labExport; /// <summary> /// btnToBitmap control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnToBitmap; /// <summary> /// btnToPDF control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnToPDF; /// <summary> /// btnToPrinter control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnToPrinter; /// <summary> /// labPan control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label labPan; /// <summary> /// btnZoomIn control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnZoomIn; /// <summary> /// btnZoomOut control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnZoomOut; /// <summary> /// btnPanNorth control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnPanNorth; /// <summary> /// btnPanWest control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnPanWest; /// <summary> /// btnPanEast control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnPanEast; /// <summary> /// btnPanSouth control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Button btnPanSouth; /// <summary> /// AddToolsLabel control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label AddToolsLabel; /// <summary> /// ToolDescription control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.Label ToolDescription; /// <summary> /// btnAddLabel control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ImageButton btnAddLabel; /// <summary> /// btnAddImage control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ImageButton btnAddImage; /// <summary> /// btnAddScaleLine control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ImageButton btnAddScaleLine; /// <summary> /// btnAddScaleBar control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ImageButton btnAddScaleBar; /// <summary> /// btnAddGrid control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.WebControls.ImageButton btnAddGrid; /// <summary> /// ScriptManager1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.ScriptManager ScriptManager1; /// <summary> /// UpdatePanel1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::System.Web.UI.UpdatePanel UpdatePanel1; /// <summary> /// Map1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::ThinkGeo.MapSuite.WebEdition.Map Map1; /// <summary> /// Footer1 control. /// </summary> /// <remarks> /// Auto-generated field. /// To modify move field declaration from designer file to code-behind file. /// </remarks> protected global::Footer Footer1; } }