Beispiel #1
0
        //判断鼠标是否在已选择要素的节点上
        public static bool MouseOnFeatureVertex(IPoint pPnt, IFeature pFeature, IActiveView pActiveView)
        {
            //设置点选择容差
            ISelectionEnvironment pSelectEnv = new SelectionEnvironmentClass();
            double Length = ConvertPixelsToMapUnits(pActiveView, pSelectEnv.SearchTolerance);

            IPointCollection pointCol = pFeature.Shape as IPointCollection;

            for (int i = 0; i < pointCol.PointCount; i++)
            {
                IGeometry4 pGeom = pointCol.get_Point(i) as IGeometry4;
                //给pGeom一个确定的空间参考
                pGeom.Project(pActiveView.FocusMap.SpatialReference);
                if (pGeom.IsEmpty)
                {
                    return(false);
                }

                IProximityOperator pObj    = pGeom as IProximityOperator;
                double             dblDist = pObj.ReturnDistance(pPnt);
                if (dblDist < Length)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #2
0
        private static bool MouseOnSelection(IFeatureLayer pFeatureLay, IPoint pPnt, IActiveView pActiveView, double Length)
        {
            IFeatureSelection pFeatureSelection = pFeatureLay as IFeatureSelection;

            if (pFeatureSelection == null)
            {
                return(false);
            }
            ISelectionSet pSelectionSet = pFeatureSelection.SelectionSet;

            if (pSelectionSet.Count == 0)
            {
                return(false);
            }
            ICursor pCursor = null;

            pSelectionSet.Search(null, false, out pCursor);
            IFeatureCursor pFeatureCursor = pCursor as IFeatureCursor;

            if (pFeatureCursor == null)
            {
                return(false);
            }
            IFeature pFeature = pFeatureCursor.NextFeature();

            while (pFeature != null)
            {
                IGeometry4 pGeom = pFeature.ShapeCopy as IGeometry4;
                //给pGeom一个确定的空间参考
                pGeom.Project(pActiveView.FocusMap.SpatialReference);
                if (pGeom.IsEmpty)
                {
                    continue;
                }

                IProximityOperator pObj    = pGeom as IProximityOperator;
                double             dblDist = pObj.ReturnDistance(pPnt);
                if (dblDist < Length)
                {
                    return(true);
                }

                pFeature = pFeatureCursor.NextFeature();
            }

            return(false);
        }