1. 下載并安裝Node.js
2. 復制粘貼代碼
2.1. 創(chuàng)建一個文件夾,名字隨便起梦鉴,但是不能有中文
2.2. 在剛剛這個文件夾里分別創(chuàng)建以下文件
- package.json
- index.html
- index.js
2.3. 復制以下代碼
package.json 文件內容:
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "parcel index.html",
"build": "parcel build --experimental-scope-hoisting --public-url . index.html"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"ol": "^6.3.1",
"parcel": "^1.12.4"
}
}
index.html :
<!DOCTYPE html>
<html lang="en">
<head>
<title>Tiled ArcGIS MapServer</title>
<!-- The line below is only needed for old environments like Internet Explorer and Android 4.x -->
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,requestAnimationFrame,Element.prototype.classList,URL"></script>
<style>
.map {
width: 100vw;
height:100vh;
}
</style>
</head>
<body>
<div id="map" class="map"></div>
<script src="index.js"></script>
</body>
</html>
index.js :
import 'ol/ol.css';
import Map from 'ol/Map';
import View from 'ol/View';
import TileLayer from 'ol/layer/Tile';
import {OSM, TileArcGISRest} from 'ol/source';
// 這個替換成你自己的路徑
let url = 'http://localhost:6080/arcgis/rest/services/%E4%BD%9C%E4%B8%9A3_%E4%B8%96%E7%95%8C%E5%9C%B0%E5%9B%BE/MapServer';
var layers = [
new TileLayer({
source: new TileArcGISRest({
url: url
})
})
];
var map = new Map({
layers: layers,
target: 'map',
view: new View({
center: [-10967148, 3069099],
zoom: 6
})
});
3. 執(zhí)行命令凤巨,進行打包
安裝cnpm
:
npm i -g cnpm
安裝依賴:
cnpm install
進行打包:
npm run build
4. 查看結果
打包好后服傍,可以看到一個dist
文件夾幸逆,里面有一個index.html
文件却嗡,打開它看看纵隔。