ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / GraphicsLayerExtensions Class / AddElement Method / AddElement(GraphicsLayer,MapPoint,String,CIMTextSymbol,String,Boolean,ElementInfo) Method
The text placement point
The text string (required)
The text symbol. Can be null (optional)
An element name (optional)
True to set the element selected after the add (default is true) (optional)
Additional element properties or null (optional)
Example

In This Topic
    AddElement(GraphicsLayer,MapPoint,String,CIMTextSymbol,String,Boolean,ElementInfo) Method
    In This Topic
    Add a ArcGIS.Desktop.Layouts.GraphicElement based on the input point, text, and textsymbol (optional). This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    Public Overloads Shared Function AddElement( _
       ByVal graphicsLayer As GraphicsLayer, _
       ByVal point As MapPoint, _
       ByVal text As String, _
       Optional ByVal textSymbol As CIMTextSymbol, _
       Optional ByVal elementName As String, _
       Optional ByVal select As Boolean, _
       Optional ByVal elementInfo As ElementInfo _
    ) As GraphicElement

    Parameters

    graphicsLayer
    point
    The text placement point
    text
    The text string (required)
    textSymbol
    The text symbol. Can be null (optional)
    elementName
    An element name (optional)
    select
    True to set the element selected after the add (default is true) (optional)
    elementInfo
    Additional element properties or null (optional)

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    point cannot be null or empty
    Map has reached maximum graphics count limit of 4000 elements. One or more elements cannot be created.
    Map has reached maximum graphics size limit of 10 MB. One or more elements cannot be created.
    Remarks
    The point cannot be null or empty. If text is null an empty string is assigned. If textSymbol is null a default text symbol is assigned.
    The map view displaying the graphics layer should be initialized.
    Custom properties, if provided, must be serializable to string.
    Example
    Text Graphic Element
    var graphicsLayer = MapView.Active.Map.GetLayersAsFlattenedList()
                        .OfType<ArcGIS.Desktop.Mapping.GraphicsLayer>().FirstOrDefault();
    if (graphicsLayer == null)
      return;
    QueuedTask.Run(() =>
    {
      //Place symbol in the center of the map
      var extent = MapView.Active.Extent;
      var location = extent.Center;
    
      //specify a text symbol
      var text_symbol = SymbolFactory.Instance.ConstructTextSymbol
      (ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
    
      graphicsLayer.AddElement(location, text_symbol, "Text Example");
    });
    Translates a point in page coordinates to a point in map coordinates.
    //On the QueuedTask
    var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault().GetLayout();
    var mapFrame = layout.FindElement("New Map Frame") as MapFrame;
    
    //Get a point in the center of the Map frame
    var mapFrameCenterPoint = mapFrame.GetBounds().CenterCoordinate;
    //Convert to MapPoint
    //At 2.x - var pointInMapFrame = MapPointBuilder.CreateMapPoint(mapFrameCenterPoint);
    var pointInMapFrame = MapPointBuilderEx.CreateMapPoint(mapFrameCenterPoint);
    
    //Find the corresponding point in the MapView
    var pointOnMap = mapFrame.PageToMap(pointInMapFrame);
    
    //Create a point graphic on the MapView.
    var cimGraphicElement = new CIMPointGraphic
    {
      Location = pointOnMap,
      Symbol = pointSymbol.MakeSymbolReference()
    };
    graphicsLayer.AddElement(cimGraphicElement);
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also