ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MappingExtensions Class / AddOverlay Method / AddOverlay(MapView,CIMGraphic,Double) Method
The view to add the overlay.
The graphic to be added to the overlay.
Map reference scale or -1
Example

In This Topic
    AddOverlay(MapView,CIMGraphic,Double) Method
    In This Topic
    Add an overlay graphic to the map view.
    Syntax
    Public Overloads Shared Function AddOverlay( _
       ByVal mapView As MapView, _
       ByVal graphic As CIMGraphic, _
       Optional ByVal referenceScale As Double _
    ) As IDisposable

    Parameters

    mapView
    The view to add the overlay.
    graphic
    The graphic to be added to the overlay.
    referenceScale
    Map reference scale or -1

    Return Value

    An object that when disposed will remove the overlay.
    Remarks
    When the referenceScale is not equal to -1, the overlay will be created in real world units relative to the provided map reference scale (referenceScale). Otherwise, the overlay will be created in units of points. This is only supported in 2D.
    Example
    Graphic Overlay
    //Defined elsewhere
    private IDisposable _graphic = null;
    public async void GraphicOverlaySnippetTest()
    {
      // get the current mapview and point
      var mapView = MapView.Active;
      if (mapView == null)
        return;
      var myextent = mapView.Extent;
      var point = myextent.Center;
    
      // add point graphic to the overlay at the center of the mapView
      _graphic = await QueuedTask.Run(() =>
      {
        //add these to the overlay
        return mapView.AddOverlay(point,
            SymbolFactory.Instance.ConstructPointSymbol(
                    ColorFactory.Instance.RedRGB, 30.0, SimpleMarkerStyle.Star).MakeSymbolReference());
      });
    
      // update the overlay with new point graphic symbol
      MessageBox.Show("Now to update the overlay...");
      await QueuedTask.Run(() =>
      {
        mapView.UpdateOverlay(_graphic, point, SymbolFactory.Instance.ConstructPointSymbol(
                                      ColorFactory.Instance.BlueRGB, 20.0, SimpleMarkerStyle.Circle).MakeSymbolReference());
      });
    
      // clear the overlay display by disposing of the graphic
      MessageBox.Show("Now to clear the overlay...");
      _graphic.Dispose();
    
    }
    Graphic Overlay with CIMPictureGraphic
    // get the current mapview
    var mapView = MapView.Active;
    if (mapView == null)
      return;
    
    //Valid formats for PictureURL are:
    // e.g. local file URL:
    // file:///<path>
    // file:///c:/images/symbol.png
    //
    // e.g. network file URL:
    // file://<host>/<path>
    // file://server/share/symbol.png
    //
    // e.g. data URL:
    // data:<mediatype>;base64,<data>
    // data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEASABIAAD/2wBDAAU ...
    //
    // image/bmp
    // image/gif
    // image/jpeg
    // image/png
    // image/tiff
    // image/x-esri-bglf
    
    var pictureGraphic = new CIMPictureGraphic
    {
      PictureURL = @"file:///C:/Images/MyImage.png",
      Shape = envelope
    };
    
    IDisposable _graphic = mapView.AddOverlay(pictureGraphic);
    Add overlay graphic with text
    internal class AddOverlayWithText : MapTool
    {
      private IDisposable _graphic = null;
      private CIMLineSymbol _lineSymbol = null;
      public AddOverlayWithText()
      {
        IsSketchTool = true;
        SketchType = SketchGeometryType.Line;
        SketchOutputMode = SketchOutputMode.Map;
      }
    
      protected override async Task<bool> OnSketchCompleteAsync(Geometry geometry)
      {
        //Add an overlay graphic to the map view
        _graphic = await this.AddOverlayAsync(geometry, _lineSymbol.MakeSymbolReference());
    
        //define the text symbol
        var textSymbol = new CIMTextSymbol();
        //define the text graphic
        var textGraphic = new CIMTextGraphic();
    
        await QueuedTask.Run(() =>
        {
          //Create a simple text symbol
          textSymbol = SymbolFactory.Instance.ConstructTextSymbol(ColorFactory.Instance.BlackRGB, 8.5, "Corbel", "Regular");
          //Sets the geometry of the text graphic
          textGraphic.Shape = geometry;
          //Sets the text string to use in the text graphic
          textGraphic.Text = "This is my line";
          //Sets symbol to use to draw the text graphic
          textGraphic.Symbol = textSymbol.MakeSymbolReference();
          //Draw the overlay text graphic
          _graphic = this.ActiveMapView.AddOverlay(textGraphic);
        });
    
        return true;
      }
    }
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also