ArcGIS api for javascript——加载图标

时间:2023-03-08 19:32:19
ArcGIS api for javascript——加载图标

描述

这个示例展示了如何能用一个动画图片显示地图正在加载。在这个示例中,图片是一个小的动画GIF。当地图第一次加载或用户缩放和平移地图时显示图片。当所有图层加载完成图片消失。

这个示例是通过events驱动的。地图的onLoad, onZoomStart和onPanStart事件加载图片显示。图层的onUpdate事件删除图标。

图片路径在HTML body里面引用。可以使用命名空间方法esri.showesri.hide来开关图片的可见性。该例使用一个计数器变量layersLoaded在隐藏图片前确认所有图层被加载。图片隐藏以后,计数器设回0.

本例的所有逻辑在init函数里,除了全局变量。

  <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=7" />
<title>Map Loading Image.</title> <link rel="stylesheet" type="text/css" href="styles.css"
href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
<link rel="stylesheet" type="text/css" href="styles.css"
href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/soria/soria.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
<style type="text/css">
#pic{
max-width:100px;
max-height:100px;
}
.infowindow .window .top .right .user .titlebar .title{
font-family: Arial,Helvetica,sans-serif;
font-weight: bold;
font-size: 14pt;
}
.infowindow .window .top .right .user.content{
font-style: italic;
font-size: 10pt;
} </style> <script type="text/javascript">
dojo.require("esri.map");
var map;
function init(){
//esri.config.defaults.io.proxyUrl="/proxy/proxy.ashx";
var layersLoaded=0;
var loading=dojo.byId("loadingImg"); map=new esri.Map("map");
dojo.connect(map,"onLoad",showLoading);
dojo.connect(map,"onZoomStart",showLoading);//用户开始缩放时触发事件。
dojo.connect(map,"onPanStart",showLoading);//用户开始移动时触发事件。 var tiledMapServiceLayer=new esri.layers.ArcGISTiledMapServiceLayer(
"http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"
);
map.addLayer(tiledMapServiceLayer); dojo.connect(tiledMapServiceLayer,"onUpdate",hideLoading); function showLoading(){
esri.show(loading);//显示图片
map.disableMapNavigation();//除了滑动条和移动箭头,不允许其它所有地图导航。
map.hideZoomSlider();//隐藏地图缩放滚动条。
} function hideLoading(){
layersLoaded++;
if(layersLoaded==map.layerIds.length){
esri.hide(loading);//隐藏图片
map.enableMapNavigation();//允许所有地图导航
map.showZoomSlider();//显示地图缩放滚动条
layersLoaded=0; }
}
} dojo.addOnLoad(init);
</script>
</head> <body class="tundra">
<table>
<tr>
<td>
<div id="map" class="soria" style="position:relative;width:900px;height:600px;border:1px solid #000">
<span id="scale" style="position:absolute;right:10px;bottom:10px;z-index:100;color:white"></span>
</div>
</td>
<td valign="top"> <div><img id="loadingImg" src="data:images/dtdq.gif" style="right:512px;top:256px;z-index:100;"/></div>
</td>
</tr>
</table>
<div id="info1" style="padding:5px; margin:5px;background-color: #eee;" ></div>
</body>
</html>