1次泽、環(huán)境安裝
(1) Node.js(包含npm了袁,node包管理器)
(2) git
(3) Java 7或更高版本 - Closure Compiler所需 (用于Dojo構(gòu)建,英文為Dojo build)
環(huán)境安裝參考React+Cordova+Android環(huán)境配置中的1刻诊、nvm-windows安裝矗烛;5、Android需求環(huán)境
2告组、克隆jsapi-resources
cd /d D:\mapp
git clone https://github.com/Esri/jsapi-resources.git
3、安裝bower
npm install -g bower
4癌佩、安裝依賴的包
進(jìn)入jsapi-resources\3.x\bower\dojo
文件夾木缝,執(zhí)行安裝依賴包,安裝過(guò)程視網(wǎng)絡(luò)情況需要一定的時(shí)間围辙,下載文件失敗請(qǐng)重試(可能需要科學(xué)上網(wǎng))
cd /d D:\mapp\jsapi-resources\3.x\bower\dojo
npm install
執(zhí)行成功后我碟,會(huì)在dojo
文件夾下多出node_modules
文件夾,在dojo/src
下多出dojo
姚建、dojox
矫俺、esri
等文件夾,如下圖所示
5掸冤、修改相應(yīng)文件
(1)dojo/build.profile.js
中的layers
layers的每一個(gè)屬性表示一個(gè)獨(dú)立的js文件溢谤,可將多個(gè)js文件合成一個(gè)文件輸出坏逢,如下面的app/main
會(huì)輸出為app/main.js
,該文件中包含app/main
、dojox/gfx/path
衙荐、dojox/gfx/svg
等多個(gè)文件的代碼。
layers: {
// This is the main loader module. It is a little special because it is treated like an AMD module even though
// it is actually just plain JavaScript. There is some extra magic in the build system specifically for this
// module ID.
"dojo/dojo": {
// By default, the build system will try to include `dojo/main` in the built `dojo/dojo` layer, which adds
// a bunch of stuff we do not want or need. We want the initial script load to be as small and quick to
// load as possible, so we configure it as a custom, bootable base.
boot: true,
customBase: true
},
'app/main': {
include: [
"app/main",
"dojox/gfx/path",
"dojox/gfx/svg",
"dojox/gfx/filters",
"dojox/gfx/svgext",
"dojox/gfx/shape",
"esri/dijit/Attribution"
],
includeLocales: ["zh-cn"]
},
"esri/layers/VectorTileLayerImpl": {
include: [
"esri/layers/VectorTileLayerImpl"
],
includeLocales: ["zh-cn"]
},
"esri/layers/support/webglDeps": {
include: [
"esri/layers/support/webglDeps"
],
includeLocales: ["zh-cn"]
}
},
(2)dojo/src/built.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;"> -->
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<title></title>
<link rel="stylesheet" href="dijit/themes/claro/claro.css">
<link rel="stylesheet" href="esri/css/esri.css">
<style>
html,
body,
#map {
height: 100%;
padding: 0;
margin: 0;
}
</style>
<script src="dojo/dojo.js"></script>
<script>require(["app/main"]);</script>
</head>
<body class="claro">
<div id="map"></div>
<script type="text/javascript" src="cordova.js"></script>
</body>
</html>
(3)dojo/src/app/main.js
define(["esri/map"], function (Map) {
var map = new Map("map", {
basemap: "topo",
center: [-122.45, 37.75],
zoom: 13
});
});
6塔淤、構(gòu)建
在jsapi-resources\3.x\bower\dojo
文件夾下執(zhí)行構(gòu)建
npm run build
注意:構(gòu)建完的文件在dojo/dist
下,包含完整的包流礁。如果需要手動(dòng)挑選出需要加載的資源文件比較困難,可通過(guò)發(fā)布網(wǎng)站并利用工具下載來(lái)達(dá)到挑選的目的罗丰。
7神帅、將文件夾發(fā)布為虛擬目錄并進(jìn)行訪問(wèn)
將D:\mapp\jsapi-resources\3.x\bower
文件夾發(fā)布為虛擬目錄
訪問(wèn)http://localhost/bower/dojo/dist/index.html
8、下載頁(yè)面資源文件
(1)打開Chrome網(wǎng)上應(yīng)用店
https://chrome.google.com/webstore/category/extensions萌抵,需要科學(xué)上網(wǎng)枕稀;
(2)查找Full download JS/CSS/HTML
,點(diǎn)擊添加至Chrome
谜嫉;
(3)按F12
打開開發(fā)者工具
萎坷,找到FullDownload
,點(diǎn)擊Record
進(jìn)行錄制沐兰,按F5
刷新頁(yè)面哆档,按DownloadAll
下載資源。
參考資料
1住闯、Using Bower for Custom Builds of the ArcGIS API for JavaScript
https://developers.arcgis.com/javascript/3/jshelp/inside_bower_custom_builds.html
2瓜浸、Bower Sample application
https://github.com/Esri/jsapi-resources/tree/master/3.x/bower/dojo
轉(zhuǎn)載請(qǐng)注明:作者gisxiaowei,首發(fā)簡(jiǎn)書 jianshu.com