/// <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); }
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> /// Enumerates all workspaces in ArcMap. /// </summary> /// <param name="esriApplication">The Esri application istance.</param> /// <returns>Enumeration of workspaces.</returns> public static IEnumerable <IWorkspace> EnumerateAllWorkspaces(IApplication esriApplication) { HashSet <IWorkspace> duplicateFinder = new HashSet <IWorkspace>(); foreach (IDataset dataset in ArcmapUtils.EnumerateAllDatasets(esriApplication)) { IWorkspace workspace = dataset.Workspace; if ((workspace != null) && !duplicateFinder.Contains(workspace)) { duplicateFinder.Add(workspace); yield return(workspace); } } }
/// <summary> /// Initializes a new instance of the <see cref="ArcmapPickCandidate"/> class. /// </summary> /// <param name="identifyOby">Identified object.</param> /// <param name="distance">Distance from the identified object to the mouse click.</param> public ArcmapPickCandidate(IIdentifyObj identifyOby, double distance) { IdentifyObj = identifyOby; DistanceToClickPoint = distance; GeometryType = ArcmapUtils.DetectGeometryBaseType(Feature.Shape); }