ArcEngine二次开发_02(鼠标移过图层中显示特定的属性信息)

首先的话这个移过图层的方法是在axMapControl.OnMouseMove事件中发生的。

然后接下来看代码:

代码当中的注释会详细解答;

        #region 鼠标移过图层中显示信息
        //用到的接口:IFeatureLayer :Provides access to members that control common aspects of a feature layer.
        private void XMMapControl_OnMouseMove(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseMoveEvent e)
        {
             if(XMMapControl.LayCount > 0)  //用于判断控件是否加载图层文件
{
            IFeatureLayer pFeatureLayer = XMMapControl.Map.get_Layer(0) as IFeatureLayer;
            pFeatureLayer.DisplayField = "BTS_NAME";  //指定特定的属性显示字段名称 Primary Display Field;
            pFeatureLayer.ShowTips = true;
            string pTip;
            pTip = pFeatureLayer.get_TipText(e.mapX, e.mapY, XMMapControl.ActiveView.FullExtent.Width / 10000);
            if (pTip != null)  // 判断pTip内容是否为空
            {
                toolTip1.SetToolTip(XMMapControl, "名称:" + pTip);  //需先添加tooltip控件:当用户移动关联控件时显示信息
            }
            else
            {
                toolTip1.SetToolTip(XMMapControl, "");
            }
}

        }
        #endregion
然后大家可以在添加图层后,试试效果。( Pay attention:you should add the tooltip widget so that you can see the result firstly;);

然后有一个bug就是未添加图层中,他会显示error;主要原因是缺少判断语句,先判断axmapcontrol中是否有图层,以后完善。现在已经解决了!!



评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Music 爱好者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值