AddLayerForm.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Windows.Forms;
  3. using System.IO;
  4. using FastReport.Utils;
  5. using FastReport.Forms;
  6. namespace FastReport.Map.Forms
  7. {
  8. internal partial class AddLayerForm : BaseDialogForm
  9. {
  10. private MapObject map;
  11. public MapObject Map
  12. {
  13. get { return map; }
  14. set { map = value; }
  15. }
  16. private void rbShapefile_CheckedChanged(object sender, EventArgs e)
  17. {
  18. tbShapefile.Enabled = rbShapefile.Checked;
  19. cbEmbed.Enabled = rbShapefile.Checked;
  20. }
  21. private void tbShapefile_ButtonClick(object sender, EventArgs e)
  22. {
  23. using (OpenFileDialog dialog = new OpenFileDialog())
  24. {
  25. dialog.Filter = Res.Get("FileFilters,ShpFile") + "|" + Res.Get("FileFilters,OsmFile");
  26. if (!String.IsNullOrEmpty(MapObject.ShapefileFolder))
  27. dialog.InitialDirectory = MapObject.ShapefileFolder;
  28. if (dialog.ShowDialog() == DialogResult.OK)
  29. tbShapefile.Text = dialog.FileName;
  30. }
  31. }
  32. private void AddLayerForm_FormClosing(object sender, FormClosingEventArgs e)
  33. {
  34. if (DialogResult == DialogResult.OK)
  35. {
  36. if (rbShapefile.Checked && String.IsNullOrEmpty(tbShapefile.Text))
  37. {
  38. FRMessageBox.Error(Res.Get("Messages,FileNameEmpty"));
  39. e.Cancel = true;
  40. }
  41. }
  42. }
  43. private void AddLayerForm_FormClosed(object sender, FormClosedEventArgs e)
  44. {
  45. if (DialogResult == DialogResult.OK)
  46. {
  47. if (rbShapefile.Checked)
  48. {
  49. if (Path.GetExtension(tbShapefile.Text).ToLower() == ".osm")
  50. {
  51. (Tag as MapEditorForm).EnableMercatorProtection(false);
  52. }
  53. map.Load(tbShapefile.Text);
  54. if (!cbEmbed.Checked)
  55. map.Layers[map.Layers.Count - 1].Shapefile = tbShapefile.Text;
  56. }
  57. else if (rbEmptyLayer.Checked)
  58. {
  59. MapLayer layer = new MapLayer();
  60. Map.Layers.Add(layer);
  61. layer.SpatialSource = SpatialSource.ApplicationData;
  62. }
  63. }
  64. }
  65. public override void Localize()
  66. {
  67. base.Localize();
  68. MyRes res = new MyRes("Forms,AddLayer");
  69. Text = res.Get("");
  70. lblSource.Text = res.Get("Source");
  71. rbShapefile.Text = res.Get("Shapefile");
  72. cbEmbed.Text = res.Get("Embed");
  73. rbEmptyLayer.Text = res.Get("Empty");
  74. }
  75. public override void UpdateDpiDependencies()
  76. {
  77. base.UpdateDpiDependencies();
  78. tbShapefile.Image = GetImage(1);
  79. }
  80. public AddLayerForm()
  81. {
  82. InitializeComponent();
  83. Localize();
  84. UIUtils.CheckRTL(this);
  85. UpdateDpiDependencies();
  86. }
  87. }
  88. }