OutPicturecjBak.cs 2.8 KB

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