描述
这个示例表现如何加两个动态地图到一个地图。动态服务按用户缩放或平移服务器每次绘制的地图, ArcGISDynamicMapServiceLayer表示ArcGIS JavaScript API动态地图服务。不像切片地图服务,动态地图服务没有一个预先渲染的图片切片的 cache。由于这个原因,动态地图服务比切片地图服务慢,但是对显示常常修改的和实时的数据是很有用的。
图层顺序由 map.addLayer方法调用的顺序决定。第一个被增加的图层被放置在下方。后来的图层放置在上面。在这个示例中,USA人口普查的国家图层被放置在堪萨斯州石油和天然气图层上方。
注意图层使用setOpacity方法设置半透明的。
dynlayer2.setOpacity(0.5);
<%@ 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>TwoDynamicMapServiceLayers</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"> <script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=1.6"></script> <script type="text/javascript"> dojo.require("esri.map"); function init(){ var map = new esri.Map("map"); //非缓存地图服务URL,多个动态地图层序由加载顺序决定,先添加的放在下面 var dynamicMapServiceLayer = new esri.layers.ArcGISDynamicMapServiceLayer( "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Petroleum/KGS_OilGasFields_Kansas/MapServer" ); map.addLayer(dynamicMapServiceLayer); var dynamicMapServiceLayer2 = new esri.layers.ArcGISDynamicMapServiceLayer( "http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer",{"opacity":0.5} //"http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Demographics/ESRI_Census_USA/MapServer" ); map.addLayer(dynamicMapServiceLayer2); } dojo.addOnLoad(init); </script> </head> <body class="tundra"> <div id="map" style="900px;height:600px;border:1px solid #000"></div> Creates a map adds two ArcGISDynamicMapServiceLayers.<br> Map navigation using mouse:利用鼠标进行地图导航 <ul> <li>Drag to pan</li> <li>SHIFT + Click to recenter</li> <li>SHIFT + Drag to zoom in</li> <li>SHIFT + CTRL + Drag to zoom out</li> <li>Mouse Scroll Forward to zoom in</li> <li>Mouse Scroll Backward to zoom out</li> <li>Use Arrow keys to pan</li> <li>+ key to zoom in a level</li> <li>- key to zoom out a level</li> <li>Double Click to Center and Zoom in</li> </ul> </body> </html>