Select to view content in your preferred language

Reusing Map control causes map to freeze

9218
16
10-27-2014 09:06 AM
SimonFisher
Frequent Contributor

In our Windows Store App (not a map centric app) we use the same map (and map control) on several different pages within the application.  This was done for several reasons, including performance, keeping the map state etc. and originally dealing with a memory leak in the map control when loading/unloading/recreating.  We do this by creating one generic map control and keeping it in the application wide state and reusing when necessary. We create the control and initialize it once and then add/remove the control to the xaml tree when navigating to/from a page that requires a map something like this;

ContentGrid.Children.Add(App.ArcGISMapCtrl); //ContentGrid is a xaml grid

and for removing;

ContentGrid.Children.Remove(App.ArcGISMapCtrl);

This has been working great for us during all the Beta releases but in this Final release we now get the following behavior;

The first time a page is loaded and we create the map everything works fine and as expected.  Any subsequent navigation to the same page or any other page with a map the page loads fine but the map control is frozen.  Everything else works on the page except the map, is just hung or something.  I can see it, but it is not allowing any interaction.

I can get the map working on all page loads if I re-create the Map control on every page navigation but this kind of defeats the point since everything has to be re-initialized, as well the maps state is lost and would have to be saved/reloaded each time.  The reusing of the map control has been working great for us as users only see some lag in the first map load, but after that maps are always ready right away and in the same state they left.

Was something major changed in the Final release that might affect this?  Any suggestions on what I could try differently?

Thanks,

Simon

Tags (4)
0 Kudos
16 Replies
SimonFisher
Frequent Contributor

No, I haven't tried yet.  Still deciding if its worth going back to my original implementation of reusing the map control which was back during the Beta. It may be better performance and hold onto state for me, but not sure if its worth it since we haven't really had major performance issues. 

0 Kudos
MattMiley
Deactivated User

Morten Nielsen:

You can (and should) cache the map though.

Morten Nielsen, How do you do this? Is it possible while using mvvm too?

Something like this?? http://stackoverflow.com/questions/13917303/how-to-pass-a-complex-object-between-pages-in-a-windows-...

0 Kudos
dotMorten_esri
Esri Notable Contributor

Your view model should contain a Map property, that you bind to the MapView when navigating to the map page.

<esri:MapView Map="{Binding MyViewModelInstance.Map}" />
0 Kudos
AnttiKajanus1
Deactivated User

There are different mechanisms to share complex objects across the ViewModels.

One way to handle this is to use a proxy class that manages the Map instance and that is shared between the ViewModels. The "manager/service/controller" approach is fairly common especially if you are using dependency injection (DI). Also static controller classes should work just fine to share references in MVVM fashion if you aren't using IoC.

You can also extend navigation pattern to deliver any object to the next page. Something like this.

0 Kudos
HebaSaleh2
Deactivated User

what about navigation from page to page causes application to freeze issue?

the application contains 2 page one for map(offline) and the other contains normal controls when navigation from normal controls to map many times the application freeze.

0 Kudos
AnttiKajanus1
Deactivated User

is that issue same as here?

0 Kudos
HebaSaleh2
Deactivated User

Yes it is the same issue.

0 Kudos