Get maps collection in project

310
2
12-10-2019 01:01 PM
MartinTyberg
New Contributor II

Hi,

In ArcObjects, it's possible to retrieve the collections of IMaps in an MXD and retrieve the layers for each one. In ArcGIS Pro SDK, I only see a MapView.Active property for retrieving just the active MapView and its corresponding Map (and layers). Is there a way to retrieve all the MapViews or all the Maps in a project?

Thanks,

Martin

Tags (1)
0 Kudos
2 Replies
UmaHarano
Esri Regular Contributor

Hi

Here are some snippets that could help you to get this information in Pro:

1.Get the Unique List of Maps From the Map Panes

2.Gets all the "MapProjectItems"

Specifically, here are the code snippets -

Get the map panes (map views):

var mapPanes = ProApp.Panes.OfType<IMapPane>()
              .GroupBy((mp) => mp.MapView.Map.URI).Select(grp => grp.FirstOrDefault());‍‍

Get all the map project items (maps in 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();
  }
});

Thanks

Uma

0 Kudos
MartinTyberg
New Contributor II

Hi Uma,

Great thanks. I hadn't seen those snippets. It's clear now.

Martin

0 Kudos