I查询实现

在实现中,主要的是OnMouseDown事件的实现。OnMouseMove与OnMouseUp事件在identify工具中不用实现。

OnMouseDown事件实现了identify元素(用户自己添加的图标等)和要素(sde数据库中的地图要素)。

/// <summary>
        /// 鼠标按下事件
        /// </summary>
        /// <param name="button">button按钮</param>
        /// <param name="shift">shift键</param>
        /// <param name="x">屏幕X坐标</param>
        /// <param name="y">屏幕Y坐标</param>
        public void OnMouseDown(int button, int shift, int x, int y)
        {
            m_isMouseDown = true;
            //未选中图标
            pointId = -1;
            // 获取焦点地图的IActiveView对象
            IActiveView  pActiveView = m_pHookHelper.ActiveView.FocusMap as IActiveView;
            //IDisplay 对象
            IDisplay pDisplay = pActiveView.ScreenDisplay;

            //IGraphicsContainer对象,图形容器
            IGraphicsContainer pGraphicsContainer;
            pGraphicsContainer = pActiveView.GraphicsContainer;
            //Create a point
            IPoint pPoint = new PointClass();

            pPoint = pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(x, y);
         
           

            //元素
            IElement pElement;
            //元素枚举
            IEnumElement pEnumElement;
            pEnumElement = pGraphicsContainer.LocateElements(pPoint,5);
            if (pEnumElement != null)//i查询element
            {
                pElement = pEnumElement.Next();
                while (pElement != null)
                {

                    if (pElement.Geometry.GeometryType.Equals(esriGeometryType.esriGeometryPoint))
                    {
                        m_element = pElement;
                        //点
                        IPoint mPoint = new PointClass();

                      
                        mPoint = pElement.Geometry as IPoint;

                        //类的属性PointId 设置
                        pointId = mPoint.ID;
                    }
                    pElement = pEnumElement.Next();
                }
            }
            else//i查询要素
            {
                //实现要素的查询
                IdentifyFeature(pPoint);

            }         
            
        }

 

 

 /// <summary>
        /// 查找要素
        /// </summary>
        /// <param name="pPoint">点</param>
        private void IdentifyFeature(IPoint pPoint)
        {
            //清空以前查询的数据
            m_identifyObj = null;
            m_feature = null;
            //查询对象,用于查询要素
            IIdentify pIdentify;
            //查询,用于控制一个图层的要素查询控制
            IIdentifyObj pIdentifyObj;
            //要素查询对象
            IFeatureIdentifyObj pFeatureIdentifyObj;
            //要素行查询对象
            IRowIdentifyObject pRowIdentifyObj;
            //查询的要素
            IFeature pFeature;
            //数组,存放要素查询对象
            IArray pIdArray;

            //地图
            IMap pMap;
            pMap = m_pHookHelper.FocusMap;
            // 获取焦点地图的IActiveView对象
            IActiveView pActiveView = m_pHookHelper.ActiveView.FocusMap as IActiveView;
            //显示对象
            IScreenDisplay pScreenDisplay = pActiveView.ScreenDisplay;
            //显示转换对象
            IDisplayTransformation pDisplayTrnsformation;
            pDisplayTrnsformation = pScreenDisplay.DisplayTransformation;

            //范围
            IEnvelope pEnvlope = new EnvelopeClass();
            pEnvlope = pPoint.Envelope;  
         
            pEnvlope.Expand(pDisplayTrnsformation.VisibleBounds.Width / 100,
                pDisplayTrnsformation.VisibleBounds.Height / 100,
                false);
     

            //图层组
            IGroupLayer pGroupLayer = new GroupLayerClass();
            for (int i = 0; i < pMap.LayerCount; i++)
            {
                pGroupLayer.Add(pMap.get_Layer(i));            
            }

            pIdentify = pGroupLayer as IIdentify;
            pIdArray = pIdentify.Identify(pEnvlope as IGeometry);
            //get the FeatureIdentifyObject
            if ((pIdArray != null) && (pIdArray.Count > 0))
            {
                pFeatureIdentifyObj = pIdArray.get_Element(0) as IFeatureIdentifyObj;
                pIdentifyObj = pFeatureIdentifyObj as IIdentifyObj;
                pRowIdentifyObj = pFeatureIdentifyObj as IRowIdentifyObject;
                pFeature = pRowIdentifyObj.Row as IFeature;
                m_feature = pFeature;
                m_identifyObj = pIdentifyObj;
                pIdentifyObj.Flash(pScreenDisplay);
            }
        }//end of IdentifyFeature

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值