Newer
Older
GHFX_REFACTOR / FrmSetFlytoPos.cs
using System;
using System.Windows.Forms;
using DevComponents.DotNetBar;
using GeoScene.Data;
using GeoScene.Globe;

namespace Cyberpipe
{
    public partial class FrmSetFlytoPos : Office2007Form
    {
        GSOGlobeControl globeControl1;

        static FrmSetFlytoPos frm;
        public static void ShowForm(GSOGlobeControl globecontrol)
        {
            if (frm == null)
            {
                frm = new FrmSetFlytoPos(globecontrol);
                frm.ShowDialog(globecontrol.Parent);
            }
            else
            {
                if (frm.WindowState == FormWindowState.Minimized)
                {
                    frm.WindowState = FormWindowState.Normal;
                }
            }
        }

        public FrmSetFlytoPos(GSOGlobeControl globecontrol)
        {
            InitializeComponent();
            globeControl1 = globecontrol;
        }

        private void SetLatLonPos_Load(object sender, EventArgs e)
        {
            if (globeControl1 != null)
            {
                globeControl1.MouseClick += new MouseEventHandler(globeControl1_MouseClick);
            }
        }
        /// <summary>
        /// 确定按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {            
            double m_strLon;
            double m_strLat;
            double m_strAlt;

            if (textBoxXLon.Text == "")
            {
                MessageBox.Show("经度不能为空!");
                return;
            }
            bool bl = double.TryParse(textBoxXLon.Text,out m_strLon);
            if (!bl)
            {
                MessageBox.Show("请输入正确的经度!");
                textBoxXLon.Text = "";
                return;
            }
            if (m_strLon > 180 || m_strLon < -180)
            {
                MessageBox.Show("请输入正确的经度!");
                textBoxXLon.Text = "";
                return;
            }
            if (textBoxXLat.Text == "")
            {
                MessageBox.Show("纬度不能为空!");
                return;
            }
             bl = double.TryParse(textBoxXLat.Text, out m_strLat);
            if (!bl)
            {
                MessageBox.Show("请输入正确的纬度!");
                textBoxXLat.Text = "";
                return;
            }
            if (m_strLat > 85 || m_strLat < -85)
            {
                MessageBox.Show("请输入正确的纬度!");
                textBoxXLat.Text = "";
                return;
            }
            if (textBox3.Text == "")
            {
                textBox3.Text = "1000";
            }
            bool bl1 = double.TryParse(textBox3.Text, out m_strAlt);
            if (!bl1)
            {
                MessageBox.Show("请输入正确的高度!");
                textBox3.Text = "";
                return;
            }
            GSOPoint3d point3d = new GSOPoint3d();

            point3d.X = m_strLon;
            point3d.Y = m_strLat;
            point3d.Z = m_strAlt;

            globeControl1.Globe.FlyToPosition(point3d, EnumAltitudeMode.RelativeToGround);
        }
        /// <summary>
        /// 窗体关闭事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmSetFlytoPos_FormClosing(object sender, FormClosingEventArgs e)
        {
            frm = null;
        }
        /// <summary>
        /// 取消按钮事件处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonX2_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void globeControl1_MouseClick(object sender, MouseEventArgs e)
        {
            try
            {
                if (e.Button == MouseButtons.Left)
                {
                    GSOPoint3d p = globeControl1.Globe.ScreenToScene(e.X, e.Y);
                    textBoxXLon.Text = p.X.ToString();
                    textBoxXLat.Text = p.Y.ToString();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("运行错误:" + ex, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }



    }
}