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()));
}
}
}
}
(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()));
}
}
}
}
相关文章推荐
- 简单免费工具实现手机端信息统计
- 编写自己的代码生成工具四:数据库信息查询实现
- javaEE实现数据库信息简单显示在浏览器上
- 爬虫requests库简单抓取页面信息功能实现(Python)
- 简单的学生信息处理程序实现 (Coursera 程序设计与算法 专项课程3 C++程序设计 郭炜、刘家瑛;OpenJudge)
- 简单文件读写的工具类(使用字节流工具类实现)
- 用DOS写一个简单的虚拟WIFI工具,CMD电脑无线WIFI工具,BAT实现WIFI和自动关机
- javaweb简单实现国际化信息输出(参考)
- 简单实现Http代理工具
- javascript实现简单的页面右下角提示信息框
- 分享一个.NET实现的简单高效WEB压力测试工具
- struts+hibernate+oracle+easyui实现lazyout组件的简单案例——Emp实体类和对应的配置信息
- 使用QTimeLine实现的一个简单信息提示窗体
- 【Android初学者】超简单的注册页面,填写完整信息实现 跳转 和 传参
- 用PB编写一个简单的网络信息收集小工具软件
- 46 puppet master-agent模型、运维工具介绍及pxe环境的实现、cobbler简单实现、CentOS7 cobbler
- 简单原始JS实现信息提示及隐藏
- Python实现简单时间人流数据收集工具
- 链表实现简单学生信息管理
- 文件读写工具简单实现(二)--选择文件按钮