|
@@ -1,99 +0,0 @@
|
1
|
|
-/**
|
2
|
|
- * 高德地图
|
3
|
|
- *
|
4
|
|
- * POI 类型下载 https://lbs.amap.com/api/webservice/guide/api/search/#around
|
5
|
|
- *
|
6
|
|
- */
|
7
|
|
-const amapLib = require('../lib/amap-wx');
|
8
|
|
-const myAmapKey = '766411323b66f7e876f428d8a23aa83c'
|
9
|
|
-const amap = new amapLib.AMapWX({ key: myAmapKey })
|
10
|
|
-
|
11
|
|
-// key 值会被拿到 building 表中 组合为字段名
|
12
|
|
-const POI_TYPES = [
|
13
|
|
- {
|
14
|
|
- key: 'Transport',
|
15
|
|
- label: '交通',
|
16
|
|
- types: ['150100', '150200', '150300', '150400', '150500', '150600'],
|
17
|
|
- },
|
18
|
|
- {
|
19
|
|
- key: 'Mall',
|
20
|
|
- label: '商业',
|
21
|
|
- types: ['060100', '060200', '060300', '060400', '060500', '060600',
|
22
|
|
- '060700', '060800', '060900', '061000', '061100', '061200',
|
23
|
|
- '061300', '061400', '080100', '080200', '080300', '080400',
|
24
|
|
- '080500', '080600'],
|
25
|
|
- },
|
26
|
|
- {
|
27
|
|
- key: 'Edu',
|
28
|
|
- label: '学校',
|
29
|
|
- types: ['141200'],
|
30
|
|
- },
|
31
|
|
- {
|
32
|
|
- key: 'Hospital',
|
33
|
|
- label: '医院',
|
34
|
|
- types: ['090100', '090200', '090300', '090400', '090500', '090600', '090700'],
|
35
|
|
- },
|
36
|
|
- {
|
37
|
|
- key: 'Bank',
|
38
|
|
- label: '银行',
|
39
|
|
- types: ['160100'],
|
40
|
|
- },
|
41
|
|
- {
|
42
|
|
- key: 'Restaurant',
|
43
|
|
- label: '餐饮',
|
44
|
|
- types: ['050100', '050200', '050300', '050400', '050500', '050600',
|
45
|
|
- '050700', '050800', '050900'],
|
46
|
|
- },
|
47
|
|
-]
|
48
|
|
-
|
49
|
|
-const getPrefix = str => str.substr(0, 4)
|
50
|
|
-
|
51
|
|
-export function getPoiAround(params) {
|
52
|
|
- const {
|
53
|
|
- lng,
|
54
|
|
- lat
|
55
|
|
- } = params || {}
|
56
|
|
-
|
57
|
|
- return new Promise((resolve, reject) => {
|
58
|
|
- const querytypes = POI_TYPES.reduce((acc, item) => ([ ...acc, ...item.types ]), []).join('|')
|
59
|
|
- const location = `${lng},${lat}`
|
60
|
|
- const iconPath = undefined
|
61
|
|
- const iconPathSelected = undefined
|
62
|
|
- const resultList = []
|
63
|
|
-
|
64
|
|
- // 成功回调
|
65
|
|
- // https://lbs.amap.com/api/webservice/guide/api/search/#around
|
66
|
|
- const successCall = poiType => res => {
|
67
|
|
- resultList.push({
|
68
|
|
- key: poiType.key,
|
69
|
|
- label: poiType.label,
|
70
|
|
- poisData: res.poisData,
|
71
|
|
- markers: res.markers
|
72
|
|
- })
|
73
|
|
-
|
74
|
|
- if (resultList.length === POI_TYPES.length) {
|
75
|
|
- resolve(resultList)
|
76
|
|
- }
|
77
|
|
- }
|
78
|
|
-
|
79
|
|
- // 失败回调
|
80
|
|
- // https://lbs.amap.com/api/webservice/guide/tools/info/
|
81
|
|
- const failCall = poiType => info => {
|
82
|
|
- console.error(poiType, info)
|
83
|
|
- reject(info)
|
84
|
|
- }
|
85
|
|
-
|
86
|
|
- POI_TYPES.forEach((pt) => {
|
87
|
|
- const querytypes = pt.types.join('|')
|
88
|
|
-
|
89
|
|
- amap.getPoiAround({
|
90
|
|
- querytypes,
|
91
|
|
- location,
|
92
|
|
- iconPath,
|
93
|
|
- iconPathSelected,
|
94
|
|
- success: successCall(pt),
|
95
|
|
- fail: failCall(pt),
|
96
|
|
- })
|
97
|
|
- })
|
98
|
|
- })
|
99
|
|
-}
|