ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapFrame Class / MapToPage Method / MapToPage(MapPoint) Method
The point in map coordinates
Example

In This Topic
    MapToPage(MapPoint) Method
    In This Topic
    Translates a point in map coordinates to a point in page coordinates. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public MapPoint MapToPage( 
       MapPoint mapPoint
    )
    Public Overloads Function MapToPage( _
       ByVal mapPoint As MapPoint _
    ) As MapPoint

    Parameters

    mapPoint
    The point in map coordinates

    Return Value

    A point in page coordinates
    Exceptions
    ExceptionDescription
    Mapframe must contain a 2D map
    mapPoint
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    The map coordinates must be in the spatial reference of the map associated with the map frame. Page coordinates can only be translated for 2D maps. If the map frame does not contain a 2D map, an System.InvalidOperationException is thrown. If either map coordinate value is double.NaN then a point with X, Y both set to System.Double.NaN is returned.
    Example
    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);
    
        });
        
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also