您的位置:首页 > 其它

MapXtreme中桌面信息工具(InfoTool)的简单实现

2007-08-18 12:25 267 查看
实现InfoTool的一个方法:使用Select工具,在ToolUsed事件处理函数中调用GetInfo方法(自己写的获取当前选择集的属性信息的方法)。
(1).在窗体构造函数中将ToolUsed事件处理函数添加到对应的委托中:
public Form1()
{
InitializeComponent();
// add Tools_Used to ToolUsedEventHandler to handle the Select tool's use event
mapControl1.Tools.Used += new MapInfo.Tools.ToolUsedEventHandler(Tools_Used);
}
(2).设置当前鼠标左键工具为Select工具:
private void btnSelectTool_Click(object sender, EventArgs e)
{
mapControl1.Tools.LeftButtonTool = "Select";
}
(3).在ToolUsed处理函数中判断如果是Select工具,则调用GetInfo方法:
private void Tools_Used(object sender, MapInfo.Tools.ToolUsedEventArgs e)
{
switch (e.ToolName)
{
case "Select":
{
// if the select tool used,call GetInfo method to show the feature's information
this.GetInfo(this);
// Note: the break keyword is needed
break;
}
}
}
(4).GetInfo方法的具体实现,用来获取Select工具当前选择的图元的属性信息:
private void GetInfo(object sender)
{
listBox1.Items.Clear();
MapInfo.Engine.ISession session=MapInfo.Engine.Session.Current;
// specify which layer dose the feature belongs to
FeatureLayer lyr = mapControl1.Map.Layers[comboBox1.Text] as FeatureLayer;
// hold the default selection(the features you clicked) in the
// IResultSetFeatureCollection
IResultSetFeatureCollection rsfc =session.Selections.DefaultSelection[lyr.Table];

if (rsfc != null) // an exception will be thrown if you remove this if-clause
{
// go through the default selection-the features
foreach (Feature f in rsfc)
{
// the columns of each feature
foreach (MapInfo.Data.Column col in f.Columns)
{
// show each field of every feature
listBox1.Items.Add(string.Format("{0}:{1}", col.ToString(), f[col.ToString()].ToString()));
}
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: