描述
本例展示了如何在地图里指出显示的缓存或切片的细节等级(LODs)。当打开示例地图,可以看到一些来自ArcGIS Online ESRI_Imagery_World_2D图层的影像。这个应用程序配置这个影像仅LOD 0 - 11是可见的,即使在源缓存中存在其他的等级。直接放大最终会切换到来自ArcGIS Online CSP_Imagery_World_2D图层的详细的user-contributed影像。该应用程序配置了user-contributed影像仅仅在LODs 12 -17是可见的。
本例为地图创建了一组LODs,这组LODs合并了在多个缓存服务中的LODs。在ArcGIS JavaScript API 1.2版本以前,仅仅能是使用增加的第一个服务的LODs。 注意设置在ArcGISTiledMapServiceLayer中的displayLevels[]如何转为图层的tileInfo.lods。随后,他们被联接为一个自定义的地图的一组LODs(customLods[])。
放大时可以显示自己的一组数据,而缩小时显示ArcGIS Online或一些其他数据。要执行这个图层转换的类型,匹配的缓存切片方案是必需的。在本例中的两个服务使用ArcGIS Online的缓存切片方案。
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//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>放大时切换图层</title>
<script type="text/javascript">djConfig = { isDebug:true };</script>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
<script type="text/javascript">
dojo.require("esri.map");
dojo.require("esri.layers.agstiled"); var customLods = [];
var loadCount = 0; function init() { var esriImageLayer = new esri.layers.ArcGISTiledMapServiceLayer(
"http://services.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer",
{displayLevels:[0,1,2,3,4,5,6,7,8,9,10,11]}
);
if (esriImageLayer.loaded) {
addLods(esriImageLayer);
}else {
dojo.connect(esriImageLayer,"onLoad",addLods);
} var cspImageryLayer = new esri.layers.ArcGISTiledMapServiceLayer
("http://services.arcgisonline.com/ArcGIS/rest/services/CSP_Imagery_World_2D/MapServer",
{displayLevels:[12,13,14,15,16,17]}); //Levels at which this layer will be visible
if (cspImageryLayer.loaded) {
addLods(cspImageryLayer);
} else {
dojo.connect(cspImageryLayer, "onLoad", addLods);
} } //用层次细节填充数组
function addLods(layer) {
customLods = customLods.concat(layer.tileInfo.lods);
loadCount++; if(loadCount === 2) {
initMap();
} }
//创建地图并且用自定义的层次细节
function initMap() {
var map = new esri.Map("map",{
lods:customLods,
extent:new esri.geometry.Extent(-82.05,34.87,-80.05,34.99,new esri.SpatialReference({wkid:4326})) }); dojo.connect(map,"onExtentChange",changeScale);
map.addLayer(esriImageLayer);
map.addLayer(cspImageryLayer); }
//报告哪一层将被显示
function changeScale(extent,delta,outLevelChange,outLod) {
dojo.byId("scale").innerHTML = "LOD Level: <i>" + outLod.level;
if (outLod.level < 12) {
dojo.byId("visibleLayer").innerHTML = "Layer:<i>ESRI_Imagery_World_2D</i>";
}else{
dojo.byId("visibleLayer").innerHTML = "Layer:<i>CSP_Imaery_World_2D</i>";
}
} dojo.addOnLoad(init);
</script> </head> <body >
<div id="map" class="tundra" 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: yellow;font-size: 150%;"></span>
<span id="visibleLayer" style="position: absolute;right: 10px;bottom: 10px;z-index: 100;color: yellow;font-size: 150%;"></span>
</div>
<p>Zoom in to the city below to switch to user-contributed imagery from ESRI's content sharing program</p>
</body>
</html>