前言
在上一篇博客讲述了怎么发布动态地图服务,在本章中介绍怎么在JavaScript加载动态地图服务。
准备
- 在本地部署ArcGIS JS API/调用在线的API
- 发布好的动态地图服务
思路
- 实例化地图对象
- 实例化动态图层对象
- 将动态图层对象添加到地图对象中
代码实现
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/arcgis_js_api/library/3.20/3.20/dijit/themes/tundra/tundra.css"/>
<link rel="stylesheet" type="text/css" href="http://localhost:8080/arcgis_js_api/library/3.20/3.20/esri/css/esri.css" />
<script type="text/javascript" src="http://localhost:8080/arcgis_js_api/library/3.20/3.20/init.js"></script>
</head>
<body class="claro">
<div id="map" style="height:800px;"></div>
<script>
require([
"esri/map",
"esri/layers/ArcGISDynamicMapServiceLayer",
"dojo/domReady!"],
function(Map,ArcGISDynamicMapServiceLayer) {
var _Map=new Map(map);
var _Dynamiclayer=new ArcGISDynamicMapServiceLayer("http://localhost:6080/arcgis/rest/services/firstTest/firstService/MapServer");
_Map.addLayer(_Dynamiclayer);
});
</script>
</body>
</html>
运行结果
注意问题
实例化动态图层链接用的是restURL