Select to view content in your preferred language

Technique for telling when the map has finished loading in the browser.

691
5
04-16-2010 01:36 PM
BradleyMontgomery
Emerging Contributor
Is there a way to determine when the browser has finished rendering the map images after a zoom-in or out? I want
to be able to let the user know when the application is still working  with a busy cursor or something similar and then remove it when the rendering is done.
The Event.Complete on the map service layers looks like it should work but it doesn't seem to. The map image hasn't finished drawing when that event returns.  The complete event says that is "dispatched when the download of the map image is complete". I added listeners for the complete event on each of my mapservice layers (dynamic and tiled) and when all of them complete, the browser is still not quite done with the rendering. Does anyone have a technique for doing this?
Tags (2)
0 Kudos
5 Replies
ReneRubalcava
Esri Frequent Contributor
If you are using Tiled Service Layers, you'll want to listen on the LayerEvent.TILES_UPDATED event.
If you have more than one layer in your application, you'll want to do a count of when each update completes.

This is code I use to track if layers are loading.

[PHP] 
protected var _serviceCount:int = 0;

protected var _currCount:int = 0;

// Cycle through your map.layers property and send each on to
// this method.
protected function mapListeners(layer:Layer):void
{
    // Note, visible matters to get a correct count.
    if (layer is ArcGISDynamicMapServiceLayer && layer.visible == true)
    {
        _serviceCount++;
        layer.addEventListener(Event.COMPLETE, onServiceIsLoading, false, 0, true);
    }
    else if (layer is ArcGISTiledMapServiceLayer && layer.visible == true)
    {
        _serviceCount++;
        layer.addEventListener(LayerEvent.TILES_UPDATED, onServiceIsLoading, false, 0, true);
    }
}

protected function onServiceIsLoading(event:Event):void
{
    _currCount++;
trace("currcount: " + _currCount);
trace("servicecount: " + _serviceCount);
    if (_currCount == _serviceCount)
    {
        isLayerLoading = false; // I bind this to a message of some sort
        _currCount = 0;
    }
}[/PHP]
0 Kudos
BradleyMontgomery
Emerging Contributor
That' basically what I did too but the problem with that is that those events fire before the images are completely rendered in the browser.  So there is still image rendering happening when the busy cursor goes away.  It is more noticeable, the more services in your map and the complexity of their features.  Do you see that in your app too?   I am looking for some event that fires when the images have completed rendering not just when they've been downloaded to the app.    Thanks
0 Kudos
DasaPaddock
Esri Regular Contributor
The tiled layer throws a complete event for each tile. Have you tried switching to the tilesUpdated event on your tiled layers? If yes, can you post your code?

Reference:
http://resources.esri.com/help/9.3/arcgisserver/apis/flex/apiref/com/esri/ags/layers/TiledMapService...
0 Kudos
BradleyMontgomery
Emerging Contributor
I tried both the Event.Complete and tilesUpdated events and they both seemed to do the same thing. My code is attached . mapSvcs is just an array of the current mapservices. This technique mostly works but there is some additional rendering or blending that seems to happen in the browser after these events complete. Using this code with a single service, even 2 services, works fine. It's as you add more services and increase the denseness of the features that it seems to take additional time. How do the individual images from each of the ArcGIS services get blended anyway? Thanks
0 Kudos
CarmenDurham
Frequent Contributor
Did you ever find a resolution to this?

It does seem like the "upon complete" occurs and removes the busy cursor before the display is completely rendered.

Thanks,
Carmen Durham
0 Kudos