Let's say I want to know the extent of every MapView in my current project. I can retrieve the extent by doing something with the MapView.Extent object.
What I can't see is how to get a list of MapViews? I can:
I might be missing something obvious, so does anyone have any clues?
Solved! Go to Solution.
Thanks, this is useful, although it doesn't really address the question. It seems the actual answer is something along these lines...
var mapViews = new List<MapView>();
foreach(var mp in ProApp.Panes.OfType<IMapPane>())
{
mapViews.Add(mp.MapView);
}
foreach(var lp in ProApp.Panes.OfType<ILayoutPane>())
{
foreach(var mp in lp.LayoutView.Layout.Elements.OfType<IMapPane>())
{
mapViews.Add(mp.MapView);
}
}
I think this sums it up. And yes regarding your last bullet:
var mapPanes = ProApp.Panes.OfType<IMapPane>();
mapPanes only contains 'panes' that are actually open. Whereas
var mapProjItems = Project.Current.GetItems<MapProjectItem>();
mapProjItems contains all map project items regardless of whether the mapview is open or not.
Thanks. How do you get the MapViews that are related to a MapProjectItem?
MapProjectItems contains maps which you can access through the GetMap() method. Each map can be displayed by multiple MapViews. To match MapProjectItems with MapViews that use the same map you would have to iterate through the collections and match the maps using the equals operator. Below is the button code-behind to find the MapProjectItem for the active MapView:
protected override async void OnClick()
{
if (MapView.Active?.Map == null) return;
var findThisMap = MapView.Active?.Map;
var result = await QueuedTask.Run<string>(() =>
{
var mpis = Project.Current.GetItems<MapProjectItem>();
foreach (var mpi in mpis)
{
if (findThisMap == mpi.GetMap())
{
return $@"Found map in this project: {mpi.Path}";
}
}
return "not found";
});
MessageBox.Show(result);
}
Thanks, this is useful, although it doesn't really address the question. It seems the actual answer is something along these lines...
var mapViews = new List<MapView>();
foreach(var mp in ProApp.Panes.OfType<IMapPane>())
{
mapViews.Add(mp.MapView);
}
foreach(var lp in ProApp.Panes.OfType<ILayoutPane>())
{
foreach(var mp in lp.LayoutView.Layout.Elements.OfType<IMapPane>())
{
mapViews.Add(mp.MapView);
}
}
Keep in mind a project can have zero or many Layouts.
A layout can have zero or many MapFrames
Each MapFrame references one (and only one) Map.
A Map can be referenced by more than one MapView, each with a different extent.
To illustrate this: Add a layout to the project and add 2 MapFrames, both pointing to the same map.
Activate one of the MapFrames and zoom to some different extent.
Run code to show how the same Map can is referenced by two different MapViews each having a different extent, via MapFrame.GetMapView().