ArcGIS Server for javascript 本地部署
第一次使用arcgis server for js開發,在經驗方面還有很多的不足,所以將自己在開發過程中遇到的問題寫出來與大家共享。有什么不足的地方還望多多指正,共同學習。
一、arcgis arcgis for JavaScript API的下載地址為:http://help.arcgis.com/en/webapi/javascript/arcgis/
二、下載之后的壓縮包解壓之后
三、將解壓的api和sdk要部署到IIS的wwwroot文件夾下面:
需要注意的是,在后邊的代碼測試中腰鍵入的文件鏈接,是將如上圖文件夾中問價單獨復制出來,放在wwwroot文件夾中,否則會出錯。
四、進行相關參數的修改,也可以參考library問價夾下面的install.html文件。
Configuration options for normal build:
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.11\3.11\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.11/3.11/"
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.11\3.11\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.11/3.11/"
Configuration options for compact build:
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.11\3.11compact\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.11/3.11compact/"
- Open C:\Inetpub\wwwroot\arcgis_js_api\library\3.11\3.11compact\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.11/3.11compact/"
注意:在進行參數替換時,其中的<myserver>為主機名,一般情況下改為localhost。否在修改太麻煩了!
五、完成以上的文件部署后在vs中新建web程序,添加html頁,進行測試是否部署成功。
具體的代碼如下:
1 <head> 2 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 3 <title>地圖的加載</title> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <title>Simple Map</title>
注意:此處的代碼為本地部署的調用,其中的文件路徑必須正確,否則調試出錯。 6 <link rel="stylesheet" type="text/css" href="http://localhost/arcgis_js_api/library/3.11/3.11/dijit/themes/tundra/tundra.css"/> 7 <link rel="stylesheet" type="text/css" href="http://localhost/arcgis_js_api/library/3.11/3.11/esri/css/esri.css" /> 8 <script type="text/javascript" src="http://localhost/arcgis_js_api/library/3.11/3.11/init.js"></script> 9 <script src="dojo/jsapi_vsdoc10_v33.js" type="text/Javascript"></script> 10 <style type="text/css"> 11 .MapClass { width:900px; height:600px; border:1px solid #000; } 12 </style> 13 <script type="text/Javascript"> dojo.require("esri.map"); 14 dojo.addOnLoad(function () 15 { 16 var MyMap = new esri.Map("MyMapDiv"); 17 var MyTiledMapServiceLayer = new esri.layers.ArcGISTiledMapServiceLayer 18 ("http://cache1.arcgisonline.cn/ArcGIS/rest/services/ChinaOnlineStreetWarm/MapServer"); 19 MyMap.addLayer(MyTiledMapServiceLayer) 20 }) 21 22 </script> 23 </head> 24 <body class="tundra"> 25 <div id="MyMapDiv" class="MapClass"> 26 27 </div> 29 </body> 30 </html>
六、測試結果的顯示