Welcome to ESRI Blogs

How to track pending tiles and display a busy indicator in a Web mapping application

Rex Hansen contributed this post about how to use some of the enhanced JavaScript in Service Pack 2 to track pending tiles and display a busy indicator (such as an animated "Loading" graphic) over the Web ADF's Map control: 

As a Web ADF developer working in an asynchronous communication environment, it is often beneficial to provide an end user with some indication that a user action is being processed. Since most Web ADF applications are centered on working with a map, the ability of an end user to effectively interact with map contents is essential. The Web ADF has the ability to asynchronously retrieve map data from multiple sources and consolidate it in a single map control. In general, data sources often differ in the time it takes to respond to a request. Since the Web ADF Map control is capable of rendering map data as it is returned to the browser, it’s possible that some portion of data in the map is visible and accessible before another portion. In this case, it will likely be important to let the end user know when the map control has finished loading map data from any and all sources.

To support this capability, 9.2 service pack 2 includes an enhanced Web ADF JavaScript Map object. The JavaScript Map object has a set of “event handlers” on the pendingTiles property. The pendingTiles property references an array of map image tiles to be rendered. The array is updated when the map needs new image tiles based on the current extent. Events on the pendingTiles property are listed below:

Event Description
add_onRequestsPending Triggered when the number of items in the pendingTiles array changes from 0 to a higher value
add_onRequestsRemove Triggered when an item is removed from the pendingTiles array
add_onRequestsCompleted Triggered when the number of item in the pendingTiles array changes to 0

Use these handlers on the Map object’s pendingTiles property to register a JavaScript function with the event. For example:

map.pendingTiles.add_onRequestsPending(showBusyIndicator)

where map is the Map object and showBusyIndicator is a JavaScript function to call when the number of items in the pendingTiles array changes from 0 to a higher value.

The JavaScript function showBusyIndicator may appear as follows.

function showBusyIndicator(sender) {

            showLayer("BusyIndicator");

            if (sender!=null) {

                window.status = "Pending Tiles: " + sender.pendingTiles.length;

            }

The argument to the function is a reference to the JavaScript Map object. This argument can be used to gain access to map properties, such as the number of map image tiles left in the pendingTiles array. In this example, the number of pending tiles is output to the browser window’s status bar. If the argument is null, the pendingTiles array contains 0 items. The Web ADF includes two convenient JavaScript functions to show or hide a layer (div) based on its id, named showLayer and hideLayer, respectively. The functions are contained in the display_common.js file which is by default embedded with the Web ADF controls. In this example, the showLayer function is used to make the contents in the div tag with an id of “BusyIndicator” visible.

You can show the number of pending tiles and a "busy indicator" in a Web mapping application
 

Included below is a simple Web page with a MapResourceManager, Map, and a div tag containing an image. The JavaScript Map object events are handled after the form to let the content of the form load before interacting with it.
 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

<%@ Register Assembly="ESRI.ArcGIS.ADF.Web.UI.WebControls, Version=9.2.2.1350, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86"

    Namespace="ESRI.ArcGIS.ADF.Web.UI.WebControls" TagPrefix="esri" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >

<head runat="server">

    <title>Untitled Page</title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <esri:MapResourceManager ID="MapResourceManager1" runat="server">

            <ResourceItems>

            </ResourceItems>

        </esri:MapResourceManager>

        <esri:Map ID="Map1" runat="server" Height="453px" Width="556px" MapResourceManager="MapResourceManager1">

        </esri:Map>   

    </div>        

    

     <div id="BusyIndicator" style="z-index: 1000; left: 25px; width: 100px; position: absolute; top: 422px;height: 100px">

        <img src="images/CircleThickbox.gif" />

     </div>

   </form>

   <script language="javascript" type="text/javascript">

           

        function showBusyIndicator(sender) {

            showLayer("BusyIndicator");

            if (sender!=null) {

                window.status = "Pending Tiles: " + sender.pendingTiles.length;

            } 

        }

       

        function showPendingTiles(sender) {

            if (sender!=null) {

                window.status = "Pending Tiles: " + sender.pendingTiles.length;

            } 

        }

       

        function hideBusyIndicator(sender) {

            hideLayer("BusyIndicator");

            if (sender!=null) {

                window.status = "";

            } 

        }

       

        // add busy indicator functions to the map

        map = Maps["Map1"];

        map.pendingTiles.add_onRequestsPending(showBusyIndicator);

        map.pendingTiles.add_onRequestsRemove(showPendingTiles);

        map.pendingTiles.add_onRequestsCompleted(hideBusyIndicator);   

       

   </script>

</body>

</html>

Published Tuesday, May 01, 2007 12:05 PM by Sterling

Comments

# re: How to track pending tiles and display a busy indicator in a Web mapping application

This is good. It solves almost all of the lack of 'working' indicators in 9.2, that existed prior in 9.1 and in ArcIMS.
Tuesday, May 01, 2007 3:07 PM by David

# Showing busy indication on ESRI Web Map control

A quick note to all people using GIS from ESRI or the Map control. Rex Hansen, one of the top software

Tuesday, May 01, 2007 8:34 PM by Community Blogs

# re: How to track pending tiles and display a busy indicator in a Web mapping application

I'm doing some testing on this "busy indicator" stuff now. However, the error message always shows up complaining about a javascript error: "map.pendingTiles is null or not an object". Already installed the ArcGis Server 9.2 for .net service pack 2. Tried to set the "UseDefaultWebResources" to ture, or false(set the "WebResourceLoation" to "/aspnet_client/ESRI/WebADF/") but it doesn't help. I could find the "pendingTiles" properties inside the javascript file "display_map.js". However, it seems the old version of javascript is still loading instead of the new one which comes with the SP2. Any help will be appreciated.
Friday, May 04, 2007 8:52 AM by stephenmau

# re: How to track pending tiles and display a busy indicator in a Web mapping application

This error is usually associated with an incorrect Map id. The sample above assumes the id is "Map1" when it gets the JavaScript Map object from the Maps array: map = Maps["Map1"]; Let me know if the problem persists.
Friday, May 04, 2007 11:23 AM by Rex Hansen

# re: How to track pending tiles and display a busy indicator in a Web mapping application

From stephenmau on May 8, 2007: Rex, My bad! I put the javascript code inside the form tag by mistake. Appreciate your help.:)

