Retrieve Scale from All Maps

426
2
10-28-2021 06:18 PM
TheBobScript
New Contributor III

I am able to get a list of all maps in a project (Project.Current.GetItems<MapProjectItem>()) and display a number of properties, like name, layers, spatial reference, etc.  One thing I cannot seem to access is the current scale for each of these maps (MapProjectItem).

I would like to retrieve the scale for all of my maps in my project.  I know you can retrieve the scale for an active map (MapView.Active.Camera.Scale), but how do I get the scale for a map that is not active?  Can I retrieve the scale from each map without making it the active map in my project? 

0 Kudos
2 Replies
KirkKuykendall1
Occasional Contributor III

I don't see scale but to get the extent, this works:

protected override async void OnClick()
{
    //Saving the project is needed to assure the 
    // map definitions are in sync with the view extents
    await Project.Current.SaveAsync();
    await QueuedTask.Run(() =>
    {
        foreach (var mapdef in Project.Current.Items
        .OfType<MapProjectItem>()
        .Select(itm => itm.GetMap().GetDefinition()))
        {
            Trace.WriteLine(mapdef.DefaultExtent.ToJson());
        }

    });
}

 

 

TheBobScript
New Contributor III

Hi Kirk - Thanks for taking the time to reply.  I'll take a look at what you have shared and see if that helps with what I'm after.

0 Kudos