Select to view content in your preferred language

Map Progress event not firing

1289
4
08-30-2011 07:28 AM
AndrewMurdoch
Regular Contributor
I'm trying to get access to the Map Progress event so that I can turn off a custom splash screen after the map tiles have been downloaded.  This is similar to this previous forum posting:

http://forums.arcgis.com/threads/17132-Event-for-when-map-service-image-is-returned?highlight=map.pr...

However, I can't seem to get the Progress event to fire when I need it.  My code looks like this:

In MainPage.xaml.cs constructor (where Map is the name of the map object):
Map.Progress += new EventHandler<ESRI.ArcGIS.Client.ProgressEventArgs>(Map_Progress);


In the procedure Map_Progress:
        void Map_Progress(object sender, ESRI.ArcGIS.Client.ProgressEventArgs e)
        {
            if (e.Progress == 100)
            {
                HtmlPage.Window.Invoke("hideSplashscreen", null);
            } 
        }


I can put the Invoke command in a handler for the Map.Loaded event, and that works, but it removes the splash screen before the map has finished loading the tiles.  Strangely, after the Map.Loaded event fires the Invoke command, the Map.Progress event will then fire.  Of course by then it is too late.

I'm really confused about this and would appreciate any help!
Thanks
0 Kudos
4 Replies
JenniferNery
Esri Regular Contributor
Have you tried with this sample? http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#MapProgressBar

You can update this sample by adding:
XAML:
<esri:Map x:Name="MyMap" WrapAround="True" Progress="MyMap_Progress">
<!-- more code here -->
<TextBlock x:Name="ProgressTb" VerticalAlignment="Top" HorizontalAlignment="Center"/>

Code-behind:
private void MyMap_Progress(object sender, ESRI.ArcGIS.Client.ProgressEventArgs e)
{
 ProgressTb.Text = string.Format("Progress : {0}", e.Progress);
}


Notice that when you navigate the map (zoom/pan), the progress bar changes as it requests for new tiles. See how your app is different from this.
0 Kudos
dotMorten_esri
Esri Notable Contributor
Have you tried hooking up the event handler in the page.loaded or map.loaded event instead of in the constructor? map.Layers.LayersInitialized might also be a good time to do this. I believe the map progress is 100% when the map initially loads (before starting to initialize the layers where no data is "missing" yet)
0 Kudos
AndrewMurdoch
Regular Contributor
Thanks for your replies.

I have tried hooking up the Map.Progress event handler in Page.Load, Map.Load and also in Map.Layers.LayersInitialized events, but without success.  By stepping through the code, I can see that the Page.Load event is reached and the Map.Load event is reached, but Map.Layers.LayersInitialized and Map.Progress events never fire (at least while the ASP.NET splashscreen is still visible). 

If I first turn off the ASP.NET splashscreen div using the javascript Invoke method in the Page.Load or Map.Load event handlers, then the Map.Layers.LayersInitialized and Map.Progress events start to fire.

I'm leaning toward putting up a separate Silverlight modal splashscreen to replace the ASP.NET splashscreen div when it is closed on Page.Load.  Then the Silverlight splashscreen would block out the page until the Map.Progress event reaches 100.  Not as elegant as I hoped, though, and I still don't understand what I'm doing wrong... 

BTW, I'm using Silverlight ESRI API 2.2.
0 Kudos
GregoryDillon
Occasional Contributor
Try setting the DisableClientCaching = true on your dynamic layers.   I figured out the progress event does not alway fire until you set this.    I think the layer becomes cached and then the event doesn't fire because there is nothing to report progress on (its already done as with the layers they are cache - you would think it would fire it anyway).   I especially notice this behavior when the map extent remains the same and the layers turned on remain the same. 

In my situation I rebuild a seperate map to generate a PDF (I do a seperate map to rescale it the page size without messing up the screen map).   Each time I do this I clear all the layer in the PDF map and rebuilt them from the screen map.   The first time I generated the map everything worked fine.   The second time I generated with the same extent/layers as before the progress does not fire dispite the fact I totally cleared the map.  I believe this is because its the webservive that is cached not so much the map object/Dynamic layers themselves.  Since I using the same webservice even with new Dynamic Layers (although with the same combo as the previous print) the map thinks its done already.   I fixed the problem by setting the DisableClientCaching = true (overriding the map caching).   At least I think that what was happening.    I still wish the progress event would fire with DisableClientCaching = false, as you really don't know that map is truely ready (to convert to bitmaps in my case) until the the progress event fires.    Maybe this is the wrong event to determine (its not the Load event I know that for sure) that the layers are all in a ready state.   This is the only event I could find.   I don't think there is one yet (ESRI please give me one in 2.3 or point me to one).
0 Kudos