您的位置:首页 > 其它

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

2018-02-07 01:48 288 查看
首先的话这个移过图层的方法是在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中是否有图层,以后完善。现在已经解决了!!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