CreateMapPaneAsync creates a new pane everytime

138
9
06-05-2020 11:55 PM
Highlighted
New Contributor II

I have a similar codeblock in my application as shown here in the Pro SDK Wiki snippets. I run this code when I need to access the map pane by name. It creates a new map pane everytime this code is run, is there a way to check and retrieve or select existing pane and if not able then to create it. 

Tags (1)
Reply
0 Kudos
9 Replies
Highlighted
New Contributor

Also, the created map is not set as active view by default. I even tried to activate the view explicitly as shown.

IMapPane activePane = await ProApp.Panes.CreateMapPaneAsync(aoMaps.ElementAt(i).GetMap());
var currentPane = activePane as Pane;
if (currentPane != null)
currentPane.Activate();

Reply
0 Kudos
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

I think the following sample implements what you want to do:  https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Framework/OpenMapViews

Reply
0 Kudos
Highlighted
New Contributor II

Wolfgang Kaiser‌ Thanks for sharing the sample. I have tried that and it didn't help. I have created a add-in to demonstrate the issue and attached herewith along with a sample project.

The sample add-in saves maps to a folder on computer as mapx files looping through all maps. The first map opens and saves perfectly fine. But when it tries to open second map and save it, the execution stops at this line of code
var activePane = await ProApp.Panes.CreateMapPaneAsync(item.GetMap());

At this point actually a map pane with the map is created by not initialized & activated.


The execution moves further only one when I select the second tab and the debugger point  shown below hits. If I do not select the pane manually, it never completes execution.


Could you take a look and let me know how to make the pane initialized and activated automatically?

Reply
0 Kudos
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

I duplicated your issue with my sample add-in, I can create one or two (at most) map panes before the [map pane creation] thread will hang.  I am checking with the developers for any workarounds.  

Reply
0 Kudos
Highlighted
New Contributor II

Thanks Wolfgang Kaiser‌, I will look forward for your response

Reply
0 Kudos
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

Besides the issue regarding the map pane initialization and activation, i think the you can implement your workflow, saving all maps in a common folder', because it is possible without first showing a map view pane.  You can save the maps as follows:

protected override async void OnClick()
{
var pathToSaveFiles = @"c:\temp\maps";
if (!System.IO.Directory.Exists(pathToSaveFiles))
{
System.IO.Directory.CreateDirectory(pathToSaveFiles);
}
var mapProjItems = Project.Current.GetItems<MapProjectItem>();
try
{
await QueuedTask.Run(() =>
{
foreach (var mapPro in mapProjItems)
{
mapPro.GetMap().SaveAsFile(System.IO.Path.Combine(pathToSaveFiles, $@"{mapPro.Name}.mapx"));
}
});
}
catch (Exception ex)
{
MessageBox.Show($@"Error: {ex}");
}
MessageBox.Show("Done");
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I attached the sample project I used to duplicate your issued and also this code.  If you want to run the sample, you need to download and use the 'C:\Data\Admin\AdminSample.aprx' project which comes with the community sample dataset here:  https://github.com/Esri/arcgis-pro-sdk-community-samples/releases  then click the 'CreateMaps' button followed by the 'SaveMaps' button which saves the map files to c:\temp\maps.

Reply
0 Kudos
Highlighted
New Contributor II

Thanks for the sample and suggestion Wolfgang Kaiser. The sample I shared is built to just demonstrate the problem. In real, there is some some custom processing to do activating the map panes automatically one after the other.

Reply
0 Kudos
Highlighted
by Esri Regular Contributor
Esri Regular Contributor

Hi Sai,

 I am not able to duplicate any problems with activation of a mapview pane unless it is done in a tight loop with no user interaction with the mapview pane (other than just displaying and activating it).  To activate a mapview pane you can lift the code from this sample: https://github.com/Esri/arcgis-pro-sdk-community-samples/tree/master/Framework/OpenMapViews  and you can then do your custom processing on the active map view.  Once you're done with your 'custom processing' and done saving your map, you can then repeat the same cycle for the next item.  I have not seem any issues with this workflow, maybe if you can elaborate what type of processing you are doing i can try to duplicate the issue.  There are plenty of issues that could be the cause of a hang but the pane activation for this type of workflow is not the reason.

Reply
0 Kudos
Highlighted
New Contributor II

Sure, I will try with the code in the sample and see if the issue is bypassed. Also, please post back when you hear from developers. Thanks!

Reply
0 Kudos