『TS 4 ArcGIS』hello world
webgis 2019-12-15
TS
GIS
二维
# 官方案例地址
https://developers.arcgis.com/javascript/latest/guide/typescript-setup/index.html
本图文是根据官方提供的 demo 模板,做的一些修改
官方案例下载地址
# 开发环境
node v7.10.0
npm v4.2.0
arcgis for js 4.7
vs code
Live Server //vs code插件,运行web服务
1
2
3
4
5
2
3
4
5
# 初始化 demo
npm install
//安装arcgis-js-api,直接使用官方demo可以忽略这步
npm install --save @types/arcgis-js-api
//dojo 依赖
npm install dojo-typings --save-dev
1
2
3
4
5
6
7
8
9
2
3
4
5
6
7
8
9
注:由于官方 demo 中 package.json 中 arcgis-js-api 版本可能不是最新的,可以先去除掉 arcgis 依赖版本或者直接修改版本号
# 运行
npm run dev //启动 ts 转 js
//运行 Live Server 启动web服务 默认端口号是 5500
1
2
2
# 运行效果

# 功能介绍
- 通过 LayerList 做图层显示隐藏
- 通过 WebTileLayer 添加高德地图和高德影像图
- 通过 GroupLayer 将影像图和注解合并为一个图层组
- view.ui.remove 属性移除官方版权信息标注
# main.ts
import EsriMap = require("esri/Map");
import MapView = require("esri/views/MapView");
import GroupLayer = require("esri/layers/GroupLayer");
import WebTileLayer = require("esri/layers/WebTileLayer");
import LayerList = require("esri/widgets/LayerList");
import Point = require("esri/geometry/Point");
const gaodeWebTileLayer = new WebTileLayer({
title: "高德地图",
urlTemplate: "http://webrd0{subDomain}.is.autonavi.com/appmaptile?lang=zh_cn&size=1&scale=1&style=8&x={col}&y={row}&z={level}",
subDomains: ["1", "2", "3", "4"],
copyright: "高德地图"
});
const gaodeSat_WTL = new WebTileLayer({
title: "高德影像图",
urlTemplate: "http://webst0{subDomain}.is.autonavi.com/appmaptile?style=6&x={col}&y={row}&z={level}",
subDomains: ["1", "2", "3", "4"],
copyright: "高德影像图"
});
const gaodeSatAnnotion_WTL = new WebTileLayer({
title: "高德影像图注解",
urlTemplate: "http://webst0{subDomain}.is.autonavi.com/appmaptile?style=8&x={col}&y={row}&z={level}",
subDomains: ["1", "2", "3", "4"],
copyright: "高德影像图"
});
const gaodeSat_group = new GroupLayer({
title: "高德影像图"
});
gaodeSat_group.addMany([gaodeSat_WTL, gaodeSatAnnotion_WTL])
const map = new EsriMap({
layers: [gaodeWebTileLayer, gaodeSat_group]
});
const view = new MapView({
map: map,
container: "viewDiv",
center: new Point({
x: 118.244,
y: 34.052
}),
zoom: 10
});
//移除 版权信息
view.ui.remove(["attribution"]);
//图层列表
const layerList = new LayerList({
view: view
});
view.ui.add(layerList, "top-left");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60