using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using ArcGIS.Core.CIM; using ArcGIS.Core.Data; using ArcGIS.Core.Geometry; using ArcGIS.Desktop.Catalog; using ArcGIS.Desktop.Core; using ArcGIS.Desktop.Editing; using ArcGIS.Desktop.Extensions; using ArcGIS.Desktop.Framework; using ArcGIS.Desktop.Framework.Contracts; using ArcGIS.Desktop.Framework.Dialogs; using ArcGIS.Desktop.Framework.Threading.Tasks; using ArcGIS.Desktop.Mapping; using System.Windows.Input; namespace ProAppModule1 { internal class MapToolSelect : MapTool { private CIMPointSymbol _pointSymbol = null; private IDisposable _graphic = null; public MapToolSelect() { IsSketchTool = true; SketchType = SketchGeometryType.Point; SketchOutputMode = SketchOutputMode.Screen; } protected async override Task OnToolActivateAsync(bool active) { if (_pointSymbol == null) _pointSymbol = await CreatePointSymbolAsync(); } protected async override Task<bool> OnSketchCompleteAsync(Geometry geometry) { if (geometry.SpatialReference == null) { // screen coordinates var screenPointAsMapPoint = geometry as MapPoint; if (screenPointAsMapPoint != null) { var pnt = new System.Windows.Point { X = screenPointAsMapPoint.X, Y = screenPointAsMapPoint.Y }; var mapScreenPoint = await QueuedTask.Run<MapPoint>( () => MapView.Active.ClientToMap(pnt)); if (mapScreenPoint.IsEmpty) { System.Diagnostics.Debug.WriteLine(@"Screen Point is empty"); } else { _graphic = await this.AddOverlayAsync(mapScreenPoint, _pointSymbol.MakeSymbolReference()); } } } else { // map coordinates _graphic = await this.AddOverlayAsync(geometry, _pointSymbol.MakeSymbolReference()); } return true; } protected override Task OnToolDeactivateAsync(bool hasMapViewChanged) { if (_graphic != null) _graphic.Dispose();//Clear out the old overlay _graphic = null; return base.OnToolDeactivateAsync(hasMapViewChanged); } internal static Task<CIMPointSymbol> CreatePointSymbolAsync() { return QueuedTask.Run(() => SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.RedRGB, 14, SimpleMarkerStyle.Circle)); } } }