OutPicture.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using WWPipeLine.MapBasic.Conditions;
  11. using Sunny.UI;
  12. using WeifenLuo.WinFormsUI.Docking;
  13. using SuperMap.Mapping;
  14. using WWPipeLine.MapBasic;
  15. using SuperMap.Data;
  16. namespace WWPipeLine.MapTools.Conditions.ShuJuChuLi
  17. {
  18. public partial class OutPicture : ConditionPanel
  19. {
  20. private string fileName = string.Empty;
  21. public bool isGeo = false;
  22. private GeoRegion m_geo = null;
  23. public OutPicture()
  24. {
  25. this.ConditionPanelName = "地图导出图片";
  26. this.IsShowResultWindow = false;
  27. this.SetSize(500, 200);
  28. InitializeComponent();
  29. }
  30. protected override void OnLoad(EventArgs e)
  31. {
  32. if (isGeo)
  33. {
  34. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  35. MapControl.Tracked += MapControl_Tracked;
  36. }
  37. }
  38. private void MapControl_Tracked(object sender, SuperMap.UI.TrackedEventArgs e)
  39. {
  40. if (e.Geometry is null) return;
  41. m_geo = e.Geometry.Clone() as GeoRegion;
  42. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
  43. m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  44. MapControl.Map.TrackingLayer.Clear();
  45. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRectangle");
  46. MapControl.Map.IsClipRegionEnabled = true;
  47. MapControl.Map.ClipRegion = m_geo;
  48. MapControl.Map.Refresh();
  49. }
  50. public override void AfterClose()
  51. {
  52. MapControl.Map.IsClipRegionEnabled = false;
  53. MapControl.Tracked -= MapControl_Tracked;
  54. base.AfterClose();
  55. }
  56. private void uiButton1_Click(object sender, EventArgs e)
  57. {
  58. SaveFileDialog sfd = new SaveFileDialog();
  59. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  60. sfd.Title = "请选择要保存的文件路径";
  61. sfd.Filter = "所有文件|*.*";
  62. if (sfd.ShowDialog() == DialogResult.OK)
  63. {
  64. fileName = sfd.FileName;
  65. uiTextBox1.Text = fileName;
  66. }
  67. }
  68. public override object Do(DockPanel dockPanel = null)
  69. {
  70. if (string.IsNullOrEmpty(fileName))
  71. { UIMessageTip.ShowError("请选择要保存的文件路径"); return false; }
  72. ImageType imgType = ImageType.JPG; ;
  73. if (uiRBjpg.Checked) { imgType = ImageType.JPG; }
  74. if (uiRBbmp.Checked) { imgType = ImageType.BMP; }
  75. if (uiRBpng.Checked) { imgType = ImageType.PNG; }
  76. bool result = MapControl.Map.OutputMapToFile(fileName, imgType, 96, MapControl.Map.ViewBounds, false);
  77. ComsStatic.ShowUIMessageTipOKorError(result, "地图导出图片");
  78. return true;
  79. }
  80. }
  81. }