Beispiel #1
0
        private void c_miOpenKeyhole_Click(object sender, EventArgs e)
        {
            String strHistoryFilename = Path.Combine(Path.Combine(UserPath, Settings.ConfigPath), "keyholehistory.cfg");

            String strInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);

            try
            {
                if (File.Exists(strHistoryFilename))
                {
                    String[] oContents = File.ReadAllLines(strHistoryFilename);
                    if (Directory.Exists(oContents[0]))
                    {
                        strInitialDirectory = oContents[0];
                    }
                }
            }
            catch (Exception)
            {
                // --- Problem reading last directory, just use My Documents ---
                strInitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            }

            OpenFileDialog bob = new OpenFileDialog();
            bob.Filter = "KML/KMZ Files|*.kml;*.kmz";
            bob.FilterIndex = 1;
            bob.InitialDirectory = strInitialDirectory;
            bob.Title = "Select Keyhole File to Open...";
            bob.Multiselect = false;
            bob.RestoreDirectory = true;

            if (bob.ShowDialog() == DialogResult.OK && File.Exists(bob.FileName))
            {
                try
                {
                    File.WriteAllText(strHistoryFilename, Path.GetDirectoryName(bob.FileName));
                }
                catch (Exception)
                {
                    // --- Problem saving last directory, just ignore it ---
                }

                try
                {
                    Dapple.KML.KMLLayerBuilder oBuilder = new Dapple.KML.KMLLayerBuilder(bob.FileName, WorldWindowSingleton, null);
                    AddLayerBuilder(oBuilder);
                    oBuilder.GoToLookAt(c_oWorldWindow);
                }
                catch (ArgumentException ex)
                {
                    Program.ShowMessageBox("An error occurred while loading file '" + Path.GetFileName(bob.FileName) + "':" + Environment.NewLine + Environment.NewLine + ex.Message, "Open KML File", MessageBoxButtons.OK, MessageBoxDefaultButton.Button1, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        private void AddKML(String strKMLFile, String strKMLName, bool blTemporary, bool blGoTo, GeographicBoundingBox oBounds)
        {
            try
            {
                this.UseWaitCursor = true;

                Dapple.KML.KMLLayerBuilder oBuilder = new Dapple.KML.KMLLayerBuilder(strKMLFile, strKMLName, WorldWindowSingleton, null, oBounds);
                oBuilder.Temporary = blTemporary;
                c_oLayerList.AddLayer(oBuilder);
                oBuilder.GoToLookAt(WorldWindowSingleton);
            }
            catch (Exception ex)
            {
                Program.ShowMessageBox(
                    "An error occurred while trying to add Keyhole file " + strKMLFile + ":" + Environment.NewLine + Environment.NewLine + ex.Message.ToString(),
                    "Open KML File",
                    MessageBoxButtons.OK,
                    MessageBoxDefaultButton.Button1,
                    MessageBoxIcon.Error
                    );
            }
            finally
            {
                this.UseWaitCursor = false;
            }
        }