基于C#的AE二次开发之鼠标滑过显示要素字段信息(ShowMapTips)
我的开发环境为ArcGIS Engine 10.2与Visual studio2010,主地图名称为axMapControl1。如果名称变动则需要修改(注意相关事件的添加与动态链接库的导入)!
- 效果预览
- 实现代码
- 方法1:通过将 axmapcontrol 自带的 ShowMapTips 属性设置为 true 来实现
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
//ShowTips显示的要素类
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
pFeatureLayer.DisplayField = "NAME"; //ShowTips显示的字段名称
//将两个ShowTips属性设置为true
pFeatureLayer.ShowTips = true;
axMapControl1.ShowMapTips = true;
}
- 方法2:通过 .NET 自带的控件 ToolTip 来实现(需要在地图中添加一个ToolTip工具,命名为toolTip1)。
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
try
{
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
pFeatureLayer.DisplayField = "Name";//显示的字段
pFeatureLayer.ShowTips = true;
//获取查询到的字段内容
string pTip;
pTip = pFeatureLayer.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 10000);
if (pTip != null)
{
//显示查询内容
toolTip1.SetToolTip(axMapControl1, "名称:" + pTip);
}
else
{
//当 ToolTip 空间显示的内容为 null 的时候,不会显示任何内容。
toolTip1.SetToolTip(axMapControl1, "");
}
}
catch { }
}