Ejemplo n.º 1
0
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_pActiveView == null || Button != 1)
            {
                return;
            }
            ArrayList             pSelected = new ArrayList();
            IFeatureClass         pFeatureClass;
            IPoint                pPoint;
            ISelectionEnvironment pSelectionEnvironment;
            IFeature              pFeature;
            IGeometry             pGeometry;
            ITopologicalOperator  pTopolagicalOperator;
            double                dLength;

            IEnvelope pSrchEnv;

            pSelectionEnvironment = new SelectionEnvironmentClass();
            dLength         = pSelectionEnvironment.SearchTolerance;
            pPoint          = m_pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            pPoint          = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint);
            pGeometry       = pPoint;
            dLength         = Common.DataEditCommon.ConvertPixelDistanceToMapDistance(m_pActiveView, dLength);
            pSrchEnv        = pPoint.Envelope;
            pSrchEnv.Width  = dLength;
            pSrchEnv.Height = dLength;
            pSrchEnv.CenterAt(pPoint);

            pTopolagicalOperator = (ITopologicalOperator)pGeometry;
            IGeometry pBuffer = pTopolagicalOperator.Buffer(dLength);

            pGeometry = pBuffer;
            IFeatureLayer pFeatureLayer;
            IFeature      pFeat = null;
            IMap          pMap  = m_hookHelper.FocusMap;

            //for (int i = 0; i < pMap.LayerCount; i++)
            //{
            //if (pMap.get_Layer(i).Name !=Common.DataEditCommon.g_pLayer.Name) continue;//20140216 lyf 只对当前选择图层进行

            //if (pMap.get_Layer(i).Visible == false || !(pMap.get_Layer(i) is IFeatureLayer))
            //{
            //    continue;
            //}
            if (Common.DataEditCommon.g_pLayer == null)
            {
                return;
            }
            pFeatureLayer = Common.DataEditCommon.g_pLayer as IFeatureLayer;
            pFeatureClass = pFeatureLayer.FeatureClass;
            if (pFeatureClass == null)
            {
                return;
            }
            IIdentify2 pID    = pFeatureLayer as IIdentify2;
            IArray     pArray = pID.Identify(pSrchEnv, null);

            //20140216 lyf 没有选中图元情况处理
            if (pArray == null)
            {
                MessageBox.Show(@"未选中当前图层的图元!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //continue;
                return;
            }

            IFeatureIdentifyObj pFeatIdObj;
            IRowIdentifyObject  pRowObj;

            if (pArray != null)
            {
                for (int j = 0; j < pArray.Count; j++)
                {
                    if (pArray.Element[j] is IFeatureIdentifyObj)
                    {
                        pFeatIdObj = pArray.Element[j] as IFeatureIdentifyObj;
                        pRowObj    = pFeatIdObj as IRowIdentifyObject;
                        pFeature   = pRowObj.Row as IFeature;
                        pSelected.Add(pFeature);
                        pSelected.Add(pFeatureLayer.Name);
                        pSelected.Add(0);
                    }
                }
                pArray.RemoveAll();
            }
            //}

            GetClosestFeatureInCollection(dLength, pSelected, pPoint, ref pFeat);
            if (pFeat != null)
            {
                if (m_pfrmFeatureAttribute == null)
                {
                    m_pfrmFeatureAttribute = new FeatureAttribute(pFeat);
                    m_pfrmFeatureAttribute.StartPosition = FormStartPosition.CenterParent;
                    m_pfrmFeatureAttribute.Show();
                }
                else
                {
                    m_pfrmFeatureAttribute.Close();
                    m_pfrmFeatureAttribute.Dispose();
                    m_pfrmFeatureAttribute = new FeatureAttribute(pFeat);
                    m_pfrmFeatureAttribute.StartPosition = FormStartPosition.CenterParent;
                    m_pfrmFeatureAttribute.Show();
                }
            }
        }
        public override void OnMouseDown(int Button, int Shift, int X, int Y)
        {
            if (m_pActiveView == null || Button != 1)
            {
                return;
            }
            ArrayList pSelected = new ArrayList();
            IFeatureClass pFeatureClass;
            IPoint pPoint;
            ISelectionEnvironment pSelectionEnvironment;
            IFeature pFeature;
            IGeometry pGeometry;
            ITopologicalOperator pTopolagicalOperator;
            double dLength;

            IEnvelope pSrchEnv;
            pSelectionEnvironment = new SelectionEnvironmentClass();
            dLength = pSelectionEnvironment.SearchTolerance;
            pPoint = m_pActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(X, Y);
            pPoint = GIS.GraphicEdit.SnapSetting.getSnapPoint(pPoint);
            pGeometry = pPoint;
            dLength = Common.DataEditCommon.ConvertPixelDistanceToMapDistance(m_pActiveView, dLength);
            pSrchEnv = pPoint.Envelope;
            pSrchEnv.Width = dLength;
            pSrchEnv.Height = dLength;
            pSrchEnv.CenterAt(pPoint);

            pTopolagicalOperator = (ITopologicalOperator)pGeometry;
            IGeometry pBuffer = pTopolagicalOperator.Buffer(dLength);
            pGeometry = pBuffer;
            IFeatureLayer pFeatureLayer;
            IFeature pFeat = null;
            IMap pMap = m_hookHelper.FocusMap;

            //for (int i = 0; i < pMap.LayerCount; i++)
            //{
                //if (pMap.get_Layer(i).Name !=Common.DataEditCommon.g_pLayer.Name) continue;//20140216 lyf ֻ�Ե�ǰѡ��ͼ�����

                //if (pMap.get_Layer(i).Visible == false || !(pMap.get_Layer(i) is IFeatureLayer))
                //{
                //    continue;
                //}
                if (Common.DataEditCommon.g_pLayer == null) return;
                pFeatureLayer = Common.DataEditCommon.g_pLayer as IFeatureLayer;
                pFeatureClass = pFeatureLayer.FeatureClass;
                if (pFeatureClass == null)
                {
                    return;
                }
                IIdentify2 pID = pFeatureLayer as IIdentify2;
                IArray pArray = pID.Identify(pSrchEnv, null);

                //20140216 lyf û��ѡ��ͼԪ�������
                if (pArray == null)
                {
                    MessageBox.Show(@"δѡ�е�ǰͼ���ͼԪ��", "��ʾ", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    //continue;
                    return;
                }

                IFeatureIdentifyObj pFeatIdObj;
                IRowIdentifyObject pRowObj;

                if (pArray != null)
                {
                    for (int j = 0; j < pArray.Count; j++)
                    {
                        if (pArray.Element[j] is IFeatureIdentifyObj)
                        {
                            pFeatIdObj = pArray.Element[j] as IFeatureIdentifyObj;
                            pRowObj = pFeatIdObj as IRowIdentifyObject;
                            pFeature = pRowObj.Row as IFeature;
                            pSelected.Add(pFeature);
                            pSelected.Add(pFeatureLayer.Name);
                            pSelected.Add(0);
                        }
                    }
                    pArray.RemoveAll();
                }
            //}

            GetClosestFeatureInCollection(dLength, pSelected, pPoint, ref pFeat);
            if (pFeat != null)
            {
                if (m_pfrmFeatureAttribute == null)
                {
                    m_pfrmFeatureAttribute = new FeatureAttribute(pFeat);
                    m_pfrmFeatureAttribute.StartPosition = FormStartPosition.CenterParent;
                    m_pfrmFeatureAttribute.Show();
                }
                else
                {
                    m_pfrmFeatureAttribute.Close();
                    m_pfrmFeatureAttribute.Dispose();
                    m_pfrmFeatureAttribute = new FeatureAttribute(pFeat);
                    m_pfrmFeatureAttribute.StartPosition = FormStartPosition.CenterParent;
                    m_pfrmFeatureAttribute.Show();
                }

            }
        }