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

本文介绍了一种使用Select工具结合自定义GetInfo方法来获取MapInfo中选定图元属性信息的技术方案。通过监听ToolUsed事件并在Select工具被使用时触发,能够有效地展示所选特征的数据详情。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

实现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()));
          }
        }
      }
    } 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值