using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using WWPipeLine.MapBasic.Conditions; using Sunny.UI; using WeifenLuo.WinFormsUI.Docking; using SuperMap.Mapping; using WWPipeLine.MapBasic; using SuperMap.Data.Conversion; using SuperMap.Data; using SuperMap.UI; using SuperMap.Layout; namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi { public partial class OutPrint : ConditionPanel { private Map m_Map; private MapLayoutControl m_MapLayoutControl; private MapLayout m_MapLayout; private Point2D addPoint = new Point2D(0, 0); /// /// 纸张大小 /// private PaperSize paperSize = PaperSize.A4; /// /// 纸张方向 Landscape横向 Portrait纵向 /// private PaperOrientation paperOrientation = PaperOrientation.Landscape; public OutPrint() { this.ConditionPanelName = "地图打印"; this.IsShowPanelFooter = false; this.SetSize(Screen.PrimaryScreen.Bounds.Width - 300, Screen.PrimaryScreen.Bounds.Height - 200); InitializeComponent(); m_Map = MapControl.Map; foreach (Layer lyr in m_Map.Layers) { Layer PrintLayer = MapControl.Map.Layers.FindLayer(lyr.Name); if (PrintLayer is null) continue; lyr.IsVisible = PrintLayer.IsVisible; } m_Map.Workspace.Maps.SetMapXML(m_Map.Name, m_Map.ToXML()); m_MapLayoutControl = new MapLayoutControl(); m_MapLayoutControl.Dock = DockStyle.Fill; m_MapLayoutControl.MapLayout.Workspace = ComsStatic.Workspace; m_MapLayoutControl.IsHorizontalScrollbarVisible = false; m_MapLayoutControl.IsVerticalScrollbarVisible = false; uiPlayout.Controls.Add(m_MapLayoutControl); uiPlayout.Controls.SetChildIndex(m_MapLayoutControl, 0); } protected override void OnLoad(EventArgs e) { m_MapLayout = m_MapLayoutControl.MapLayout; m_MapLayout.Paper.Grid = new GridSetting() { IsVisible = false }; m_MapLayout.Paper.Size = paperSize; m_MapLayout.Paper.Orientation = paperOrientation; m_MapLayout.ZoomToPaper(); GeoMap geoMap = new GeoMap(); geoMap.MapName = m_Map.Name; geoMap.MapCenter = m_Map.ViewBounds.Center; geoMap.MapScale = m_Map.Scale; Double width = m_Map.ViewBounds.Width * m_Map.Scale * 10000;//将地图范围转换为逻辑坐标 Double height = m_Map.ViewBounds.Height * m_Map.Scale * 10000; geoMap.Shape = new GeoRectangle(m_MapLayout.Center, width, height, 0); //if (paperOrientation == PaperOrientation.Landscape) //横向 // geoMap.Shape = new GeoRectangle(m_MapLayout.Center, m_MapLayout.Printer.PaperHeight * 0.8, m_MapLayout.Printer.PaperWidth * 0.8, 0); //else // geoMap.Shape = new GeoRectangle(m_MapLayout.Center, m_MapLayout.Printer.PaperWidth * 0.8, m_MapLayout.Printer.PaperHeight * 0.8, 0); geoMap.IsGridVisible = false;//是否显示网格 geoMap.IsBorderVisible = false;//地图几何对象的边框是否显示 m_MapLayout.Elements.AddNew(geoMap); //m_MapLayout.Refresh(); //Bitmap bitmap = new Bitmap(m_MapLayoutControl.Width, m_MapLayoutControl.Height); //m_MapLayoutControl.DrawToBitmap(bitmap, new Rectangle(0, 0, bitmap.Width, bitmap.Height)); //GeoMap addedGeoMap = m_MapLayout.Elements.GetGeometry() as GeoMap; //addedGeoMap.MapCenter = m_Map.ViewBounds.Center; //m_MapLayout.Elements.SetGeometry(addedGeoMap); foreach (String printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { toolStripCBdayinji.Items.Add(printer); } toolStripCBdayinji.SelectedIndex = 0; toolStripComboBoxPapersize.ComboBox.ValueMember = "sizekey"; toolStripComboBoxPapersize.ComboBox.DisplayMember = "sizedesc"; toolStripComboBoxPapersize.ComboBox.DataSource = ComsStatic.getPaperSize(); } //public override bool ShowModal() { return true; } private int GetGeoMapID() { int mapID = -1; LayoutElements les = m_MapLayout.Elements; les.MoveFirst(); while (!les.IsEOF) { if (les.GetGeometry().Type == GeometryType.GeoMap) { mapID = les.GetID(); break; } les.MoveNext(); } return mapID; } private void toolStripButtonNorthArrow_Click(object sender, EventArgs e) { GeoNorthArrow geoNorthArrow = new GeoNorthArrow(); geoNorthArrow.StyleType = NorthArrowStyleType.ArrowInsideCircle; geoNorthArrow.BindingGeoMapID = GetGeoMapID(); geoNorthArrow.SetGeoReference(new Rectangle2D(addPoint, new Size2D(100, 100))); bool result = m_MapLayout.Elements.AddNew(geoNorthArrow); ComsStatic.ShowUIMessageTipOKorError(result, "添加指南针"); } private void toolStripButtonScale_Click(object sender, EventArgs e) { GeoMapScale geoMapScale = new GeoMapScale(GetGeoMapID(), addPoint, 500, 20); geoMapScale.ScaleType = GeoMapScaleType.RailwayMidSplit; geoMapScale.ScaleUnit = Unit.Meter; geoMapScale.LeftDivisionCount = 4; geoMapScale.SegmentCount = 4; bool result = m_MapLayout.Elements.AddNew(geoMapScale); ComsStatic.ShowUIMessageTipOKorError(result, "添加比例尺"); } private void toolSBLegend_Click(object sender, EventArgs e) { GeoLegend geoLegend = new GeoLegend(MapControl.Map.Name, MapControl.Map.Workspace); geoLegend.Center = addPoint; bool result = m_MapLayout.Elements.AddNew(geoLegend); ComsStatic.ShowUIMessageTipOKorError(result, "添加图例"); } private void toolStripButton1_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(toolStripTextBoxBiaoti.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标题内容"); return; } TextStyle textStyle = new TextStyle(); textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter; textStyle.Bold = true; textStyle.IsSizeFixed = true; textStyle.FontHeight = 5.0; TextPart textPart = new TextPart(toolStripTextBoxBiaoti.Text, addPoint, 0); GeoText geoText = new GeoText(textPart, textStyle); bool result = m_MapLayout.Elements.AddNew(geoText); ComsStatic.ShowUIMessageTipOKorError(result, "添加标题内容"); toolStripTextBoxBiaoti.Text = ""; } private void toolStripButton2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(toolStripTextBoxBiaozhu.Text)) { Sunny.UI.UIMessageTip.ShowError("请先输入需要添加的标注内容"); return; } TextStyle textStyle = new TextStyle(); textStyle.Alignment = SuperMap.Data.TextAlignment.TopCenter; textStyle.IsSizeFixed = true; textStyle.FontHeight = 3.0; TextPart textPart = new TextPart(toolStripTextBoxBiaozhu.Text, addPoint, 0); GeoText geoText = new GeoText(textPart, textStyle); bool result = m_MapLayout.Elements.AddNew(geoText); ComsStatic.ShowUIMessageTipOKorError(result, "添加标注内容"); toolStripTextBoxBiaozhu.Text = ""; } private void toolStripButtonPrint_Click(object sender, EventArgs e) { string printerName = toolStripCBdayinji.SelectedItem as String; //toolStripCBdayinji.ComboBox.SelectedValue if (string.IsNullOrEmpty(printerName)) { Sunny.UI.UIMessageTip.ShowError("请先选择打印机"); return; } Printer printer = m_MapLayout.Printer; printer.PaperSize = paperSize; printer.Orientation = paperOrientation; printer.PrinterName = printerName; if (printer.IsValidPrinter) { WaitingForm wf = new WaitingForm((obj, args) => { m_MapLayout.Printer.Print(); }, "正在打印,请等待!"); wf.ShowDialog(this); ComsStatic.ShowOKLog("打印完成"); } else { ComsStatic.ShowErrorLog("当前打印机\"" + printerName + "\"无法打印"); return; } } private void toolStripButtonZoomIn_Click(object sender, EventArgs e) { m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomIn; } private void toolStripButtonZoomOut_Click(object sender, EventArgs e) { m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.ZoomOut; } private void toolStripButtonPan_Click(object sender, EventArgs e) { m_MapLayoutControl.LayoutAction = SuperMap.UI.Action.Pan; } private void toolStripComboBoxPapersize_SelectedIndexChanged(object sender, EventArgs e) { string sizeStr = toolStripComboBoxPapersize.ComboBox.SelectedValue.ToString(); paperSize = ComsStatic.getPaperSize(sizeStr); m_MapLayout.Paper.Size = paperSize; m_MapLayout.ZoomToPaper(); addPoint = new Point2D(m_MapLayout.Paper.Margin.Left, ComsStatic.StringToInt(m_MapLayout.Paper.Height) - m_MapLayout.Paper.Margin.Top - m_MapLayout.Paper.Margin.Bottom); } private void toolStripButtonQuantu_Click(object sender, EventArgs e) { m_MapLayout.Paper.Size = paperSize; m_MapLayout.ZoomToPaper(); } } }