描述
ArcGIS JavaScript API的1.2版本加入更多地图如何缓存,切片和地图服务的控制。本例展示了如何限制地图能够接收切片的比例等级。如果不想用户过分的放大或缩小,即使切片存在这些极端的比例,这个方法是有用处的。
本例使用ArcGIS Online上的一个影像图层。这个服务有16等级可以使用,但是应用被设置为仅仅使用相近的8个等级。因为应用系统重点是一个国家公园,用户不需要放大太多。
在本例中,细节的等级通过lods[]数组配置,lods[]数组包含每个级别的索引数信息,分辨率和比例。如何轻松地接收所有的信息呢?最好的方式是转到服务的Services Directory页面,然后添加?f=pjson到URL。下面是一个示例:
http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer?f=pjson
能够从这里拷贝需要的详情等级。一旦配置了数组,能够在构造函数里设置地图的lods。仅仅能在创建地图的时间设置详情等级。
1 <%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> 2 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/strict.dtd"> 3 <html> 4 <head> 5 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 6 <meta http-equiv="X-UA-Compatible" content="IE=7" /> 7 <title>ArcGIS Online tiled maps.</title> 8 9 <link rel="stylesheet" type="text/css" href="styles.css" 10 href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css"> 11 <link rel="stylesheet" type="text/css" href="styles.css" 12 href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/soria/soria.css"> 13 <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script> 14 15 <script type="text/javascript"> 16 dojo.require("esri.map"); 17 var map; 18 function init(){ 19 20 //在这个示例中,我剔除ESRI_Imagery_World_2D的9到16级之间的地图服务,一旦创建了映射id将被重新设置水平(1-8) 21 var lods = [ 22 {"level" : 9, "resolution" : 0.001373291015625, "scale" : 577143.747208662}, 23 {"level" : 10, "resolution" : 0.0006866455078125, "scale" : 288571.873604331}, 24 {"level" : 11, "resolution" : 0.00034332275390625, "scale" : 144285.936802165}, 25 {"level" : 12, "resolution" : 0.000171661376953125, "scale" : 72142.9684010827}, 26 {"level" : 13, "resolution" : 8.58306884765629E-05, "scale" : 36071.4842005414}, 27 {"level" : 14, "resolution" : 4.29153442382814E-05, "scale" : 18035.7421002707}, 28 {"level" : 15, "resolution" : 2.14576721191407E-05, "scale" : 9017.87105013534}, 29 {"level" : 16, "resolution" : 1.07288360595703E-05, "scale" : 4508.93552506767} 30 ]; 31 32 map=new esri.Map("map",{ 33 extent:new esri.geometry.Extent({xmin:110,ymin:31,xmax:117,ymax:37,spatialReference:{wkid:4326}}) 34 ,lods:lods 35 }); 36 37 dojo.connect(map,"onExtentChange",function(extent,delta,outLevelChange,outLod){ 38 dojo.byId("scale").innerHTML="LOD Level:<i>"+outLod.level 39 +"</i>Resolution:<i>"+outLod.resolution 40 +"</i>Scale:<i>"+outLod.scale+"</i>;" 41 42 }); 43 44 var tiledMapServiceLayer=new esri.layers.ArcGISTiledMapServiceLayer( 45 "http://server.arcgisonline.com/ArcGIS/rest/services/ESRI_Imagery_World_2D/MapServer" 46 ); 47 map.addLayer(tiledMapServiceLayer); 48 49 50 /*加载不了图片*/ 51 var heNanDynamicMapServiceLayer=new esri.layers.ArcGISDynamicMapServiceLayer( 52 "http://118.144.36.6:6080/arcgis/rest/services/chakan/henan530/MapServer" 53 ); 54 heNanDynamicMapServiceLayer.setOpacity(0.75); 55 map.addLayer(heNanDynamicMapServiceLayer); 56 57 58 } 59 60 dojo.addOnLoad(init); 61 </script> 62 </head> 63 64 <body class="tundra"> 65 <table> 66 <tr> 67 <td> 68 <div id="map" class="soria" style="position:relative;900px;height:600px;border:1px solid #000"> 69 <span id="scale" style="position:absolute;right:10px;bottom:10px;z-index:100;color:white"></span> 70 </div> 71 </td> 72 73 </tr> 74 </table> 75 </body> 76 </html> 77 78 79