Exemple #1
0
        private static List <ArcmapPickCandidate> FindPickCandidates(
            IPoint mapPoint, List <IFeatureLayer> pickLayers, double mapScale, double searchTolerance)
        {
            List <ArcmapPickCandidate> result = new List <ArcmapPickCandidate>();

            if (pickLayers.Count > 0)
            {
                IEnvelope searchEnvelope = mapPoint.Envelope;
                searchEnvelope.Expand(searchTolerance, searchTolerance, false);

                foreach (IFeatureLayer pickLayer in pickLayers)
                {
                    if (ArcmapLayerUtils.LayerIsVisible(pickLayer, mapScale))
                    {
                        IIdentify identifier = pickLayer as IIdentify;
                        IArray    elements   = identifier.Identify(searchEnvelope);
                        foreach (object element in elements.Enumerate())
                        {
                            IFeature feature = (element as IRowIdentifyObject).Row as IFeature;
                            double   distance;
                            IPoint   footPoint;
                            CalculateNearestDistanceToFeature(mapPoint, feature, out distance, out footPoint);

                            ArcmapPickCandidate ranking = new ArcmapPickCandidate(element as IIdentifyObj, distance);
                            result.Add(ranking);
                        }
                    }
                }
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Can be called from the mouse up event of the ArcMap tool.
        /// </summary>
        /// <param name="x">Clicked x coordinate.</param>
        /// <param name="y">Clicked y coordinate.</param>
        /// <returns>The picked feature candidate or null if no feature was picked.</returns>
        public ArcmapPickCandidate OnMouseUp(int x, int y)
        {
            ArcmapPickCandidate result        = null;
            IScreenDisplay      screenDisplay = ArcmapUtils.FocusMapToScreenDisplay(FocusMap);
            IPoint mapPoint        = TransformMousePositionToMapPoint(x, y, screenDisplay);
            double searchTolerance = ArcmapUtils.PixelsToDistance(_snapTolerance, screenDisplay);
            double mapScale        = GetCurrentMapScale(screenDisplay);

            List <ArcmapPickCandidate> pickCandidates = FindPickCandidates(mapPoint, _pickLayers, mapScale, searchTolerance);

            SortPickCandidates(pickCandidates);

            if (pickCandidates.Count == 1)
            {
                result = pickCandidates[0];
            }
            else if (pickCandidates.Count > 1)
            {
                System.Drawing.Point position = new System.Drawing.Point(x + popupShiftH, y + popupShiftV);
                ContextMenuStrip     menu     = BuildContextMenu(pickCandidates);
                menu.Opacity       = 0.9;
                _selectedCandidate = null;
                ContextMenuUtils.ShowContextMenu(menu, position, (IntPtr)ArcmapUtils.FocusMapToScreenDisplay(FocusMap).hWnd);
                if (_selectedCandidate != null)
                {
                    result = _selectedCandidate;
                }
            }
            return(result);
        }
Exemple #3
0
        private void contextMenuItem_Select(object sender, EventArgs e)
        {
            object menuTag = ((ToolStripItem)sender).Tag;
            ArcmapPickCandidate candidate = (ArcmapPickCandidate)menuTag;

            ArcmapUtils.FlashFeature(candidate.Feature, ArcmapUtils.FocusMapToScreenDisplay(FocusMap));
        }
        /// <summary>
        /// Compares the candidate with another candidate, to determine the favorited candidate.
        /// </summary>
        /// <param name="other">Other candidate to compare with.</param>
        /// <returns>Returns a value, indicating which one is the better candidate.</returns>
        public int CompareTo(ArcmapPickCandidate other)
        {
            int result = GeometryType.CompareTo(other.GeometryType);

            if (result == 0)
            {
                result = DistanceToClickPoint.CompareTo(other.DistanceToClickPoint);
            }
            return(result);
        }
Exemple #5
0
        private void contextMenuItem_Click(object sender, EventArgs e)
        {
            object menuTag = ((ToolStripItem)sender).Tag;

            _selectedCandidate = (ArcmapPickCandidate)menuTag;
        }