예제 #1
0
 private void Add_Click(object sender, EventArgs e)
 {
     OpenFileDialog.Filter = "All formats|*.mif;*.txt;*.grd|Layers (*.mif)|*.mif|Grid files (*.grd)|*.grd|Geopoints file (*.txt)|*.txt";
     if (OpenFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
     {
         if (OpenFileDialog.FileName != null)
         {
             try
             {
                 bool isExistName = true;
                 for (int i = 0; i < map.LayersCount; i++)
                 {
                     if (map.Layers[i].Name == System.IO.Path.GetFileNameWithoutExtension(OpenFileDialog.FileName))
                     {
                         isExistName = false;
                     }
                 }
                 if (isExistName)
                 {
                     if (Path.GetExtension(OpenFileDialog.FileName) == ".mif")
                     {
                         VectorLayer MifLayer = new VectorLayer();
                         map.AddLayer(MifLayer);
                         MifLayer.LoadFromFile(OpenFileDialog.FileName);
                     }
                     if (Path.GetExtension(OpenFileDialog.FileName) == ".txt")
                     {
                         VectorLayer vectorLayer = new VectorLayer();
                         map.AddLayer(vectorLayer);
                         vectorLayer.LoadFromFile(OpenFileDialog.FileName);
                     }
                     if (Path.GetExtension(OpenFileDialog.FileName) == ".grd")
                     {
                         GridLayer gridLayer = new GridLayer(new GridGeometry(), map);
                         map.AddLayer(gridLayer);
                         gridLayer.LoadFromFile(OpenFileDialog.FileName);
                     }
                     map.ZoomToAll();
                     map.Refresh();
                     LayerControl.RefreshList();
                 }
                 else
                 {
                     MessageBox.Show("Слой с таким именем уже существует.");
                 }
                 isExistName = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
             }
         }
     }
 }