描述

ArcGISTiledMapServiceLayer,这意味着图层有一个在明确的比例的预先渲染的地图切片的cache。能够从tileInfo属性获得图层的的缓存比例数组。这是本例中标注如何被得到。在下面的代码中,记得"lods"是"levels of detail"。

var lods = layer.tileInfo.lods;
for (var i=0, il=lods.length; i<il; i++) {
  labels[i] = lods[i].scale;
}

构建这个比例等级的数组后,通过esriConfig中的sliderLabel.labels将比例等级数组应用为标注很容易的。

esriConfig.defaults.map.sliderLabel = {
  ...
  labels: labels,
  ...
};

 <!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>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.5/js/dojo/dijit/themes/tundra/tundra.css">
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.5"></script>
<script type="text/javascript"> dojo.require("esri.map");
function init() {
var layer = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer"); if(layer.loaded) { initMap(layer);
}else { dojo.connect(layer,"onLoad",initMap);
}
} function initMap(layer) { //增加自定义注标器
//用层的缩放来展示滑动器类别
var labels = [];
var lods = layer.tileInfo.lods; alert(lods.length);
for(var i=0,j=lods.length;i<j;i++) {
labels[i] = lods[i].scale; }
esriConfig.defaults.map.sliderLabel = {
tick:0,
labels:labels,
style:"width:2em;font-family:Verdana;font-size:65%;color:#fff;padding-left:2px;" }; var map = new esri.Map("map");
map.addLayer(layer); }
dojo.addOnLoad(init); </script>
</head>
<body class="tundra">
<div id="map" style="width:1024px; height:512px; border:1px solid #000;"></div>
</body>
</html>
05-27 16:38