ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapFactory Class / CreateMapFromItem Method
An ArcGIS.Desktop.Core.Item
Example

In This Topic
    CreateMapFromItem Method (MapFactory)
    In This Topic
    Creates a new Map in the project using an item e.g. webmap, mxd etc. This method must be called on the MCT. Use QueuedTask.Run.
    Syntax
    public Map CreateMapFromItem( 
       Item item
    )
    Public Function CreateMapFromItem( _
       ByVal item As Item _
    ) As Map

    Parameters

    item
    An ArcGIS.Desktop.Core.Item

    Return Value

    Exceptions
    ExceptionDescription
    This method or property must be called within the lambda passed to QueuedTask.Run.
    Remarks
    You should always check using MapFactory.CanCreateMapFrom() method before passing an item to this method.
    To open a map, use ProApp.Panes.CreateMapPaneAsync method.
    Example
    BrowseDialogItems
    // cref: OpenItemDialog;ArcGIS.Desktop.Catalog.ItemDialog.Filter
    // cref: OpenItemDialog;ArcGIS.Desktop.Catalog.ItemDialog.InitialLocation
    // cref: OpenItemDialog;ArcGIS.Desktop.Catalog.ItemDialog.Title
    // cref: OpenItemDialog;ArcGIS.Desktop.Catalog.OpenItemDialog
    #region OpenItemDialog
    
    /// Adds a single item to a map
    OpenItemDialog addToMapDialog = new OpenItemDialog()
    {
      Title = "Add To Map",
      InitialLocation = @"C:\Data\NewYork\Counties\Erie\Streets",
      Filter = ItemFilters.Composite_AddToMap
    };
    
    Open a webmap
    Map map = null;
    
    //Assume we get the selected webmap from the Project pane's Portal tab
    if (Project.Current.SelectedItems.Count > 0)
    {
      if (MapFactory.Instance.CanCreateMapFrom(Project.Current.SelectedItems[0]))
      {
        map = MapFactory.Instance.CreateMapFromItem(Project.Current.SelectedItems[0]);
        await ProApp.Panes.CreateMapPaneAsync(map);
      }
    }
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also