ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Desktop.Mapping Namespace / MapProjectItem Class
Members Example

In This Topic
    MapProjectItem Class
    In This Topic
    Represents a map project item.
    Object Model
    MapProjectItem ClassMapProjectItem ClassMap ClassTimeInstant Class
    Syntax
    Example
    Get MapProjectItems
    /// Get all the maps in a project
    IEnumerable<MapProjectItem> projectMaps = Project.Current.GetItems<MapProjectItem>();
    
    Remove Map From Project
    /// Remove a map from a project; the map is deleted
    IProjectItem mapToRemove = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(map => map.Name.Equals("OldStreetRoutes"));
    var removedMapProjectItem = await QueuedTask.Run(
             () => Project.Current.RemoveItem(mapToRemove));
    
    Get all "MapProjectItems" for a project
    IEnumerable<MapProjectItem> newMapItemsContainer = project.GetItems<MapProjectItem>();
    
    await QueuedTask.Run(() =>
    {
      foreach (var mp in newMapItemsContainer)
      {
        //Do Something with the map. For Example:
        Map myMap = mp.GetMap();
      }
    });
    Get a specific "MapProjectItem"
    MapProjectItem mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("EuropeMap"));
    ProjectItem: Get an Item or Find an Item
    //GetItems searches project content
    var map = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(m => m.Name == "Map1");
    var layout = Project.Current.GetItems<LayoutProjectItem>().FirstOrDefault(m => m.Name == "Layout1");
    var folders = Project.Current.GetItems<FolderConnectionProjectItem>();
    var style = Project.Current.GetItems<StyleProjectItem>().FirstOrDefault(s => s.Name == "ArcGIS 3D");
    
    //Find item uses a catalog path. The path can be to a file or dataset
    var fcPath = @"C:\Pro\CommunitySampleData\Interacting with Maps\Interacting with Maps.gdb\Crimes";
    var pdfPath = @"C:\Temp\Layout1.pdf";
    var imgPath = @"C:\Temp\AddinDesktop16.png";
    
    var fc = Project.Current.FindItem(fcPath);
    var pdf = Project.Current.FindItem(pdfPath);
    var img = Project.Current.FindItem(imgPath);
    
    How to access Geoprocessing History
    string openProjectPath = @"D\DATA\IGPHistoryItemTestProject\IGPHistoryItemTestProject.aprx";
    await Project.OpenAsync(openProjectPath);
    MapProjectItem mapProjItem = Project.Current.GetItems<MapProjectItem>().FirstOrDefault(item => item.Name.Equals("Map", StringComparison.CurrentCultureIgnoreCase));
    
    var map = await QueuedTask.Run(() => mapProjItem.GetMap());
    var ftrLayer = map.Layers[0] as FeatureLayer;
    string tool1 = "management.GetCount";
    var args1 = Geoprocessing.MakeValueArray(ftrLayer);
    var env = Geoprocessing.MakeEnvironmentArray(overwriteoutput: true);
    GPExecuteToolFlags executeFlags = GPExecuteToolFlags.AddToHistory;
    var t = await Geoprocessing.ExecuteToolAsync(tool1, args1, env, null, null, executeFlags);
    
    IEnumerable<IGPHistoryItem> hisItems = Project.Current.GetProjectItemContainer(Geoprocessing.HistoryContainerKey) as IEnumerable<IGPHistoryItem>;
    
    String hitemID = "";
    String hitemToolPath = "";
    IGPResult hitemGPResult = null;
    DateTime hitemTimeStamp;
    
    foreach (var hitem in hisItems)
    {
      // common IGPHistoryItem and Item properties
      hitemID = (hitem as Item).ID;
      hitemToolPath = hitem.ToolPath;
      hitemGPResult = hitem.GPResult;
      hitemTimeStamp = hitem.TimeStamp;
    }
    
    
    Create Map Frame and Set Camera
    //Create a map frame and set its camera by zooming to the extent of an existing bookmark.
    
    //Construct on the worker thread
    await QueuedTask.Run(() =>
    {
      //Build 2D envelope geometry
      Coordinate2D mf_ll = new Coordinate2D(6.0, 8.5);
      Coordinate2D mf_ur = new Coordinate2D(8.0, 10.5);
      //At 2.x - Envelope mf_env = EnvelopeBuilder.CreateEnvelope(mf_ll, mf_ur);
      Envelope mf_env = EnvelopeBuilderEx.CreateEnvelope(mf_ll, mf_ur);
    
      //Reference map, create MF and add to layout
      MapProjectItem mapPrjItem = Project.Current.GetItems<MapProjectItem>()
                           .FirstOrDefault(item => item.Name.Equals("Map"));
      Map mfMap = mapPrjItem.GetMap();
      Bookmark bookmark = mfMap.GetBookmarks().FirstOrDefault(
                            b => b.Name == "Great Lakes");
    
      //At 2.x - MapFrame mfElm =
      //                  LayoutElementFactory.Instance.CreateMapFrame(
      //                                             layout, mf_env, mfMap);
      //         mfElm.SetName("New Map Frame");
      //
      MapFrame mfElm = ElementFactory.Instance.CreateMapFrameElement(
                           layout, mf_env, mfMap, "New Map Frame");
    
      //Zoom to bookmark
      mfElm.SetCamera(bookmark);
    });
    Find a map within a project and open it
    public static async Task<Map> FindOpenExistingMapAsync(string mapName)
    {
      return await QueuedTask.Run(async () =>
      {
        Map map = null;
        Project proj = Project.Current;
    
        //Finding the first project item with name matches with mapName
        MapProjectItem mpi = proj.GetItems<MapProjectItem>()
          .FirstOrDefault(m => m.Name.Equals(mapName, StringComparison.CurrentCultureIgnoreCase));
        if (mpi != null)
        {
          map = mpi.GetMap();
          //Opening the map in a mapview
          await ProApp.Panes.CreateMapPaneAsync(map);
        }
        return map;
      });
    
    }
    Inheritance Hierarchy

    System.Object
       ArcGIS.Desktop.Framework.Contracts.PropertyChangedBase
          ArcGIS.Desktop.Core.Item
                      ArcGIS.Desktop.Mapping.MapProjectItem

    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also