ArcGIS Server地图加载过程显示等待状态

本文介绍如何使用WebADF JavaScript Map对象的事件来跟踪待加载的地图瓦片,并显示加载指示器。通过监听特定事件,可以实现动态展示加载状态,提高用户体验。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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:

EventDescription
add_onRequestsPendingTriggered when the number of items in the pendingTiles array changes from 0 to a higher value
add_onRequestsRemoveTriggered when an item is removed from the pendingTiles array
add_onRequestsCompletedTriggered 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>

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
Published Tuesday, May 01, 2007 12:05 PM by Sterling
 
### 如何检测Cesium地图完成加载 为了确保在Cesium的地图完全加载之后执行特定操作,可以利用`readyPromise`这一特性。当涉及到等待整个场景初始化完毕的情况时,`viewer.scene.readyPromise`能够派上用场[^4]。 对于更具体的图层加载情况,则应关注于各个图像提供商(`ImageryProvider`)实例上的`readyPromise`属性。一旦这些承诺被解决,就意味着对应的资源已经准备好用于显示了。 下面是一个简单的例子来展示怎样监听地图及其基础影像图层的准备状态: ```javascript // 初始化Viewer对象 var viewer = new Cesium.Viewer('cesiumContainer'); // 地图整体以及默认底图加载完成后的回调 viewer.scene.readyPromise.then(function(scene) { console.log("Map and base layer are fully loaded."); }).otherwise(function(error) { console.error("Error during map loading:", error); }); // 如果有额外添加的imagery layers, 可以单独监控它们的状态 var customLayer = viewer.imageryLayers.addImageryProvider( new Cesium.UrlTemplateImageryProvider({ url : 'https://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer/tile/{z}/{y}/{x}' }) ); customLayer.provider.readyPromise.then(function() { console.log("Custom imagery layer is now ready."); }); ``` 通过上述方式可以在不同层次上捕获到地图组件加载成功的时刻,并据此安排后续逻辑,比如更新UI、启动动画或是像提问者提到的一样,在此时点放置地理标记以避免视觉上的不稳定现象[^1]。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值