Tuesday, May 08, 2007 1:27 PM by sterlingdq

# re: How to track pending tiles and display a busy indicator in a Web mapping application

Simple yet works so efficiently. Thanks so much for this.

Thursday, May 10, 2007 2:19 PM by lvo2006

# re: How to track pending tiles and display a busy indicator in a Web mapping application

where is image CircleThickbox?
Monday, May 28, 2007 1:52 AM by Michael

# re: How to track pending tiles and display a busy indicator in a Web mapping application

I install sp3 and I can not see the busy indicator?
Wednesday, September 12, 2007 7:01 PM by aaron

# re: How to track pending tiles and display a busy indicator in a Web mapping application

This should still work in sp3. Are any errors returned? Do you see information in the status bar to indicate the showBusyIndicator or showPendingTiles functions are being called? Is the script tag that contains these functions outside the form tag in the page? In the custom JavaScript added for this scenario, is the map id correct when referencing the Maps array?
Thursday, September 13, 2007 11:47 AM by Rex Hansen

# Busy indicator when custom tool bar action underway?

Rex, your code works wonderfully! I'd like to learn how to extend it in this way: I have a custom tool bar tool that when clicked on the map it performs a spatial query (before the map refreshes), then refreshes the map with a circle on it. How do I get a "busy indicator" to display when the spatial query is launched and before the map.Refresh() event is fired? Thanks!
Friday, September 14, 2007 12:53 PM by Eric

# re: How to track pending tiles and display a busy indicator in a Web mapping application

Eric, You'll need to trigger the busy indicator when the initial callback is sent to the server. If this happens when using a tool in a Web ADF Toolbar control, the callback is sent when the tool interacts with the Map. Depending on the tools ClientAction, this may occur during an onclick, onmouseup, etc. event on the div object that contains the map. So one easy way to implement this is to listen for the appropriate event in the browser, check the mode on the map to determine which tool is active, then choose to show the busy indicator. In the server implementation of the tool you'll need to create a custom CallbackResult using JavaScript to locate and hide the busy indicator. Add the CallbackResult to the callback response (via the Map). Two code snippets are provided below. The name of the custom tool is "CustomTool". 1) Custom client code to listen for an event on the map div (same location as the custom JavaScript for the pending tiles example).
. . .
var map = Maps['Map1'];

map.divObject.onmouseup = function() {
if (map.mode == 'CustomTool')
{    
   document.getElementById('BusyIndicator').style.visibility = 'visible';                         
}
}    
. . .
2) Custom CallbackResult to use in the tool implementation on the server.
Map adfMap = (Map)args.Control;
. . . 

string jsHideLoading = "document.getElementById('BusyIndicator').style.visibility = 'hidden'";
CallbackResult hideLoadingCallbackResult = new CallbackResult(null, null, "javascript", jsHideLoading);
adfMap.CallbackResults.Add(hideLoadingCallbackResult);
Hope this helps, -Rex
Monday, September 17, 2007 2:53 PM by Rex Hansen

# re: How to track pending tiles and display a busy indicator in a Web mapping application

Thanks Rex, that worked perfectly!
Wednesday, September 19, 2007 12:32 PM by Eric

# re: How to track pending tiles and display a busy indicator in a Web mapping application

Thanks Rex, I have a little problem with the function showLayer("ProcessingNow") and hideLayer("ProcessingNow"). They are not working, and after I replaced them by my own code, I can see the gif image now. I'm using IE7. Actually I have another question for you. I want to add coordinate grids for my map and label the degree numbers on the left and bottom border. Could you please tell me how I can get the handler after the map extent is changed? I'm thinking to use the functions you posted here, do you know any easier way? Thanks! Tommy
Thursday, September 27, 2007 7:41 AM by Tommy

# re: How to track pending tiles and display a busy indicator in a Web mapping application

For those who want to apply this method into a custom command, you could 1). set the ClientAction as: showBusyIndicator(); postBack('Toolbar1',); 2). On the server side, add the code below to hide the busy indicator: CallbackResult hideLoading = new CallbackResult(null, null, "JavaScript", "window.setTimeout('hideBusyIndicator();', 500)"); mapCtrl.CallbackResults.Add(hideLoading);
Monday, October 01, 2007 6:14 PM by Jian Huang

# re: How to track pending tiles and display a busy indicator in a Web mapping application

Can this be done while using master pages and contentplaceholders? If so, how?
Wednesday, November 07, 2007 2:06 PM by Jeff

# re: How to track pending tiles and display a busy indicator in a Web mapping application

I got a bug with the code.If I identified map  some times and then click "Clear All" link in TaskResults Control,the BusyIndicator don't disappear.

Is there anyone face the same problem and How to resove this bug??

thanks?

Wednesday, November 14, 2007 1:00 AM by secondflying

# re: How to track pending tiles and display a busy indicator in a Web mapping application

Rex,

It is a useful code, but sometimes image does not even show up but I can see the status bar message is there, so I know it is working, in your original code I try to set a timeout on java script in showPendingTiles(sender) method: at the end of if statement i put this: setTimeout('hideLayer("BusyIndicator");', 10000);

and it is not working, still doing the same thing. I have 9.2 sp3. Any help would be greatly appreciated.

Wednesday, December 26, 2007 2:44 PM by abakhtiyarov

# re: How to track pending tiles and display a busy indicator in a Web mapping application

In other words, I want the client to detect the last “expected?” message from the server, so I can display an animated “Loading…” message until the last “data packet?” is received and processed.  My application appears to be receiving/expecting data even after the pending tiles collection has no more items, so my best guess, which is limited by my level of web development experience, is that I need to monitor some other collection variable and await its depletion.  How are web browsers able to show their waiting icon/message?  In my opinion, the web browser’s default wait notification is unfortunately not apparent to the end user, but that is what I want to monitor, so that is what I am trying to enhance.

Any help will be greatly appreciated.

Monday, December 31, 2007 12:13 PM by abakhtiyarov
New Comments to this post are disabled