OutPicturecj.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 OutPicturecj : ConditionPanel
  19. {
  20. private string fileName = string.Empty;
  21. private GeoRegion m_geo = null;
  22. public OutPicturecj()
  23. {
  24. this.ConditionPanelName = "裁剪地图导出图片";
  25. InitializeComponent();
  26. }
  27. protected override void OnLoad(EventArgs e)
  28. {
  29. }
  30. private void uiButton1_Click(object sender, EventArgs e)
  31. {
  32. SaveFileDialog sfd = new SaveFileDialog();
  33. sfd.InitialDirectory = System.Environment.GetFolderPath(System.Environment.SpecialFolder.DesktopDirectory);
  34. sfd.Title = "请选择要保存的文件路径";
  35. sfd.Filter = "所有文件|*.*";
  36. if (sfd.ShowDialog() == DialogResult.OK)
  37. {
  38. fileName = sfd.FileName;
  39. uiTextBox1.Text = fileName;
  40. }
  41. }
  42. public override object Do(DockPanel dockPanel = null)
  43. {
  44. this.IsShowResultWindow = false;
  45. if (string.IsNullOrEmpty(fileName))
  46. { UIMessageTip.ShowError("请选择要保存的文件路径"); return false; }
  47. ImageType imgType = ImageType.JPG; ;
  48. if (uiRBjpg.Checked) { imgType = ImageType.JPG; }
  49. if (uiRBbmp.Checked) { imgType = ImageType.BMP; }
  50. if (uiRBpng.Checked) { imgType = ImageType.PNG; }
  51. bool result = MapControl.Map.OutputMapToFile(fileName, imgType, 96, MapControl.Map.ViewBounds, false);
  52. ComsStatic.ShowUIMessageTipOKorError(result, "地图导出图片");
  53. return true;
  54. }
  55. private void uiButton2_Click(object sender, EventArgs e)
  56. {
  57. MapControl.Action = SuperMap.UI.Action.CreatePolygon;
  58. MapControl.Tracked += MapControl_Tracked;
  59. }
  60. private void uiButton3_Click(object sender, EventArgs e)
  61. {
  62. MapControl.Action = SuperMap.UI.Action.Pan;
  63. MapControl.Map.TrackingLayer.Clear();
  64. MapControl.Map.RefreshEx(MapControl.Map.ViewBounds);
  65. }
  66. private void MapControl_Tracked(object sender, SuperMap.UI.TrackedEventArgs e)
  67. {
  68. if (e.Geometry is null) return;
  69. m_geo = e.Geometry.Clone() as GeoRegion;
  70. if (m_geo is null) { Sunny.UI.UIMessageTip.ShowError("区域绘制失败"); return; }
  71. m_geo.Style = ComsStatic.geoStyle_Red_1mm_OpaqueRate;
  72. MapControl.Map.TrackingLayer.Clear();
  73. MapControl.Map.TrackingLayer.Add(m_geo, "GeoRectangle");
  74. MapControl.Map.IsClipRegionEnabled = true;
  75. MapControl.Map.ClipRegion = m_geo;
  76. MapControl.Map.Refresh();
  77. }
  78. public override void AfterClose()
  79. {
  80. MapControl.Map.IsClipRegionEnabled = false;
  81. MapControl.Tracked -= MapControl_Tracked;
  82. base.AfterClose();
  83. }
  84. }
  85. }