描述
此示例显示了如何添加一个的地形底图层到您的应用程序。该示例使用一个缓存的地图服务从ArcGIS Online。您可以浏览ArcGIS.com额外的在线参考底图和地图服务的网站,或使用ArcGIS Server作为服务发布自己的地理数据。
此示例设置初始范围的地图在旧金山的区域,使用下面的代码:
var initExtent=new esri.geometry.Extent({"xmin":-13635568.034589134,"ymin":4541606.359162286,"xmax":-13625430.573712826,"ymax":4547310.472398059,"spatialReference":{"wkid":102100}});
map = new esri.Map("map",{extent:initExtent});
演示地址联接:http://help.arcgis.com/en/webapi/javascript/arcgis/samples/map_topo/index.html
<!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,IE=9" />
<!--The viewport meta tag is used to improve the presentation and behavior of the samples
on iOS devices-->
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
<title>Topographic Map</title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/claro/claro.css">
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" />
<style>
html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
.esriScalebar{
padding: 20px 20px;
}
#map{
padding:0;
}
</style>
<script type="text/javascript">var djConfig = {parseOnLoad: true};</script>
<script type="text/javascript" src="http://serverapi.arcgisonline.com/jsapi/arcgis/?v=3.2"></script>
<script type="text/javascript">
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("esri.map");
var map;
function init() {
var initExtent = new esri.geometry.Extent({"xmin":-122.46,"ymin":37.73,"xmax":-122.36,"ymax":37.77,"spatialReference":{"wkid":4326}});
map = new esri.Map("map",{
extent:esri.geometry.geographicToWebMercator(initExtent)
});
//添加到地图的地形层。ArcGIS Online的网站服务http://arcgisonline/home/search.html?t=content&f=typekeywords:service
var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://server.arcgisonline.com/ArcGIS/rest/services/World_Topo_Map/MapServer");
map.addLayer(basemap);
dojo.connect(map, 'onLoad', function(theMap) {
//地图随浏览器变动
dojo.connect(dijit.byId('map'), 'resize', map,map.resize);
});
}
dojo.addOnLoad(init);
</script>
</head>
<body class="claro">
<div dojotype="dijit.layout.BorderContainer" design="headline" gutters="false" style="width: 100%; height: 100%; margin: 0;">
<div id="map" dojotype="dijit.layout.ContentPane" region="center" style="border:1px solid #000;padding:0;">
</div>
</div>
</body>
</html>
具体使用方法属性和参数,请参考API文档:
相关所有API:http://resources.arcgis.com/en/help/previous-help/index.html
The Demo 链接:http://help.arcgis.com/en/webapi/javascript/arcgis/help/jssamples_start.htm
效果图: