前期做地图开发用的API 是SILVERLIGHT 项目需要,学习下JS API
首先从官方下载最新的API包 3.2一共有2个压缩包API:arcgis_js_v32_api.zip和arcgis_js_v32_sdk.zip
解压arcgis_js_v32_api,在library文件夹下可以看到安装说明文件install.htm
下一步 根据安装说明进行配置。
部署步骤1:将解压缩后的文件目录拷贝到web服务器网站根目录下,这里使用IIS。根目录。C:\Inetpub\wwwroot
拷贝后的文件目录结构为
C:\Inetpub\wwwroot\arcgis_js_api\library
部署步骤2:修改全局变量[HOSTNAME_AND_PATH_TO_JSAPI] ,EditPlus或则DW都可以 查找替换为localhost/library/3.2/jsapi 和localhost/library/3.2/jsapicompact
如果端口不是80 需要加上端口号 (localhost:端口)
Configuration options for normal build:
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.2\jsapi\init.js in a text editor and search for the text
'[HOSTNAME_AND_PATH_TO_JSAPI]'
, and replace this text with"<myserver>/arcgis_js_api/library/3.2/jsapi/"
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.2\jsapi\js\dojo\dojo\dojo.js in a text editor and search for the text
'[HOSTNAME_AND_PATH_TO_JSAPI]'
, and replace this text with"<myserver>/arcgis_js_api/library/3.2/jsapi/"
Configuration options for compact build:
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.2\jsapicompact\init.js in a text editor and search for the text
'[HOSTNAME_AND_PATH_TO_JSAPI]'
, and replace each instance of this text with"<myserver>/arcgis_js_api/library/3.2/jsapicompact/"
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.2\jsapicompact\js\dojo\dojo\dojo.js in a text editor and search for the text
'[HOSTNAME_AND_PATH_TO_JSAPI]'
, and replace this text with"<myserver>/arcgis_js_api/library/3.2/jsapicompact/"
步骤3: 测试是否发布成功,官方的安装说明文件中给出了完成的测试代码
< html >
< head >
< meta http-equiv ="Content-Type" content ="text/html; charset=utf-8" /> < title >Simple Map </ title >
< link rel ="stylesheet" type ="text/css" href ="http://<myserver>/arcgis_js_api/library/3.2/jsapi/js/dojo/dijit/themes/tundra/tundra.css" />
< link rel ="stylesheet" type ="text/css" href ="http://<myserver>/arcgis_js_api/library/3.2/jsapi/js/esri/css/esri.css" />
< script type ="text/javascript" src ="http://<myserver>/arcgis_js_api/library/3.2/jsapi/init.js" ></ script >
< script type ="text/javascript" > dojo.require( " esri.map " );
function init() {
var myMap = new esri.Map( " mapDiv " );
// note that if you do not have public Internet access then you will need to point this url to your own locally accessible cached service.
var myTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer( " http://server.arcgisonline.com/ArcGIS/rest/services/NGS_Topo_US_2D/MapServer " ); myMap.addLayer(myTiledMapServiceLayer); }
dojo.addOnLoad(init);
</ script >
</ head >
< div id ="mapDiv" style ="width:900px; height:600px; border:1px solid #000;" ></ div >
</ html >
放到IIS目录里运行下试试,如果地图可以正常显示 则表示部署成功 。
注意:官方测试代码给出的地图服务是缓存地图,如果地图服务是动态地图话需要使用动态图层ArcGISDynamicMapServiceLayer才能显示。