ArcEngine实现鼠标滑过显示要素的属性(c#)

网上有个方法主要是借助 axmapcontrol 自带的 ShowMapTips 来实现,鄙人感觉有点复杂,其代码大致如下

private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
 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, "");
    }
}

我的思路如下,通过获取鼠标位置来创建缓冲区,然后用MapContral.Map.SelectByShap(缓冲区,null,true)去查询,最终使用windows自带的tooltip控件来显示,主要代码如下

  pPoint = new PointClass();
                            pPoint.PutCoords(e.mapX, e.mapY);
                            pTopo = pPoint as ITopologicalOperator;17                             double m_Radius = 1;
                             pGeometry = pTopo.Buffer(m_Radius); 
                             if (pGeometry == null)
                                 continue;
                            axMapControl1.Map.SelectByShape(pGeometry, null, true);//第三个参数为是否只选中一个
                             axMapControl1.Refresh(esriViewDrawPhase.esriViewGeoSelection, null, null); //选中要素高亮显示
                             pFilter = new SpatialFilterClass();
                             pFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;
                             pFilter.Geometry = pGeometry;
                             pFeatureLayer = axMapControl1.Map.get_Layer(i) as IFeatureLayer; 
                             pCursor = pFeatureLayer.Search(pFilter, false);
                             pFeature = pCursor.NextFeature();
                             string fieldName;
                             if (pFeature != null)
                             {
                                IField fields=pFeatureLayer.FeatureClass.Fields;
                                int pIndexNumber=fields.FindField("类别");
                                string leibie=pFeature.get_Value(pIndexNumber);
                                toolTip.SetToolTip(MapControl,"类别",leibie);



猜你喜欢

转载自blog.csdn.net/Yuanben_wuxin/article/details/80732896