private void OnFormLoad(object sender, EventArgs e)
        {
            global.LoadFormSettings(this, true);

            _layersHandler = global.MappingForm.MapLayersHandler;
            _layersHandler.CurrentLayer += OnCurrentLayer;

            lvERDDAP.Visible = false;

            lvERDDAP.Columns.Clear();
            lvERDDAP.Columns.Add("Title");
            lvERDDAP.Columns.Add("Data start");
            lvERDDAP.Columns.Add("Data end");
            lvERDDAP.Columns.Add("Frequency");
            lvERDDAP.Columns.Add("Cell size");
            lvERDDAP.ShowItemToolTips = true;
            SizeColumns(lvERDDAP);

            //ERDDAP data download
            ERDDAPMetadataFiles.OnMetadataRead += OnERDDAPMetadataRead;
            _ERDDAPMetadataFolder      = ERDDAPMetadataFiles.GetMetadataDirectorySetting();
            txtMetadataFolderPath.Text = _ERDDAPMetadataFolder;

            if (_ERDDAPMetadataFolder.Length > 0)
            {
                //the xml metadatafiles in the metadata folder determines what FAD3 can download from ERDDAP
                ERDDAPMetadataFiles.MetadataDirectory = _ERDDAPMetadataFolder;

                //read xml metadata for ERDDAP download
                ERDDAPMetadataFiles.ReadISO9115Metadata();
            }

            lvERDDAP.Visible = true;

            MakeGridFromPoints.MapLayersHandler = global.MappingForm.MapLayersHandler;
            MakeGridFromPoints.OnExtentDefined += OnExtentDefined;
            Text = "Download gridded, oceanographic, spatio-temporal data using ERDDAP";
            UpdateDataSetCount();
            SetupTooltips();
        }
        private void OnButtonClick(object sender, EventArgs e)
        {
            switch (((Button)sender).Name)
            {
            case "btnCreateExtent":

                MakeGridFromPoints.MakeExtentShapeFile();

                break;

            case "btnOk":
                Close();
                break;

            case "btnGetMetadataFolder":
                var folderBrowser = new FolderBrowserDialog();
                folderBrowser.ShowNewFolderButton = true;
                if (_ERDDAPMetadataFolder == "")
                {
                    folderBrowser.SelectedPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
                }
                else
                {
                    folderBrowser.SelectedPath = _ERDDAPMetadataFolder;
                }
                folderBrowser.Description = "Locate folder containing ERDDAP metadata";
                DialogResult result = FolderBrowserLauncher.ShowFolderBrowser(folderBrowser);
                if (result == DialogResult.OK)
                {
                    ERDDAPMetadataFiles.MetadataFiles.Clear();
                    lvERDDAP.Visible = false;
                    lvERDDAP.Items.Clear();
                    ERDDAPMetadataFiles.MetadataDirectory = folderBrowser.SelectedPath;
                    ERDDAPMetadataFiles.ReadISO9115Metadata();
                    ERDDAPMetadataFiles.SaveMetadataDirectorySetting(folderBrowser.SelectedPath);
                    txtMetadataFolderPath.Text = folderBrowser.SelectedPath;
                    lvERDDAP.Visible           = true;
                    UpdateDataSetCount();
                }
                break;

            case "btnDownload":
                if (txtMinLat.Text.Length > 0 &&
                    txtMaxLat.Text.Length > 0 &&
                    txtMinLon.Text.Length > 0 &&
                    txtMaxLon.Text.Length > 0 &&
                    lvERDDAP.SelectedItems.Count > 0)
                {
                    ERDDAPConfigureDownloadForm edf = ERDDAPConfigureDownloadForm.GetInstance(this);
                    if (edf.Visible)
                    {
                        edf.BringToFront();
                    }
                    else
                    {
                        string identifier = lvERDDAP.SelectedItems[0].Name;
                        edf.BeginPosition    = ERDDAPMetadataFiles.MetadataFiles[identifier].BeginPosition;
                        edf.EndPosition      = ERDDAPMetadataFiles.MetadataFiles[identifier].EndPosition;
                        edf.Dimensions       = ERDDAPMetadataFiles.MetadataFiles[identifier].Dimensions;
                        edf.DataExtents      = _selectionExtent;
                        edf.GridParameters   = ERDDAPMetadataFiles.MetadataFiles[identifier].DataParameters;
                        edf.Credits          = ERDDAPMetadataFiles.MetadataFiles[identifier].Credits;
                        edf.Title            = ERDDAPMetadataFiles.MetadataFiles[identifier].DataTitle;
                        edf.DataAbstract     = ERDDAPMetadataFiles.MetadataFiles[identifier].DataAbstract;
                        edf.LegalConstraint  = ERDDAPMetadataFiles.MetadataFiles[identifier].LegalConstraints;
                        edf.GridExtents      = ERDDAPMetadataFiles.MetadataFiles[identifier].Extents;
                        edf.URL              = ERDDAPMetadataFiles.MetadataFiles[identifier].URL;
                        edf.Identifier       = identifier;
                        edf.MetadataFileName = ERDDAPMetadataFiles.MetadataFiles[identifier].MetaDataFilename;
                        edf.Show(this);
                    }
                }
                else
                {
                    MessageBox.Show("Data extents must be provided and data to download must be selected");
                }
                break;
            }
        }