目录
目前最新版本为ArcGIS API for JavaScript 4.14
ArcGIS API for JavaScript下载
ArcGIS API for JavaScript官网下载地址:https://developers.arcgis.com/downloads/apis-and-sdks?product=javascript
API安装包介绍
打开解压完的API
修改文件
dojo.js
在文本编辑器中打开并搜索文本[HOSTNAME_AND_PATH_TO_JSAPI]
,然后将其替换为www.example.com/arcgis_js_api/library/4.14/
。
www.example.com可以是localhost,只能本机引用
也可以是 本机的IPv4,局域网中均可访问
IPv4地址查询参考:https://blog.csdn.net/qq_41664159/article/details/103300878
本次安装使用 localhost/arcgis_js_api/library/4.14/
init.js
在文本编辑器中打开并搜索文本[HOSTNAME_AND_PATH_TO_JSAPI]
,然后将其替换为localhost/arcgis_js_api/library/4.14/
。
移动文件
可以将ArcGIS API for JavaScript库全部复制到Web服务器目录(C:\Inetpub\wwwroot\arcgis_js_api\library\4.14\
)。将\arcgis_js_api\library\4.14\
ArcGIS API for JavaScript 复制及其所有内容下载到Web服务器。在此示例中,文件被复制到:C:\Inetpub\wwwroot\arcgis_js_api\library\4.14\
。
C:\Inetpub\wwwroot 为本机默认端口的端口,也就是在浏览器中输入localhost出现的界面
也就是说可以改变端口号
测试
官方测试demo
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no" />
<title>Test Map</title>
<link rel="stylesheet" href="http://localhost/arcgis_js_api/library/4.14/dijit/themes/claro/claro.css" />
<link rel="stylesheet" href="http://localhost/arcgis_js_api/library/4.14/esri/themes/light/main.css" />
<style>
html,
body,
#viewDiv {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
</style>
<script src="http://localhost/arcgis_js_api/library/4.14/dojo/dojo.js"></script>
<script>
var myMap, view;
require([
"esri/Basemap",
"esri/layers/TileLayer",
"esri/Map",
"esri/views/MapView"
], function (Basemap, TileLayer, Map, MapView){
// --------------------------------------------------------------------
// If you do not have public internet access then use the Basemap class
// and point this URL to your own locally accessible cached service.
//
// Otherwise you can just use one of the named hosted ArcGIS services.
// https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer
// --------------------------------------------------------------------
var layer = new TileLayer({
url:"https://services.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer"
// url: "https://js.arcgis.com/arcgis/rest/services/Folder/Custom_Base_Map/MapServer"
});
var customBasemap = new Basemap({
baseLayers: [layer],
title: "Custom Basemap",
id: "myBasemap"
});
myMap = new Map({
basemap: customBasemap
});
view = new MapView({
center: [-111.87, 40.57], // long, lat
container: "viewDiv",
map: myMap,
zoom: 6
});
});
</script>
</head>
<body class="claro">
<div id="viewDiv"></div>
</body>
</html>
webscene加载
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
<title>Create a 3D map</title>
<style>
html,
body,
#viewDiv {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
</style>
<link rel="stylesheet" href="http://localhost/arcgis_js_api/library/4.14/esri/themes/light/main.css">
<script src="http://localhost/arcgis_js_api/library/4.14/dojo/dojo.js"></script>
<!--<script src="https://js.arcgis.com/4.14/"></script>-->
<script>
require([ "esri/views/SceneView", "esri/WebScene","esri/config","dojo/domReady!"],
function(SceneView, WebScene, esriConfig){
//设置portal的url,如果不设置默认为“http://www.arcgis.com/”
esriConfig.portalUrl="http://www.arcgis.com/";
var scene = new WebScene({
portalItem: { // 自动创建一个PortalItem()
id: "579f97b2f3b94d4a8e48a5f140a6639b"
} });
var view = new SceneView({
map: scene,
container: "viewDiv" });
});
</script>
</head>
<body>
<div id="viewDiv"></div>
</body>
</html>
参考:http://zhihu.esrichina.com.cn/article/3514
这个老哥的方法也很好,不过没尝试:https://blog.csdn.net/shl123s/article/details/70792700