Exemplo n.º 1
0
        private void _btn_to_kml_Click(object sender, EventArgs e)
        {
            StringBuilder placemarks = new StringBuilder();
            StringBuilder path       = new StringBuilder();
            double        lat_home_rad;
            double        lon_home_rad;

            // we need a home position in case the navigation uses relative coordinates
            AskHome ah = new AskHome();

            if (ah.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            lat_home_rad = ah.GetLatitudeRad();
            lon_home_rad = ah.GetLongitudeRad();

            // generate the KML
            string kml = KmlNavigation.BuildKml(GetNavigationList(), lat_home_rad, lon_home_rad);

            // save to file
            SaveFileDialog sfd = new SaveFileDialog();

            sfd.DefaultExt = "kml";
            sfd.Filter     = "KML files (*.kml)|*.kml|All files (*.*)|*.*";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                Stream       s  = sfd.OpenFile();
                StreamWriter sw = new StreamWriter(s);
                try
                {
                    sw.Write(kml.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                sw.Close();
                if (MessageBox.Show("Do you want to open the file in Google Earth?", "Open file?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                {
                    Process.Start(sfd.FileName);
                }
            }
        }
Exemplo n.º 2
0
        private void _btn_to_kml_Click(object sender, EventArgs e)
        {
            StringBuilder placemarks = new StringBuilder();
            StringBuilder path = new StringBuilder();
            double lat_home_rad;
            double lon_home_rad;

            // we need a home position in case the navigation uses relative coordinates
            AskHome ah = new AskHome();
            if (ah.ShowDialog() != DialogResult.OK)
                return;
            lat_home_rad = ah.GetLatitudeRad();
            lon_home_rad = ah.GetLongitudeRad();

            // generate the KML
            string kml = KmlNavigation.BuildKml(GetNavigationList(), lat_home_rad, lon_home_rad);

            // save to file
            SaveFileDialog sfd = new SaveFileDialog();
            sfd.DefaultExt = "kml";
            sfd.Filter = "KML files (*.kml)|*.kml|All files (*.*)|*.*";
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                Stream s = sfd.OpenFile();
                StreamWriter sw = new StreamWriter(s);
                try
                {
                    sw.Write(kml.ToString());
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                sw.Close();
                if (MessageBox.Show("Do you want to open the file in Google Earth?", "Open file?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes)
                    Process.Start(sfd.FileName);
            }
        }