首页 > 代码库 > ArcGIS api for javascript——显示地图属性

ArcGIS api for javascript——显示地图属性

描述

本例展示了如哦读取地图和图层的属性和返回信息给用户。本例中的四个按钮允许用户接收地图属性。每个按钮调用不同的函数。

  • ·Get All Map Layers - 这个按钮调用getMapLayers函数,循环地图里的每个图层并在报警框中报告 layer ID,visibility和 opacity信息
  • ·Get SR - 这个按钮调用getSR函数,在报警框中报告地图的空间参考的WKID。
  • ·Get Scales for portlandParcels - 这个按钮调用函数getScales,在地图服务图层的portlandParcels切片中报告关于每个比例级别。该函数使用 ArcGISTiledMapServiceLayer.tileInfo属性,这个属性能显示 map cache里有多少个比例级别,级别是什么比例的,每个比例的分辨率是什么。
  • ·Get Map Width Height - 这个按钮调用函数getMapWidthHeight,在报警框里报告地图的width和 height,单位是像素。
 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     
 8     <title>ArcGIS JavaScript API Map Layer</title>
 9     
10     <link rel="stylesheet" type="text/css" href="styles.css"
11            href="http://serverapi.arcgisonline.com/jsapi/arcgis/1.6/js/dojo/dijit/themes/tundra/tundra.css">
12     <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script>
13     <script type="text/javascript">
14         dojo.require("esri.map");
15         
16         var map,portlandParcels,transportation,census;
17         
18          function init(){
19             map=new esri.Map("map");
20             //波特兰(美国奥勒冈州最大的城市)地块
21             portlandParcels=new esri.layers.ArcGISDynamicMapServiceLayer(
22                 //"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Portland/Portland_ESRI_LandBase_AGO/MapServer"
23                 "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Population_World/MapServer"
24             );
25              map.addLayer(portlandParcels);    
26             //交通系统
27              /* transportation = new esri.layers.ArcGISTiledMapServiceLayer(
28                  "http://server.arcgisonline.com/ArcGIS/rest/services/Reference/ESRI_Transportation_World_2D/MapServer",
29                  {"id":"agoreference", "opacity":0.5}
30              );
31              myMap.addLayer(transportation); */
32             //人口普查
33              /* census = new esri.layers.ArcGISDynamicMapServiceLayer(
34                  "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer", 
35                  {"id":"census","opacity":0.5}
36              );
37              myMap.addLayer(census);
38             */
39         
40         } 
41          //所有图层信息
42          function getMapLayers(){
43             for(var i=0,i1=map.layerIds.length;i<i1;i++){
44                 var currentlayer=map.getLayer(map.layerIds[i]);
45                 alert("id: "+currentlayer.id+",visible:"+currentlayer.visible+",opacity"+currentlayer.opacity);
46             }
47         
48         } 
49         //控件参考
50         function getSr(){
51             alert("Spatial Reference WKID:"+map.spatialReference.wkid);
52         
53         }
54         //比例级别
55         function getScales(){
56             var titleInfo=portlandParcels.titleInfo;
57             var scales="";
58             for(var i=0,j=titleInfo.lods.length;i<j;i++){
59                 var level=titleInfo.lods[i].level;
60                 var scale=titleInfo.lods[i].scale;
61                 var resolution=titleInfo.lods[i].resolution;
62                 scales=scales + "level:" + level + ",scale" + scale + ",resolution" + resolution;
63             }
64             alert(scales);
65         
66         }
67         //获取地图宽度和高度
68         
69         function getMapWidthHeight(){
70             alert("Width: " + map.width + "Height: " + map.height);
71         }
72         
73         dojo.addOnLoad(init);
74     </script>
75 
76   </head>
77   
78   <body>
79     <div id="map" class="tundra" style="width:900px;height:600px;border:1px solid #000;"></div>
80             <input type="button" value="所有图层" onclick="getMapLayers()"/>
81            <input type="button" value="控件参考" onclick="getSr()"/>
82            <input type="button" value="比例级别" onclick="getScales()"/>
83            <input type="button" value="地图的宽度高度" onclick="getMapWidthHeight()"/>
84   </body>
85 </html>

 

ArcGIS api for javascript——显示地图属性