年度变更建库软件5.0版本
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
5.6 KiB

4 months ago
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Geometry;
using KGIS.Framework.Utils;
using KGIS.Framework.Utils.Helper;
using System;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Input;
namespace Kingo.Plugin.MapView.Views.GoToXYUi
{
/// <summary>
/// GoToXYUi.xaml 的交互逻辑
/// </summary>
public partial class GoToXYUi : BaseWindow
{
private static GoToXYUi instance;
public static GoToXYUi Instance(object Helpers)
{
if (instance == null)
instance = new GoToXYUi(Helpers);
else
{
instance.m_hookHelper = Helpers as IHookHelper;
}
return instance;
}
private IHookHelper m_hookHelper;//获取地图控件和主窗体
public GoToXYUi(object Helpers)
{
try
{
if (this.m_hookHelper == null)
{
this.m_hookHelper = Helpers as IHookHelper;
}
}
catch (Exception ex)
{
//LogAPI.Debug("转到XY异常!" + ex.Message);
LogAPI.Debug("初始化 转到XY页面 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("初始化 转到XY页面 时异常信息结束");
}
InitializeComponent();
}
/// <summary>
/// 转到XY轴点击事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Btn_GotoXy_Click(object sender, RoutedEventArgs e)
{
GotoXy();
}
/// <summary>
/// 定位XY方法封装
/// </summary>
public void GotoXy()
{
try
{
//非空验证
if ((Txt_X.Text).Trim() == "" || (Txt_Y.Text).Trim() == "")
{
MessageHelper.Show("X或Y轴为空,请重新输入!");
return;
}
Double latitude = Double.Parse(Txt_X.Text);//获取输入的X轴坐标
Double longitude = Double.Parse(Txt_Y.Text);//获取输入的Y轴坐标
IPoint point = new PointClass();
IGeometry geometry;//声明一个几何
point.X = latitude;
point.Y = longitude;
geometry = (IGeometry)point;//向几何中添加一个点
IArray geoArray = new ArrayClass();//声明一个几何的集合
geoArray.Add(geometry);//向几何集合中添加几何对象
IHookActions hookActions = (IHookActions)m_hookHelper;//通过IHookActions闪烁要素集合
hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsPan);
System.Windows.Forms.Application.DoEvents();
m_hookHelper.ActiveView.ScreenDisplay.UpdateWindow();
((m_hookHelper.Hook) as IMapControl2).CenterAt(point);
hookActions.DoActionOnMultiple(geoArray, esriHookActions.esriHookActionsFlash);
}
catch (Exception ex)
{
//LogAPI.Debug(ex.Message);
LogAPI.Debug("执行 定位XY方法 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("执行 定位XY方法 时异常信息结束");
}
}
/// <summary>
/// 设置XY的值
/// </summary>
/// <param name="x">x轴的值</param>
/// <param name="y">y轴的值</param>
public void SetXYValue(int x, int y)
{
Txt_X.Text = x.ToString();
Txt_Y.Text = y.ToString();
}
/// <summary>
/// 窗口关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
//public Action Closeds;
private void BaseWindow_Closed(object sender, EventArgs e)
{
//this.Closeds();
instance = null;
this.Close();
}
/// <summary>
/// 验证Y轴输入是否合法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Txt_Y_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
try
{
Regex re = new Regex("[^0-9.-]+");
e.Handled = re.IsMatch(e.Text);
}
catch (Exception ex)
{
//LogAPI.Debug(ex.Message);
LogAPI.Debug("验证Y轴输入是否合法 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("验证Y轴输入是否合法 时异常信息结束");
}
}
/// <summary>
/// 验证X轴输入是否合法
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Txt_X_PreviewTextInput(object sender, TextCompositionEventArgs e)
{
try
{
Regex re = new Regex(@"[^0-9.-]+");
e.Handled = re.IsMatch(e.Text);
}
catch (Exception ex)
{
//LogAPI.Debug(ex.Message);
LogAPI.Debug("验证X轴输入是否合法 时异常,异常信息如下:");
LogAPI.Debug(ex);
LogAPI.Debug("验证X轴输入是否合法 时异常信息结束");
}
}
}
}