Пример #1
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);
        }