ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Desktop.Layouts Namespace / MapSurround Class
Members Example

In This Topic
    MapSurround Class
    In This Topic
    Represents a map surround on a page layout.
    Object Model
    MapSurround ClassCoordinate2D StructureEnvelope ClassCIMElement ClassGeometry ClassIElementContainer InterfaceMapFrame Class
    Syntax
    Remarks

    A MapSurround is a type of Element and therefore can be positioned or resized on the page. A MapSurround also has an associated MapFrame that can be modified.

    Legend, NorthArrow, and ScaleBar are types of a MapSurround.

    Example
    MapSurroundExample
    //Added references
    using ArcGIS.Desktop.Core;                         //Project
    using ArcGIS.Desktop.Layouts;                      //Layout class
    using ArcGIS.Desktop.Framework.Threading.Tasks;    //QueuedTask
    
    public class MapSurroundExample
    {
      public static Task<bool> UpdateMapSurroundAsync(string LayoutName, string SBName, string MFName)
      {
        //Reference a layoutitem in a project by name
        LayoutProjectItem layoutItem = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(item => item.Name.Equals(LayoutName));
        if (layoutItem == null)
          return Task.FromResult(false);
    
        return QueuedTask.Run<bool>(() =>
        {
                //Reference and load the layout associated with the layout item
                Layout lyt = layoutItem.GetLayout();
    
                //Reference a scale bar element by name
                MapSurround scaleBar = lyt.FindElement(SBName) as MapSurround;
          if (scaleBar == null)
            return false;
    
                //Reference a map frame element by name
                MapFrame mf = lyt.FindElement(MFName) as MapFrame;
          if (mf == null)
            return false;
    
                //Set the scale bar to the newly referenced map frame
                scaleBar.SetMapFrame(mf);
          return true;
        });
      }
    }
    Update a map surround
    //Update a map surround.
    
    //Perform on the worker thread
    QueuedTask.Run(() =>
    {
      // Reference and load the layout associated with the layout item
      Layout layout = layoutItem.GetLayout();
      if (layout != null)
      {
        // Reference a scale bar element by name
        MapSurround scaleBar = layout.FindElement("MyScaleBar") as MapSurround;
    
        // Reference a map frame element by name
        MapFrame mf = layout.FindElement("MyMapFrame") as MapFrame;
    
        if ((scaleBar != null) && (mf != null))
          //Set the scale bar to the newly referenced map frame
          scaleBar.SetMapFrame(mf);
      }
    });
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Layouts.Element
             ArcGIS.Desktop.Layouts.MapSurround
                ArcGIS.Desktop.Layouts.ChartFrame
                ArcGIS.Desktop.Layouts.ElevationGuideBar
                ArcGIS.Desktop.Layouts.Legend
                ArcGIS.Desktop.Layouts.NorthArrow
                ArcGIS.Desktop.Layouts.ScaleBar
                ArcGIS.Desktop.Layouts.TableFrame

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also