C#+ArcEngine10.0+SP5实现鼠标移动动态显示要素属性信息
为了解决鼠标移过动态显示要素属性的问题,我在网上先是查到的只能显示单个要素的属性,就是直接在arcmap中设置好的那个tips就可以显示,但是这种显示效果只是简单的实现了显示要素的属性值,可是没有对该要素的描述。
为了在程序中实现这种效果,代码可写为:
private void axMap_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e) { stFirst.Text = " 比例尺 1 : " + ((long)axMap.MapScale).ToString(); stSecond.Text = " 当前坐标 X = " + e.mapX.ToString() + " Y = " + e.mapY.ToString() + " " + axMap.MapUnits.ToString().Substring(4) + " "; //显示属性 ShowLayerTips(e.mapX, e.mapY); } private void ShowLayerTips(double x, double y)//显示地图tips方法 { for (int i = 0; i < axMap.LayerCount; i++) { string fieldstring = ""; ILayer layer = axMap.Map.get_Layer(i); axMap.ShowMapTips = true; IFeatureLayer fLayer = layer as IFeatureLayer; fLayer.ShowTips = true; ILayerFields layerFields = (ILayerFields)fLayer; for (int k = 0; k <= layerFields.FieldCount - 1; k++) { IField field = layerFields.get_Field(k); if (field.Name.ToLower() != "shape"&& !field.IsNullable) { fieldstring += "\""+field.AliasName+":\"&"+"[" + field.Name + "]" + " & vbnewline & "; } } IDisplayString displayString = fLayer as IDisplayString; IDisplayExpressionProperties properties = displayString.ExpressionProperties; properties.Expression = fieldstring.Substring(0, fieldstring.Length - 14); } }
最终实现效果如下: