using System; using System.Windows.Forms; using DevComponents.DotNetBar; using GeoScene.Data; using GeoScene.Globe; namespace Cyberpipe { public partial class FrmSetLatLonPos : Office2007Form { private GSOGlobeControl globeControl1; static FrmSetLatLonPos frm; public static void ShowForm(GSOGlobeControl ctl) { if (frm == null) { frm = new FrmSetLatLonPos(ctl); frm.Show(ctl.Parent); } else { if (frm.WindowState == FormWindowState.Minimized) { frm.WindowState = FormWindowState.Normal; } } } public FrmSetLatLonPos(GSOGlobeControl ctl) { InitializeComponent(); globeControl1 = ctl; } /// <summary> /// 复选框选中事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void checkBoxX1_CheckedChanged(object sender, EventArgs e) { groupPanel1.Visible = checkBoxX1.Checked; groupPanel2.Visible = !checkBoxX1.Checked; } /// <summary> /// 复选框选中事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void checkBoxX2_CheckedChanged(object sender, EventArgs e) { groupPanel1.Visible = !checkBoxX2.Checked; groupPanel2.Visible = checkBoxX2.Checked; } /// <summary> /// 确定按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX1_Click(object sender, EventArgs e) { if (checkBoxX1.Checked) { double m_strLon; double m_strLat; double m_strAlt; if (textbox1.Text == "") { MessageBox.Show("经度不能为空!"); return; } bool bl = double.TryParse(textbox1.Text, out m_strLon); if (!bl) { MessageBox.Show("请输入正确的经度!"); textbox1.Text = ""; return; } if (m_strLon > 180 || m_strLon < -180) { MessageBox.Show("请输入正确的经度!"); textbox1.Text = ""; return; } if (textBox2.Text == "") { MessageBox.Show("纬度不能为空!"); return; } bl = double.TryParse(textBox2.Text, out m_strLat); if (!bl) { MessageBox.Show("请输入正确的纬度!"); textBox2.Text = ""; return; } if (m_strLat > 85 || m_strLat < -85) { MessageBox.Show("请输入正确的纬度!"); textBox2.Text = ""; return; } if (textBox3.Text == "") { textBox3.Text = "1000"; } bool bl1 = double.TryParse(textBox3.Text, out m_strAlt); if (!bl1) { MessageBox.Show("请输入正确的高度!"); textBox3.Text = ""; return; } GSOCameraState cameraState = new GSOCameraState(); cameraState.Longitude = m_strLon; cameraState.Latitude = m_strLat; cameraState.Distance = m_strAlt; cameraState.Tilt = 0; cameraState.Heading = 0; globeControl1.Globe.FlyToCameraState(cameraState); } else if (checkBoxX2.Checked) { int id = GSOProjectManager.AddProject(Utility.projectStr); double m_strLon; double m_strLat; double m_strAlt; if (textBox5.Text == "") { MessageBox.Show("X值不能为空!"); return; } bool bl = double.TryParse(textBox5.Text, out m_strLon); if (!bl) { MessageBox.Show("请输入正确的X值!"); textBox5.Text = ""; return; } if (textBox6.Text == "") { MessageBox.Show("Y值不能为空!"); return; } bl = double.TryParse(textBox6.Text, out m_strLat); if (!bl) { MessageBox.Show("请输入正确的Y值!"); textBox6.Text = ""; return; } if (textBox4.Text == "") { textBox4.Text = "1000"; } bool bl1 = double.TryParse(textBox4.Text, out m_strAlt); if (!bl1) { MessageBox.Show("请输入正确的Z值!"); textBox4.Text = ""; return; } GSOPoint2d pt2d = new GSOPoint2d(m_strLon, m_strLat); GSOPoint2d result = GSOProjectManager.Inverse(pt2d, id); if (result.X > 180 || result.X < -180) { MessageBox.Show("请输入正确的X值!"); textBox5.Text = ""; return; } if (result.Y > 85 || result.Y < -85) { MessageBox.Show("请输入正确的Y值!"); textBox6.Text = ""; return; } GSOCameraState cameraState = new GSOCameraState(); cameraState.Longitude = result.X; cameraState.Latitude = result.Y; cameraState.Distance = m_strAlt; cameraState.Tilt = 0; cameraState.Heading = 0; globeControl1.Globe.FlyToCameraState(cameraState); } } /// <summary> /// 取消按钮事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void buttonX2_Click(object sender, EventArgs e) { Close(); } /// <summary> /// 窗体关闭事件处理 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmSetLatLonPos_FormClosing(object sender, FormClosingEventArgs e) { frm = null; } } }