ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapTool Class / HandleMouseDownAsync Method
A MapViewMouseButtonEventArgs that contains the event data.
Example

In This Topic
    HandleMouseDownAsync Method (MapTool)
    In This Topic
    Occurs when the OnToolMouseDown event is handled.
    Syntax
    protected virtual Task HandleMouseDownAsync( 
       MapViewMouseButtonEventArgs args
    )
    Protected Overridable Function HandleMouseDownAsync( _
       ByVal args As MapViewMouseButtonEventArgs _
    ) As Task

    Parameters

    args
    A MapViewMouseButtonEventArgs that contains the event data.

    Return Value

    A Task that represents a mouse down event.
    Remarks
    This method is intended to perform asynchronous operations associated with a mouse down event. It will be called if you override the OnToolMouseDown virtual method and set the handled property on the MapViewMouseButtonEventArgs to true.
    Example
    How to position an embeddable control inside a MapView
    public ProSnippetMapTool()
    {
      //Set the MapTool base class' OverlayControlID to the DAML id of your embeddable control in the constructor
      this.OverlayControlID = "ProAppModule1_EmbeddableControl1";
    }
    
    protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
    {
      if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
        e.Handled = true;
    }
    
    protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
    {
      return QueuedTask.Run(() =>
      {
        //assign the screen coordinate clicked point to the MapTool base class' OverlayControlLocation property.
        this.OverlayControlPositionRatio = e.ClientPoint;
    
      });
    }
    
    Translates a point in map coordinates to a point in page coordinates
    internal class GetMapCoordinates : MapTool
    {
      protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
      {
        if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
          e.Handled = true; //Handle the event args to get the call to the corresponding async method
      }
    
      protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
      {
        return QueuedTask.Run(() =>
        {
          var pointSymbol = SymbolFactory.Instance.ConstructPointSymbol(ColorFactory.Instance.BlackRGB, 8);
          var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
          
          //Convert the clicked point in client coordinates to the corresponding map coordinates.
          var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
          ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(string.Format("X: {0} Y: {1} Z: {2}",
              mapPoint.X, mapPoint.Y, mapPoint.Z), "Map Coordinates");
          //Get the corresponding layout point
          var mapFrame = layout.FindElement("New Map Frame") as MapFrame;
          var pointOnLayoutFrame = mapFrame.MapToPage(mapPoint);
    
          //Create a point graphic on the Layout.
          var cimGraphicElement = new CIMPointGraphic
          {
            Location = pointOnLayoutFrame,
            Symbol = pointSymbol.MakeSymbolReference()
          };
          //Or use GraphicFactory
          var cimGraphicElement2 = GraphicFactory.Instance.CreateSimpleGraphic(
                  pointOnLayoutFrame, pointSymbol);
    
          //At 2.x - LayoutElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement);
    
          ElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement);
          ElementFactory.Instance.CreateGraphicElement(layout, cimGraphicElement2);
    
        });
        
      }
    }
    Create a tool to the return coordinates of the point clicked in the map
    internal class GetMapCoordinates : MapTool
    {
      protected override void OnToolMouseDown(MapViewMouseButtonEventArgs e)
      {
        if (e.ChangedButton == System.Windows.Input.MouseButton.Left)
          e.Handled = true; //Handle the event args to get the call to the corresponding async method
      }
    
      protected override Task HandleMouseDownAsync(MapViewMouseButtonEventArgs e)
      {
        return QueuedTask.Run(() =>
        {
          //Convert the clicked point in client coordinates to the corresponding map coordinates.
          var mapPoint = MapView.Active.ClientToMap(e.ClientPoint);
          ArcGIS.Desktop.Framework.Dialogs.MessageBox.Show(string.Format("X: {0} Y: {1} Z: {2}",
                      mapPoint.X, mapPoint.Y, mapPoint.Z), "Map Coordinates");
        });
      }
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also