@10yun/cv-mobile-ui 0.5.38 → 0.5.39
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/libs/amap-wx.130.js +485 -0
- package/libs/amap-wx.js +517 -0
- package/libs/highlight/github-dark.min.css +10 -0
- package/libs/highlight/highlight-uni.min.js +5256 -0
- package/libs/html-parser.js +352 -0
- package/libs/jweixin-module.js +1 -0
- package/libs/markdown-it.min.js +2 -0
- package/libs/md5.js +774 -0
- package/libs/permission.js +244 -0
- package/libs/qqmap-wx-jssdk.js +1178 -0
- package/package.json +1 -1
- package/plugins/{map/uniMap.js → uniMap.js} +0 -20
- package/uview-plus/libs/ctocode/index.js +1 -10
- package/plugins/map/lib/amap-wx.js +0 -1
- /package/{plugins/map → libs}/amqp-wx.js +0 -0
- /package/{plugins/map → libs}/qqmap.js +0 -0
|
@@ -0,0 +1,1178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 微信小程序JavaScriptSDK
|
|
3
|
+
*
|
|
4
|
+
* @version 1.2
|
|
5
|
+
* @date 2019-03-06
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
var ERROR_CONF = {
|
|
9
|
+
KEY_ERR: 311,
|
|
10
|
+
KEY_ERR_MSG: 'key格式错误',
|
|
11
|
+
PARAM_ERR: 310,
|
|
12
|
+
PARAM_ERR_MSG: '请求参数信息有误',
|
|
13
|
+
SYSTEM_ERR: 600,
|
|
14
|
+
SYSTEM_ERR_MSG: '系统错误',
|
|
15
|
+
WX_ERR_CODE: 1000,
|
|
16
|
+
WX_OK_CODE: 200
|
|
17
|
+
};
|
|
18
|
+
var BASE_URL = 'https://apis.map.qq.com/ws/';
|
|
19
|
+
var URL_SEARCH = BASE_URL + 'place/v1/search';
|
|
20
|
+
var URL_SUGGESTION = BASE_URL + 'place/v1/suggestion';
|
|
21
|
+
var URL_GET_GEOCODER = BASE_URL + 'geocoder/v1/';
|
|
22
|
+
var URL_CITY_LIST = BASE_URL + 'district/v1/list';
|
|
23
|
+
var URL_AREA_LIST = BASE_URL + 'district/v1/getchildren';
|
|
24
|
+
var URL_DISTANCE = BASE_URL + 'distance/v1/';
|
|
25
|
+
var URL_DIRECTION = BASE_URL + 'direction/v1/';
|
|
26
|
+
var MODE = { driving: 'driving', transit: 'transit' };
|
|
27
|
+
var EARTH_RADIUS = 6378136.49;
|
|
28
|
+
var Utils = {
|
|
29
|
+
/**
|
|
30
|
+
* md5加密方法
|
|
31
|
+
* 版权所有©2011 Sebastian Tschan,https://blueimp.net
|
|
32
|
+
*/
|
|
33
|
+
safeAdd(x, y) {
|
|
34
|
+
var lsw = (x & 0xffff) + (y & 0xffff);
|
|
35
|
+
var msw = (x >> 16) + (y >> 16) + (lsw >> 16);
|
|
36
|
+
return (msw << 16) | (lsw & 0xffff);
|
|
37
|
+
},
|
|
38
|
+
bitRotateLeft(num, cnt) {
|
|
39
|
+
return (num << cnt) | (num >>> (32 - cnt));
|
|
40
|
+
},
|
|
41
|
+
md5cmn(q, a, b, x, s, t) {
|
|
42
|
+
return this.safeAdd(this.bitRotateLeft(this.safeAdd(this.safeAdd(a, q), this.safeAdd(x, t)), s), b);
|
|
43
|
+
},
|
|
44
|
+
md5ff(a, b, c, d, x, s, t) {
|
|
45
|
+
return this.md5cmn((b & c) | (~b & d), a, b, x, s, t);
|
|
46
|
+
},
|
|
47
|
+
md5gg(a, b, c, d, x, s, t) {
|
|
48
|
+
return this.md5cmn((b & d) | (c & ~d), a, b, x, s, t);
|
|
49
|
+
},
|
|
50
|
+
md5hh(a, b, c, d, x, s, t) {
|
|
51
|
+
return this.md5cmn(b ^ c ^ d, a, b, x, s, t);
|
|
52
|
+
},
|
|
53
|
+
md5ii(a, b, c, d, x, s, t) {
|
|
54
|
+
return this.md5cmn(c ^ (b | ~d), a, b, x, s, t);
|
|
55
|
+
},
|
|
56
|
+
binlMD5(x, len) {
|
|
57
|
+
/* append padding */
|
|
58
|
+
x[len >> 5] |= 0x80 << len % 32;
|
|
59
|
+
x[(((len + 64) >>> 9) << 4) + 14] = len;
|
|
60
|
+
|
|
61
|
+
var i;
|
|
62
|
+
var olda;
|
|
63
|
+
var oldb;
|
|
64
|
+
var oldc;
|
|
65
|
+
var oldd;
|
|
66
|
+
var a = 1732584193;
|
|
67
|
+
var b = -271733879;
|
|
68
|
+
var c = -1732584194;
|
|
69
|
+
var d = 271733878;
|
|
70
|
+
|
|
71
|
+
for (i = 0; i < x.length; i += 16) {
|
|
72
|
+
olda = a;
|
|
73
|
+
oldb = b;
|
|
74
|
+
oldc = c;
|
|
75
|
+
oldd = d;
|
|
76
|
+
|
|
77
|
+
a = this.md5ff(a, b, c, d, x[i], 7, -680876936);
|
|
78
|
+
d = this.md5ff(d, a, b, c, x[i + 1], 12, -389564586);
|
|
79
|
+
c = this.md5ff(c, d, a, b, x[i + 2], 17, 606105819);
|
|
80
|
+
b = this.md5ff(b, c, d, a, x[i + 3], 22, -1044525330);
|
|
81
|
+
a = this.md5ff(a, b, c, d, x[i + 4], 7, -176418897);
|
|
82
|
+
d = this.md5ff(d, a, b, c, x[i + 5], 12, 1200080426);
|
|
83
|
+
c = this.md5ff(c, d, a, b, x[i + 6], 17, -1473231341);
|
|
84
|
+
b = this.md5ff(b, c, d, a, x[i + 7], 22, -45705983);
|
|
85
|
+
a = this.md5ff(a, b, c, d, x[i + 8], 7, 1770035416);
|
|
86
|
+
d = this.md5ff(d, a, b, c, x[i + 9], 12, -1958414417);
|
|
87
|
+
c = this.md5ff(c, d, a, b, x[i + 10], 17, -42063);
|
|
88
|
+
b = this.md5ff(b, c, d, a, x[i + 11], 22, -1990404162);
|
|
89
|
+
a = this.md5ff(a, b, c, d, x[i + 12], 7, 1804603682);
|
|
90
|
+
d = this.md5ff(d, a, b, c, x[i + 13], 12, -40341101);
|
|
91
|
+
c = this.md5ff(c, d, a, b, x[i + 14], 17, -1502002290);
|
|
92
|
+
b = this.md5ff(b, c, d, a, x[i + 15], 22, 1236535329);
|
|
93
|
+
|
|
94
|
+
a = this.md5gg(a, b, c, d, x[i + 1], 5, -165796510);
|
|
95
|
+
d = this.md5gg(d, a, b, c, x[i + 6], 9, -1069501632);
|
|
96
|
+
c = this.md5gg(c, d, a, b, x[i + 11], 14, 643717713);
|
|
97
|
+
b = this.md5gg(b, c, d, a, x[i], 20, -373897302);
|
|
98
|
+
a = this.md5gg(a, b, c, d, x[i + 5], 5, -701558691);
|
|
99
|
+
d = this.md5gg(d, a, b, c, x[i + 10], 9, 38016083);
|
|
100
|
+
c = this.md5gg(c, d, a, b, x[i + 15], 14, -660478335);
|
|
101
|
+
b = this.md5gg(b, c, d, a, x[i + 4], 20, -405537848);
|
|
102
|
+
a = this.md5gg(a, b, c, d, x[i + 9], 5, 568446438);
|
|
103
|
+
d = this.md5gg(d, a, b, c, x[i + 14], 9, -1019803690);
|
|
104
|
+
c = this.md5gg(c, d, a, b, x[i + 3], 14, -187363961);
|
|
105
|
+
b = this.md5gg(b, c, d, a, x[i + 8], 20, 1163531501);
|
|
106
|
+
a = this.md5gg(a, b, c, d, x[i + 13], 5, -1444681467);
|
|
107
|
+
d = this.md5gg(d, a, b, c, x[i + 2], 9, -51403784);
|
|
108
|
+
c = this.md5gg(c, d, a, b, x[i + 7], 14, 1735328473);
|
|
109
|
+
b = this.md5gg(b, c, d, a, x[i + 12], 20, -1926607734);
|
|
110
|
+
|
|
111
|
+
a = this.md5hh(a, b, c, d, x[i + 5], 4, -378558);
|
|
112
|
+
d = this.md5hh(d, a, b, c, x[i + 8], 11, -2022574463);
|
|
113
|
+
c = this.md5hh(c, d, a, b, x[i + 11], 16, 1839030562);
|
|
114
|
+
b = this.md5hh(b, c, d, a, x[i + 14], 23, -35309556);
|
|
115
|
+
a = this.md5hh(a, b, c, d, x[i + 1], 4, -1530992060);
|
|
116
|
+
d = this.md5hh(d, a, b, c, x[i + 4], 11, 1272893353);
|
|
117
|
+
c = this.md5hh(c, d, a, b, x[i + 7], 16, -155497632);
|
|
118
|
+
b = this.md5hh(b, c, d, a, x[i + 10], 23, -1094730640);
|
|
119
|
+
a = this.md5hh(a, b, c, d, x[i + 13], 4, 681279174);
|
|
120
|
+
d = this.md5hh(d, a, b, c, x[i], 11, -358537222);
|
|
121
|
+
c = this.md5hh(c, d, a, b, x[i + 3], 16, -722521979);
|
|
122
|
+
b = this.md5hh(b, c, d, a, x[i + 6], 23, 76029189);
|
|
123
|
+
a = this.md5hh(a, b, c, d, x[i + 9], 4, -640364487);
|
|
124
|
+
d = this.md5hh(d, a, b, c, x[i + 12], 11, -421815835);
|
|
125
|
+
c = this.md5hh(c, d, a, b, x[i + 15], 16, 530742520);
|
|
126
|
+
b = this.md5hh(b, c, d, a, x[i + 2], 23, -995338651);
|
|
127
|
+
|
|
128
|
+
a = this.md5ii(a, b, c, d, x[i], 6, -198630844);
|
|
129
|
+
d = this.md5ii(d, a, b, c, x[i + 7], 10, 1126891415);
|
|
130
|
+
c = this.md5ii(c, d, a, b, x[i + 14], 15, -1416354905);
|
|
131
|
+
b = this.md5ii(b, c, d, a, x[i + 5], 21, -57434055);
|
|
132
|
+
a = this.md5ii(a, b, c, d, x[i + 12], 6, 1700485571);
|
|
133
|
+
d = this.md5ii(d, a, b, c, x[i + 3], 10, -1894986606);
|
|
134
|
+
c = this.md5ii(c, d, a, b, x[i + 10], 15, -1051523);
|
|
135
|
+
b = this.md5ii(b, c, d, a, x[i + 1], 21, -2054922799);
|
|
136
|
+
a = this.md5ii(a, b, c, d, x[i + 8], 6, 1873313359);
|
|
137
|
+
d = this.md5ii(d, a, b, c, x[i + 15], 10, -30611744);
|
|
138
|
+
c = this.md5ii(c, d, a, b, x[i + 6], 15, -1560198380);
|
|
139
|
+
b = this.md5ii(b, c, d, a, x[i + 13], 21, 1309151649);
|
|
140
|
+
a = this.md5ii(a, b, c, d, x[i + 4], 6, -145523070);
|
|
141
|
+
d = this.md5ii(d, a, b, c, x[i + 11], 10, -1120210379);
|
|
142
|
+
c = this.md5ii(c, d, a, b, x[i + 2], 15, 718787259);
|
|
143
|
+
b = this.md5ii(b, c, d, a, x[i + 9], 21, -343485551);
|
|
144
|
+
|
|
145
|
+
a = this.safeAdd(a, olda);
|
|
146
|
+
b = this.safeAdd(b, oldb);
|
|
147
|
+
c = this.safeAdd(c, oldc);
|
|
148
|
+
d = this.safeAdd(d, oldd);
|
|
149
|
+
}
|
|
150
|
+
return [a, b, c, d];
|
|
151
|
+
},
|
|
152
|
+
binl2rstr(input) {
|
|
153
|
+
var i;
|
|
154
|
+
var output = '';
|
|
155
|
+
var length32 = input.length * 32;
|
|
156
|
+
for (i = 0; i < length32; i += 8) {
|
|
157
|
+
output += String.fromCharCode((input[i >> 5] >>> i % 32) & 0xff);
|
|
158
|
+
}
|
|
159
|
+
return output;
|
|
160
|
+
},
|
|
161
|
+
rstr2binl(input) {
|
|
162
|
+
var i;
|
|
163
|
+
var output = [];
|
|
164
|
+
output[(input.length >> 2) - 1] = undefined;
|
|
165
|
+
for (i = 0; i < output.length; i += 1) {
|
|
166
|
+
output[i] = 0;
|
|
167
|
+
}
|
|
168
|
+
var length8 = input.length * 8;
|
|
169
|
+
for (i = 0; i < length8; i += 8) {
|
|
170
|
+
output[i >> 5] |= (input.charCodeAt(i / 8) & 0xff) << i % 32;
|
|
171
|
+
}
|
|
172
|
+
return output;
|
|
173
|
+
},
|
|
174
|
+
rstrMD5(s) {
|
|
175
|
+
return this.binl2rstr(this.binlMD5(this.rstr2binl(s), s.length * 8));
|
|
176
|
+
},
|
|
177
|
+
rstrHMACMD5(key, data) {
|
|
178
|
+
var i;
|
|
179
|
+
var bkey = this.rstr2binl(key);
|
|
180
|
+
var ipad = [];
|
|
181
|
+
var opad = [];
|
|
182
|
+
var hash;
|
|
183
|
+
ipad[15] = opad[15] = undefined;
|
|
184
|
+
if (bkey.length > 16) {
|
|
185
|
+
bkey = this.binlMD5(bkey, key.length * 8);
|
|
186
|
+
}
|
|
187
|
+
for (i = 0; i < 16; i += 1) {
|
|
188
|
+
ipad[i] = bkey[i] ^ 0x36363636;
|
|
189
|
+
opad[i] = bkey[i] ^ 0x5c5c5c5c;
|
|
190
|
+
}
|
|
191
|
+
hash = this.binlMD5(ipad.concat(this.rstr2binl(data)), 512 + data.length * 8);
|
|
192
|
+
return this.binl2rstr(this.binlMD5(opad.concat(hash), 512 + 128));
|
|
193
|
+
},
|
|
194
|
+
rstr2hex(input) {
|
|
195
|
+
var hexTab = '0123456789abcdef';
|
|
196
|
+
var output = '';
|
|
197
|
+
var x;
|
|
198
|
+
var i;
|
|
199
|
+
for (i = 0; i < input.length; i += 1) {
|
|
200
|
+
x = input.charCodeAt(i);
|
|
201
|
+
output += hexTab.charAt((x >>> 4) & 0x0f) + hexTab.charAt(x & 0x0f);
|
|
202
|
+
}
|
|
203
|
+
return output;
|
|
204
|
+
},
|
|
205
|
+
str2rstrUTF8(input) {
|
|
206
|
+
return unescape(encodeURIComponent(input));
|
|
207
|
+
},
|
|
208
|
+
rawMD5(s) {
|
|
209
|
+
return this.rstrMD5(this.str2rstrUTF8(s));
|
|
210
|
+
},
|
|
211
|
+
hexMD5(s) {
|
|
212
|
+
return this.rstr2hex(this.rawMD5(s));
|
|
213
|
+
},
|
|
214
|
+
rawHMACMD5(k, d) {
|
|
215
|
+
return this.rstrHMACMD5(this.str2rstrUTF8(k), str2rstrUTF8(d));
|
|
216
|
+
},
|
|
217
|
+
hexHMACMD5(k, d) {
|
|
218
|
+
return this.rstr2hex(this.rawHMACMD5(k, d));
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
md5(string, key, raw) {
|
|
222
|
+
if (!key) {
|
|
223
|
+
if (!raw) {
|
|
224
|
+
return this.hexMD5(string);
|
|
225
|
+
}
|
|
226
|
+
return this.rawMD5(string);
|
|
227
|
+
}
|
|
228
|
+
if (!raw) {
|
|
229
|
+
return this.hexHMACMD5(key, string);
|
|
230
|
+
}
|
|
231
|
+
return this.rawHMACMD5(key, string);
|
|
232
|
+
},
|
|
233
|
+
/**
|
|
234
|
+
* 得到md5加密后的sig参数
|
|
235
|
+
* @param {Object} requestParam 接口参数
|
|
236
|
+
* @param {String} sk签名字符串
|
|
237
|
+
* @param {String} featrue 方法名
|
|
238
|
+
* @return 返回加密后的sig参数
|
|
239
|
+
*/
|
|
240
|
+
getSig(requestParam, sk, feature, mode) {
|
|
241
|
+
var sig = null;
|
|
242
|
+
var requestArr = [];
|
|
243
|
+
Object.keys(requestParam)
|
|
244
|
+
.sort()
|
|
245
|
+
.forEach(function (key) {
|
|
246
|
+
requestArr.push(key + '=' + requestParam[key]);
|
|
247
|
+
});
|
|
248
|
+
if (feature == 'search') {
|
|
249
|
+
sig = '/ws/place/v1/search?' + requestArr.join('&') + sk;
|
|
250
|
+
}
|
|
251
|
+
if (feature == 'suggest') {
|
|
252
|
+
sig = '/ws/place/v1/suggestion?' + requestArr.join('&') + sk;
|
|
253
|
+
}
|
|
254
|
+
if (feature == 'reverseGeocoder') {
|
|
255
|
+
sig = '/ws/geocoder/v1/?' + requestArr.join('&') + sk;
|
|
256
|
+
}
|
|
257
|
+
if (feature == 'geocoder') {
|
|
258
|
+
sig = '/ws/geocoder/v1/?' + requestArr.join('&') + sk;
|
|
259
|
+
}
|
|
260
|
+
if (feature == 'getCityList') {
|
|
261
|
+
sig = '/ws/district/v1/list?' + requestArr.join('&') + sk;
|
|
262
|
+
}
|
|
263
|
+
if (feature == 'getDistrictByCityId') {
|
|
264
|
+
sig = '/ws/district/v1/getchildren?' + requestArr.join('&') + sk;
|
|
265
|
+
}
|
|
266
|
+
if (feature == 'calculateDistance') {
|
|
267
|
+
sig = '/ws/distance/v1/?' + requestArr.join('&') + sk;
|
|
268
|
+
}
|
|
269
|
+
if (feature == 'direction') {
|
|
270
|
+
sig = '/ws/direction/v1/' + mode + '?' + requestArr.join('&') + sk;
|
|
271
|
+
}
|
|
272
|
+
sig = this.md5(sig);
|
|
273
|
+
return sig;
|
|
274
|
+
},
|
|
275
|
+
/**
|
|
276
|
+
* 得到终点query字符串
|
|
277
|
+
* @param {Array|String} 检索数据
|
|
278
|
+
*/
|
|
279
|
+
location2query(data) {
|
|
280
|
+
if (typeof data == 'string') {
|
|
281
|
+
return data;
|
|
282
|
+
}
|
|
283
|
+
var query = '';
|
|
284
|
+
for (var i = 0; i < data.length; i++) {
|
|
285
|
+
var d = data[i];
|
|
286
|
+
if (!!query) {
|
|
287
|
+
query += ';';
|
|
288
|
+
}
|
|
289
|
+
if (d.location) {
|
|
290
|
+
query = query + d.location.lat + ',' + d.location.lng;
|
|
291
|
+
}
|
|
292
|
+
if (d.latitude && d.longitude) {
|
|
293
|
+
query = query + d.latitude + ',' + d.longitude;
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
return query;
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* 计算角度
|
|
301
|
+
*/
|
|
302
|
+
rad(d) {
|
|
303
|
+
return (d * Math.PI) / 180.0;
|
|
304
|
+
},
|
|
305
|
+
/**
|
|
306
|
+
* 处理终点location数组
|
|
307
|
+
* @return 返回终点数组
|
|
308
|
+
*/
|
|
309
|
+
getEndLocation(location) {
|
|
310
|
+
var to = location.split(';');
|
|
311
|
+
var endLocation = [];
|
|
312
|
+
for (var i = 0; i < to.length; i++) {
|
|
313
|
+
endLocation.push({
|
|
314
|
+
lat: parseFloat(to[i].split(',')[0]),
|
|
315
|
+
lng: parseFloat(to[i].split(',')[1])
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
return endLocation;
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* 计算两点间直线距离
|
|
323
|
+
* @param a 表示纬度差
|
|
324
|
+
* @param b 表示经度差
|
|
325
|
+
* @return 返回的是距离,单位m
|
|
326
|
+
*/
|
|
327
|
+
getDistance(latFrom, lngFrom, latTo, lngTo) {
|
|
328
|
+
var radLatFrom = this.rad(latFrom);
|
|
329
|
+
var radLatTo = this.rad(latTo);
|
|
330
|
+
var a = radLatFrom - radLatTo;
|
|
331
|
+
var b = this.rad(lngFrom) - this.rad(lngTo);
|
|
332
|
+
var distance =
|
|
333
|
+
2 *
|
|
334
|
+
Math.asin(
|
|
335
|
+
Math.sqrt(Math.pow(Math.sin(a / 2), 2) + Math.cos(radLatFrom) * Math.cos(radLatTo) * Math.pow(Math.sin(b / 2), 2))
|
|
336
|
+
);
|
|
337
|
+
distance = distance * EARTH_RADIUS;
|
|
338
|
+
distance = Math.round(distance * 10000) / 10000;
|
|
339
|
+
return parseFloat(distance.toFixed(0));
|
|
340
|
+
},
|
|
341
|
+
/**
|
|
342
|
+
* 使用微信接口进行定位
|
|
343
|
+
*/
|
|
344
|
+
getWXLocation(success, fail, complete) {
|
|
345
|
+
wx.getLocation({
|
|
346
|
+
type: 'gcj02',
|
|
347
|
+
success: success,
|
|
348
|
+
fail: fail,
|
|
349
|
+
complete: complete
|
|
350
|
+
});
|
|
351
|
+
},
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 获取location参数
|
|
355
|
+
*/
|
|
356
|
+
getLocationParam(location) {
|
|
357
|
+
if (typeof location == 'string') {
|
|
358
|
+
var locationArr = location.split(',');
|
|
359
|
+
if (locationArr.length === 2) {
|
|
360
|
+
location = {
|
|
361
|
+
latitude: location.split(',')[0],
|
|
362
|
+
longitude: location.split(',')[1]
|
|
363
|
+
};
|
|
364
|
+
} else {
|
|
365
|
+
location = {};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return location;
|
|
369
|
+
},
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* 回调函数默认处理
|
|
373
|
+
*/
|
|
374
|
+
polyfillParam(param) {
|
|
375
|
+
param.success = param.success || function () {};
|
|
376
|
+
param.fail = param.fail || function () {};
|
|
377
|
+
param.complete = param.complete || function () {};
|
|
378
|
+
},
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* 验证param对应的key值是否为空
|
|
382
|
+
*
|
|
383
|
+
* @param {Object} param 接口参数
|
|
384
|
+
* @param {String} key 对应参数的key
|
|
385
|
+
*/
|
|
386
|
+
checkParamKeyEmpty(param, key) {
|
|
387
|
+
if (!param[key]) {
|
|
388
|
+
var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + key + '参数格式有误');
|
|
389
|
+
param.fail(errconf);
|
|
390
|
+
param.complete(errconf);
|
|
391
|
+
return true;
|
|
392
|
+
}
|
|
393
|
+
return false;
|
|
394
|
+
},
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* 验证参数中是否存在检索词keyword
|
|
398
|
+
*
|
|
399
|
+
* @param {Object} param 接口参数
|
|
400
|
+
*/
|
|
401
|
+
checkKeyword(param) {
|
|
402
|
+
return !this.checkParamKeyEmpty(param, 'keyword');
|
|
403
|
+
},
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* 验证location值
|
|
407
|
+
*
|
|
408
|
+
* @param {Object} param 接口参数
|
|
409
|
+
*/
|
|
410
|
+
checkLocation(param) {
|
|
411
|
+
var location = this.getLocationParam(param.location);
|
|
412
|
+
if (!location || !location.latitude || !location.longitude) {
|
|
413
|
+
var errconf = this.buildErrorConfig(ERROR_CONF.PARAM_ERR, ERROR_CONF.PARAM_ERR_MSG + ' location参数格式有误');
|
|
414
|
+
param.fail(errconf);
|
|
415
|
+
param.complete(errconf);
|
|
416
|
+
return false;
|
|
417
|
+
}
|
|
418
|
+
return true;
|
|
419
|
+
},
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* 构造错误数据结构
|
|
423
|
+
* @param {Number} errCode 错误码
|
|
424
|
+
* @param {Number} errMsg 错误描述
|
|
425
|
+
*/
|
|
426
|
+
buildErrorConfig(errCode, errMsg) {
|
|
427
|
+
return { status: errCode, message: errMsg };
|
|
428
|
+
},
|
|
429
|
+
|
|
430
|
+
/**
|
|
431
|
+
*
|
|
432
|
+
* 数据处理函数
|
|
433
|
+
* 根据传入参数不同处理不同数据
|
|
434
|
+
* @param {String} feature 功能名称
|
|
435
|
+
* search 地点搜索
|
|
436
|
+
* suggest关键词提示
|
|
437
|
+
* reverseGeocoder逆地址解析
|
|
438
|
+
* geocoder地址解析
|
|
439
|
+
* getCityList获取城市列表:父集
|
|
440
|
+
* getDistrictByCityId获取区县列表:子集
|
|
441
|
+
* calculateDistance距离计算
|
|
442
|
+
* @param {Object} param 接口参数
|
|
443
|
+
* @param {Object} data 数据
|
|
444
|
+
*/
|
|
445
|
+
handleData(param, data, feature) {
|
|
446
|
+
if (feature == 'search') {
|
|
447
|
+
var searchResult = data.data;
|
|
448
|
+
var searchSimplify = [];
|
|
449
|
+
for (var i = 0; i < searchResult.length; i++) {
|
|
450
|
+
searchSimplify.push({
|
|
451
|
+
id: searchResult[i].id || null,
|
|
452
|
+
title: searchResult[i].title || null,
|
|
453
|
+
latitude: (searchResult[i].location && searchResult[i].location.lat) || null,
|
|
454
|
+
longitude: (searchResult[i].location && searchResult[i].location.lng) || null,
|
|
455
|
+
address: searchResult[i].address || null,
|
|
456
|
+
category: searchResult[i].category || null,
|
|
457
|
+
tel: searchResult[i].tel || null,
|
|
458
|
+
adcode: (searchResult[i].ad_info && searchResult[i].ad_info.adcode) || null,
|
|
459
|
+
city: (searchResult[i].ad_info && searchResult[i].ad_info.city) || null,
|
|
460
|
+
district: (searchResult[i].ad_info && searchResult[i].ad_info.district) || null,
|
|
461
|
+
province: (searchResult[i].ad_info && searchResult[i].ad_info.province) || null
|
|
462
|
+
});
|
|
463
|
+
}
|
|
464
|
+
param.success(data, {
|
|
465
|
+
searchResult: searchResult,
|
|
466
|
+
searchSimplify: searchSimplify
|
|
467
|
+
});
|
|
468
|
+
} else if (feature == 'suggest') {
|
|
469
|
+
var suggestResult = data.data;
|
|
470
|
+
var suggestSimplify = [];
|
|
471
|
+
for (var i = 0; i < suggestResult.length; i++) {
|
|
472
|
+
suggestSimplify.push({
|
|
473
|
+
adcode: suggestResult[i].adcode || null,
|
|
474
|
+
address: suggestResult[i].address || null,
|
|
475
|
+
category: suggestResult[i].category || null,
|
|
476
|
+
city: suggestResult[i].city || null,
|
|
477
|
+
district: suggestResult[i].district || null,
|
|
478
|
+
id: suggestResult[i].id || null,
|
|
479
|
+
latitude: (suggestResult[i].location && suggestResult[i].location.lat) || null,
|
|
480
|
+
longitude: (suggestResult[i].location && suggestResult[i].location.lng) || null,
|
|
481
|
+
province: suggestResult[i].province || null,
|
|
482
|
+
title: suggestResult[i].title || null,
|
|
483
|
+
type: suggestResult[i].type || null
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
param.success(data, {
|
|
487
|
+
suggestResult: suggestResult,
|
|
488
|
+
suggestSimplify: suggestSimplify
|
|
489
|
+
});
|
|
490
|
+
} else if (feature == 'reverseGeocoder') {
|
|
491
|
+
var reverseGeocoderResult = data.result;
|
|
492
|
+
var reverseGeocoderSimplify = {
|
|
493
|
+
address: reverseGeocoderResult.address || null,
|
|
494
|
+
latitude: (reverseGeocoderResult.location && reverseGeocoderResult.location.lat) || null,
|
|
495
|
+
longitude: (reverseGeocoderResult.location && reverseGeocoderResult.location.lng) || null,
|
|
496
|
+
adcode: (reverseGeocoderResult.ad_info && reverseGeocoderResult.ad_info.adcode) || null,
|
|
497
|
+
city: (reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.city) || null,
|
|
498
|
+
district: (reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.district) || null,
|
|
499
|
+
nation: (reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.nation) || null,
|
|
500
|
+
province: (reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.province) || null,
|
|
501
|
+
street: (reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street) || null,
|
|
502
|
+
street_number: (reverseGeocoderResult.address_component && reverseGeocoderResult.address_component.street_number) || null,
|
|
503
|
+
recommend: (reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.recommend) || null,
|
|
504
|
+
rough: (reverseGeocoderResult.formatted_addresses && reverseGeocoderResult.formatted_addresses.rough) || null
|
|
505
|
+
};
|
|
506
|
+
if (reverseGeocoderResult.pois) {
|
|
507
|
+
//判断是否返回周边poi
|
|
508
|
+
var pois = reverseGeocoderResult.pois;
|
|
509
|
+
var poisSimplify = [];
|
|
510
|
+
for (var i = 0; i < pois.length; i++) {
|
|
511
|
+
poisSimplify.push({
|
|
512
|
+
id: pois[i].id || null,
|
|
513
|
+
title: pois[i].title || null,
|
|
514
|
+
latitude: (pois[i].location && pois[i].location.lat) || null,
|
|
515
|
+
longitude: (pois[i].location && pois[i].location.lng) || null,
|
|
516
|
+
address: pois[i].address || null,
|
|
517
|
+
category: pois[i].category || null,
|
|
518
|
+
adcode: (pois[i].ad_info && pois[i].ad_info.adcode) || null,
|
|
519
|
+
city: (pois[i].ad_info && pois[i].ad_info.city) || null,
|
|
520
|
+
district: (pois[i].ad_info && pois[i].ad_info.district) || null,
|
|
521
|
+
province: (pois[i].ad_info && pois[i].ad_info.province) || null
|
|
522
|
+
});
|
|
523
|
+
}
|
|
524
|
+
param.success(data, {
|
|
525
|
+
reverseGeocoderResult: reverseGeocoderResult,
|
|
526
|
+
reverseGeocoderSimplify: reverseGeocoderSimplify,
|
|
527
|
+
pois: pois,
|
|
528
|
+
poisSimplify: poisSimplify
|
|
529
|
+
});
|
|
530
|
+
} else {
|
|
531
|
+
param.success(data, {
|
|
532
|
+
reverseGeocoderResult: reverseGeocoderResult,
|
|
533
|
+
reverseGeocoderSimplify: reverseGeocoderSimplify
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
} else if (feature == 'geocoder') {
|
|
537
|
+
var geocoderResult = data.result;
|
|
538
|
+
var geocoderSimplify = {
|
|
539
|
+
title: geocoderResult.title || null,
|
|
540
|
+
latitude: (geocoderResult.location && geocoderResult.location.lat) || null,
|
|
541
|
+
longitude: (geocoderResult.location && geocoderResult.location.lng) || null,
|
|
542
|
+
adcode: (geocoderResult.ad_info && geocoderResult.ad_info.adcode) || null,
|
|
543
|
+
province: (geocoderResult.address_components && geocoderResult.address_components.province) || null,
|
|
544
|
+
city: (geocoderResult.address_components && geocoderResult.address_components.city) || null,
|
|
545
|
+
district: (geocoderResult.address_components && geocoderResult.address_components.district) || null,
|
|
546
|
+
street: (geocoderResult.address_components && geocoderResult.address_components.street) || null,
|
|
547
|
+
street_number: (geocoderResult.address_components && geocoderResult.address_components.street_number) || null,
|
|
548
|
+
level: geocoderResult.level || null
|
|
549
|
+
};
|
|
550
|
+
param.success(data, {
|
|
551
|
+
geocoderResult: geocoderResult,
|
|
552
|
+
geocoderSimplify: geocoderSimplify
|
|
553
|
+
});
|
|
554
|
+
} else if (feature == 'getCityList') {
|
|
555
|
+
var provinceResult = data.result[0];
|
|
556
|
+
var cityResult = data.result[1];
|
|
557
|
+
var districtResult = data.result[2];
|
|
558
|
+
param.success(data, {
|
|
559
|
+
provinceResult: provinceResult,
|
|
560
|
+
cityResult: cityResult,
|
|
561
|
+
districtResult: districtResult
|
|
562
|
+
});
|
|
563
|
+
} else if (feature == 'getDistrictByCityId') {
|
|
564
|
+
var districtByCity = data.result[0];
|
|
565
|
+
param.success(data, districtByCity);
|
|
566
|
+
} else if (feature == 'calculateDistance') {
|
|
567
|
+
var calculateDistanceResult = data.result.elements;
|
|
568
|
+
var distance = [];
|
|
569
|
+
for (var i = 0; i < calculateDistanceResult.length; i++) {
|
|
570
|
+
distance.push(calculateDistanceResult[i].distance);
|
|
571
|
+
}
|
|
572
|
+
param.success(data, {
|
|
573
|
+
calculateDistanceResult: calculateDistanceResult,
|
|
574
|
+
distance: distance
|
|
575
|
+
});
|
|
576
|
+
} else if (feature == 'direction') {
|
|
577
|
+
var direction = data.result.routes;
|
|
578
|
+
param.success(data, direction);
|
|
579
|
+
} else {
|
|
580
|
+
param.success(data);
|
|
581
|
+
}
|
|
582
|
+
},
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* 构造微信请求参数,公共属性处理
|
|
586
|
+
*
|
|
587
|
+
* @param {Object} param 接口参数
|
|
588
|
+
* @param {Object} param 配置项
|
|
589
|
+
* @param {String} feature 方法名
|
|
590
|
+
*/
|
|
591
|
+
buildWxRequestConfig(param, options, feature) {
|
|
592
|
+
var that = this;
|
|
593
|
+
options.header = { 'content-type': 'application/json' };
|
|
594
|
+
options.method = 'GET';
|
|
595
|
+
options.success = function (res) {
|
|
596
|
+
var data = res.data;
|
|
597
|
+
if (data.status === 0) {
|
|
598
|
+
that.handleData(param, data, feature);
|
|
599
|
+
} else {
|
|
600
|
+
param.fail(data);
|
|
601
|
+
}
|
|
602
|
+
};
|
|
603
|
+
options.fail = function (res) {
|
|
604
|
+
res.statusCode = ERROR_CONF.WX_ERR_CODE;
|
|
605
|
+
param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
|
|
606
|
+
};
|
|
607
|
+
options.complete = function (res) {
|
|
608
|
+
var statusCode = +res.statusCode;
|
|
609
|
+
switch (statusCode) {
|
|
610
|
+
case ERROR_CONF.WX_ERR_CODE: {
|
|
611
|
+
param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
|
|
612
|
+
break;
|
|
613
|
+
}
|
|
614
|
+
case ERROR_CONF.WX_OK_CODE: {
|
|
615
|
+
var data = res.data;
|
|
616
|
+
if (data.status === 0) {
|
|
617
|
+
param.complete(data);
|
|
618
|
+
} else {
|
|
619
|
+
param.complete(that.buildErrorConfig(data.status, data.message));
|
|
620
|
+
}
|
|
621
|
+
break;
|
|
622
|
+
}
|
|
623
|
+
default: {
|
|
624
|
+
param.complete(that.buildErrorConfig(ERROR_CONF.SYSTEM_ERR, ERROR_CONF.SYSTEM_ERR_MSG));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
};
|
|
628
|
+
return options;
|
|
629
|
+
},
|
|
630
|
+
|
|
631
|
+
/**
|
|
632
|
+
* 处理用户参数是否传入坐标进行不同的处理
|
|
633
|
+
*/
|
|
634
|
+
locationProcess(param, locationsuccess, locationfail, locationcomplete) {
|
|
635
|
+
var that = this;
|
|
636
|
+
locationfail =
|
|
637
|
+
locationfail ||
|
|
638
|
+
function (res) {
|
|
639
|
+
res.statusCode = ERROR_CONF.WX_ERR_CODE;
|
|
640
|
+
param.fail(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
|
|
641
|
+
};
|
|
642
|
+
locationcomplete =
|
|
643
|
+
locationcomplete ||
|
|
644
|
+
function (res) {
|
|
645
|
+
if (res.statusCode == ERROR_CONF.WX_ERR_CODE) {
|
|
646
|
+
param.complete(that.buildErrorConfig(ERROR_CONF.WX_ERR_CODE, res.errMsg));
|
|
647
|
+
}
|
|
648
|
+
};
|
|
649
|
+
if (!param.location) {
|
|
650
|
+
that.getWXLocation(locationsuccess, locationfail, locationcomplete);
|
|
651
|
+
} else if (that.checkLocation(param)) {
|
|
652
|
+
var location = Utils.getLocationParam(param.location);
|
|
653
|
+
locationsuccess(location);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
class QQMapWX {
|
|
659
|
+
/**
|
|
660
|
+
* 构造函数
|
|
661
|
+
*
|
|
662
|
+
* @param {Object} options 接口参数,key 为必选参数
|
|
663
|
+
*/
|
|
664
|
+
constructor(options) {
|
|
665
|
+
if (!options.key) {
|
|
666
|
+
throw Error('key值不能为空');
|
|
667
|
+
}
|
|
668
|
+
this.key = options.key;
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
/**
|
|
672
|
+
* POI周边检索
|
|
673
|
+
*
|
|
674
|
+
* @param {Object} options 接口参数对象
|
|
675
|
+
*
|
|
676
|
+
* 参数对象结构可以参考
|
|
677
|
+
* @see http://lbs.qq.com/webservice_v1/guide-search.html
|
|
678
|
+
*/
|
|
679
|
+
search(options) {
|
|
680
|
+
var that = this;
|
|
681
|
+
options = options || {};
|
|
682
|
+
|
|
683
|
+
Utils.polyfillParam(options);
|
|
684
|
+
|
|
685
|
+
if (!Utils.checkKeyword(options)) {
|
|
686
|
+
return;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
var requestParam = {
|
|
690
|
+
keyword: options.keyword,
|
|
691
|
+
orderby: options.orderby || '_distance',
|
|
692
|
+
page_size: options.page_size || 10,
|
|
693
|
+
page_index: options.page_index || 1,
|
|
694
|
+
output: 'json',
|
|
695
|
+
key: that.key
|
|
696
|
+
};
|
|
697
|
+
|
|
698
|
+
if (options.address_format) {
|
|
699
|
+
requestParam.address_format = options.address_format;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
if (options.filter) {
|
|
703
|
+
requestParam.filter = options.filter;
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
var distance = options.distance || '1000';
|
|
707
|
+
var auto_extend = options.auto_extend || 1;
|
|
708
|
+
var region = null;
|
|
709
|
+
var rectangle = null;
|
|
710
|
+
|
|
711
|
+
//判断城市限定参数
|
|
712
|
+
if (options.region) {
|
|
713
|
+
region = options.region;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
//矩形限定坐标(暂时只支持字符串格式)
|
|
717
|
+
if (options.rectangle) {
|
|
718
|
+
rectangle = options.rectangle;
|
|
719
|
+
}
|
|
720
|
+
|
|
721
|
+
var locationsuccess = function (result) {
|
|
722
|
+
if (region && !rectangle) {
|
|
723
|
+
//城市限定参数拼接
|
|
724
|
+
requestParam.boundary = 'region(' + region + ',' + auto_extend + ',' + result.latitude + ',' + result.longitude + ')';
|
|
725
|
+
if (options.sig) {
|
|
726
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'search');
|
|
727
|
+
}
|
|
728
|
+
} else if (rectangle && !region) {
|
|
729
|
+
//矩形搜索
|
|
730
|
+
requestParam.boundary = 'rectangle(' + rectangle + ')';
|
|
731
|
+
if (options.sig) {
|
|
732
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'search');
|
|
733
|
+
}
|
|
734
|
+
} else {
|
|
735
|
+
requestParam.boundary = 'nearby(' + result.latitude + ',' + result.longitude + ',' + distance + ',' + auto_extend + ')';
|
|
736
|
+
if (options.sig) {
|
|
737
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'search');
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
wx.request(
|
|
741
|
+
Utils.buildWxRequestConfig(
|
|
742
|
+
options,
|
|
743
|
+
{
|
|
744
|
+
url: URL_SEARCH,
|
|
745
|
+
data: requestParam
|
|
746
|
+
},
|
|
747
|
+
'search'
|
|
748
|
+
)
|
|
749
|
+
);
|
|
750
|
+
};
|
|
751
|
+
Utils.locationProcess(options, locationsuccess);
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
/**
|
|
755
|
+
* sug模糊检索
|
|
756
|
+
*
|
|
757
|
+
* @param {Object} options 接口参数对象
|
|
758
|
+
*
|
|
759
|
+
* 参数对象结构可以参考
|
|
760
|
+
* http://lbs.qq.com/webservice_v1/guide-suggestion.html
|
|
761
|
+
*/
|
|
762
|
+
getSuggestion(options) {
|
|
763
|
+
var that = this;
|
|
764
|
+
options = options || {};
|
|
765
|
+
Utils.polyfillParam(options);
|
|
766
|
+
|
|
767
|
+
if (!Utils.checkKeyword(options)) {
|
|
768
|
+
return;
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
var requestParam = {
|
|
772
|
+
keyword: options.keyword,
|
|
773
|
+
region: options.region || '全国',
|
|
774
|
+
region_fix: options.region_fix || 0,
|
|
775
|
+
policy: options.policy || 0,
|
|
776
|
+
page_size: options.page_size || 10, //控制显示条数
|
|
777
|
+
page_index: options.page_index || 1, //控制页数
|
|
778
|
+
get_subpois: options.get_subpois || 0, //返回子地点
|
|
779
|
+
output: 'json',
|
|
780
|
+
key: that.key
|
|
781
|
+
};
|
|
782
|
+
//长地址
|
|
783
|
+
if (options.address_format) {
|
|
784
|
+
requestParam.address_format = options.address_format;
|
|
785
|
+
}
|
|
786
|
+
//过滤
|
|
787
|
+
if (options.filter) {
|
|
788
|
+
requestParam.filter = options.filter;
|
|
789
|
+
}
|
|
790
|
+
//排序
|
|
791
|
+
if (options.location) {
|
|
792
|
+
var locationsuccess = function (result) {
|
|
793
|
+
requestParam.location = result.latitude + ',' + result.longitude;
|
|
794
|
+
if (options.sig) {
|
|
795
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'suggest');
|
|
796
|
+
}
|
|
797
|
+
wx.request(
|
|
798
|
+
Utils.buildWxRequestConfig(
|
|
799
|
+
options,
|
|
800
|
+
{
|
|
801
|
+
url: URL_SUGGESTION,
|
|
802
|
+
data: requestParam
|
|
803
|
+
},
|
|
804
|
+
'suggest'
|
|
805
|
+
)
|
|
806
|
+
);
|
|
807
|
+
};
|
|
808
|
+
Utils.locationProcess(options, locationsuccess);
|
|
809
|
+
} else {
|
|
810
|
+
if (options.sig) {
|
|
811
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'suggest');
|
|
812
|
+
}
|
|
813
|
+
wx.request(
|
|
814
|
+
Utils.buildWxRequestConfig(
|
|
815
|
+
options,
|
|
816
|
+
{
|
|
817
|
+
url: URL_SUGGESTION,
|
|
818
|
+
data: requestParam
|
|
819
|
+
},
|
|
820
|
+
'suggest'
|
|
821
|
+
)
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
/**
|
|
827
|
+
* 逆地址解析
|
|
828
|
+
*
|
|
829
|
+
* @param {Object} options 接口参数对象
|
|
830
|
+
*
|
|
831
|
+
* 请求参数结构可以参考
|
|
832
|
+
* http://lbs.qq.com/webservice_v1/guide-gcoder.html
|
|
833
|
+
*/
|
|
834
|
+
reverseGeocoder(options) {
|
|
835
|
+
var that = this;
|
|
836
|
+
options = options || {};
|
|
837
|
+
Utils.polyfillParam(options);
|
|
838
|
+
var requestParam = {
|
|
839
|
+
coord_type: options.coord_type || 5,
|
|
840
|
+
get_poi: options.get_poi || 0,
|
|
841
|
+
output: 'json',
|
|
842
|
+
key: that.key
|
|
843
|
+
};
|
|
844
|
+
if (options.poi_options) {
|
|
845
|
+
requestParam.poi_options = options.poi_options;
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
var locationsuccess = function (result) {
|
|
849
|
+
requestParam.location = result.latitude + ',' + result.longitude;
|
|
850
|
+
if (options.sig) {
|
|
851
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'reverseGeocoder');
|
|
852
|
+
}
|
|
853
|
+
wx.request(
|
|
854
|
+
Utils.buildWxRequestConfig(
|
|
855
|
+
options,
|
|
856
|
+
{
|
|
857
|
+
url: URL_GET_GEOCODER,
|
|
858
|
+
data: requestParam
|
|
859
|
+
},
|
|
860
|
+
'reverseGeocoder'
|
|
861
|
+
)
|
|
862
|
+
);
|
|
863
|
+
};
|
|
864
|
+
Utils.locationProcess(options, locationsuccess);
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
/**
|
|
868
|
+
* 地址解析
|
|
869
|
+
*
|
|
870
|
+
* @param {Object} options 接口参数对象
|
|
871
|
+
*
|
|
872
|
+
* 请求参数结构可以参考
|
|
873
|
+
* http://lbs.qq.com/webservice_v1/guide-geocoder.html
|
|
874
|
+
*/
|
|
875
|
+
geocoder(options) {
|
|
876
|
+
var that = this;
|
|
877
|
+
options = options || {};
|
|
878
|
+
Utils.polyfillParam(options);
|
|
879
|
+
|
|
880
|
+
if (Utils.checkParamKeyEmpty(options, 'address')) {
|
|
881
|
+
return;
|
|
882
|
+
}
|
|
883
|
+
|
|
884
|
+
var requestParam = {
|
|
885
|
+
address: options.address,
|
|
886
|
+
output: 'json',
|
|
887
|
+
key: that.key
|
|
888
|
+
};
|
|
889
|
+
|
|
890
|
+
//城市限定
|
|
891
|
+
if (options.region) {
|
|
892
|
+
requestParam.region = options.region;
|
|
893
|
+
}
|
|
894
|
+
|
|
895
|
+
if (options.sig) {
|
|
896
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'geocoder');
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
wx.request(
|
|
900
|
+
Utils.buildWxRequestConfig(
|
|
901
|
+
options,
|
|
902
|
+
{
|
|
903
|
+
url: URL_GET_GEOCODER,
|
|
904
|
+
data: requestParam
|
|
905
|
+
},
|
|
906
|
+
'geocoder'
|
|
907
|
+
)
|
|
908
|
+
);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
/**
|
|
912
|
+
* 获取城市列表
|
|
913
|
+
*
|
|
914
|
+
* @param {Object} options 接口参数对象
|
|
915
|
+
*
|
|
916
|
+
* 请求参数结构可以参考
|
|
917
|
+
* http://lbs.qq.com/webservice_v1/guide-region.html
|
|
918
|
+
*/
|
|
919
|
+
getCityList(options) {
|
|
920
|
+
var that = this;
|
|
921
|
+
options = options || {};
|
|
922
|
+
Utils.polyfillParam(options);
|
|
923
|
+
var requestParam = {
|
|
924
|
+
output: 'json',
|
|
925
|
+
key: that.key
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
if (options.sig) {
|
|
929
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'getCityList');
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
wx.request(
|
|
933
|
+
Utils.buildWxRequestConfig(
|
|
934
|
+
options,
|
|
935
|
+
{
|
|
936
|
+
url: URL_CITY_LIST,
|
|
937
|
+
data: requestParam
|
|
938
|
+
},
|
|
939
|
+
'getCityList'
|
|
940
|
+
)
|
|
941
|
+
);
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
/**
|
|
945
|
+
* 获取对应城市ID的区县列表
|
|
946
|
+
*
|
|
947
|
+
* @param {Object} options 接口参数对象
|
|
948
|
+
*
|
|
949
|
+
* 请求参数结构可以参考
|
|
950
|
+
* http://lbs.qq.com/webservice_v1/guide-region.html
|
|
951
|
+
*/
|
|
952
|
+
getDistrictByCityId(options) {
|
|
953
|
+
var that = this;
|
|
954
|
+
options = options || {};
|
|
955
|
+
Utils.polyfillParam(options);
|
|
956
|
+
|
|
957
|
+
if (Utils.checkParamKeyEmpty(options, 'id')) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
var requestParam = {
|
|
962
|
+
id: options.id || '',
|
|
963
|
+
output: 'json',
|
|
964
|
+
key: that.key
|
|
965
|
+
};
|
|
966
|
+
|
|
967
|
+
if (options.sig) {
|
|
968
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'getDistrictByCityId');
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
wx.request(
|
|
972
|
+
Utils.buildWxRequestConfig(
|
|
973
|
+
options,
|
|
974
|
+
{
|
|
975
|
+
url: URL_AREA_LIST,
|
|
976
|
+
data: requestParam
|
|
977
|
+
},
|
|
978
|
+
'getDistrictByCityId'
|
|
979
|
+
)
|
|
980
|
+
);
|
|
981
|
+
}
|
|
982
|
+
|
|
983
|
+
/**
|
|
984
|
+
* 用于单起点到多终点的路线距离(非直线距离)计算:
|
|
985
|
+
* 支持两种距离计算方式:步行和驾车。
|
|
986
|
+
* 起点到终点最大限制直线距离10公里。
|
|
987
|
+
*
|
|
988
|
+
* 新增直线距离计算。
|
|
989
|
+
*
|
|
990
|
+
* @param {Object} options 接口参数对象
|
|
991
|
+
*
|
|
992
|
+
* 请求参数结构可以参考
|
|
993
|
+
* http://lbs.qq.com/webservice_v1/guide-distance.html
|
|
994
|
+
*/
|
|
995
|
+
calculateDistance(options) {
|
|
996
|
+
var that = this;
|
|
997
|
+
options = options || {};
|
|
998
|
+
Utils.polyfillParam(options);
|
|
999
|
+
|
|
1000
|
+
if (Utils.checkParamKeyEmpty(options, 'to')) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
|
|
1004
|
+
var requestParam = {
|
|
1005
|
+
mode: options.mode || 'walking',
|
|
1006
|
+
to: Utils.location2query(options.to),
|
|
1007
|
+
output: 'json',
|
|
1008
|
+
key: that.key
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
if (options.from) {
|
|
1012
|
+
options.location = options.from;
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
//计算直线距离
|
|
1016
|
+
if (requestParam.mode == 'straight') {
|
|
1017
|
+
var locationsuccess = function (result) {
|
|
1018
|
+
var locationTo = Utils.getEndLocation(requestParam.to); //处理终点坐标
|
|
1019
|
+
var data = {
|
|
1020
|
+
message: 'query ok',
|
|
1021
|
+
result: {
|
|
1022
|
+
elements: []
|
|
1023
|
+
},
|
|
1024
|
+
status: 0
|
|
1025
|
+
};
|
|
1026
|
+
for (var i = 0; i < locationTo.length; i++) {
|
|
1027
|
+
data.result.elements.push({
|
|
1028
|
+
//将坐标存入
|
|
1029
|
+
distance: Utils.getDistance(result.latitude, result.longitude, locationTo[i].lat, locationTo[i].lng),
|
|
1030
|
+
duration: 0,
|
|
1031
|
+
from: {
|
|
1032
|
+
lat: result.latitude,
|
|
1033
|
+
lng: result.longitude
|
|
1034
|
+
},
|
|
1035
|
+
to: {
|
|
1036
|
+
lat: locationTo[i].lat,
|
|
1037
|
+
lng: locationTo[i].lng
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
}
|
|
1041
|
+
var calculateResult = data.result.elements;
|
|
1042
|
+
var distanceResult = [];
|
|
1043
|
+
for (var i = 0; i < calculateResult.length; i++) {
|
|
1044
|
+
distanceResult.push(calculateResult[i].distance);
|
|
1045
|
+
}
|
|
1046
|
+
return options.success(data, {
|
|
1047
|
+
calculateResult: calculateResult,
|
|
1048
|
+
distanceResult: distanceResult
|
|
1049
|
+
});
|
|
1050
|
+
};
|
|
1051
|
+
|
|
1052
|
+
Utils.locationProcess(options, locationsuccess);
|
|
1053
|
+
} else {
|
|
1054
|
+
var locationsuccess = function (result) {
|
|
1055
|
+
requestParam.from = result.latitude + ',' + result.longitude;
|
|
1056
|
+
if (options.sig) {
|
|
1057
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'calculateDistance');
|
|
1058
|
+
}
|
|
1059
|
+
wx.request(
|
|
1060
|
+
Utils.buildWxRequestConfig(
|
|
1061
|
+
options,
|
|
1062
|
+
{
|
|
1063
|
+
url: URL_DISTANCE,
|
|
1064
|
+
data: requestParam
|
|
1065
|
+
},
|
|
1066
|
+
'calculateDistance'
|
|
1067
|
+
)
|
|
1068
|
+
);
|
|
1069
|
+
};
|
|
1070
|
+
|
|
1071
|
+
Utils.locationProcess(options, locationsuccess);
|
|
1072
|
+
}
|
|
1073
|
+
}
|
|
1074
|
+
|
|
1075
|
+
/**
|
|
1076
|
+
* 路线规划:
|
|
1077
|
+
*
|
|
1078
|
+
* @param {Object} options 接口参数对象
|
|
1079
|
+
*
|
|
1080
|
+
* 请求参数结构可以参考
|
|
1081
|
+
* https://lbs.qq.com/webservice_v1/guide-road.html
|
|
1082
|
+
*/
|
|
1083
|
+
direction(options) {
|
|
1084
|
+
var that = this;
|
|
1085
|
+
options = options || {};
|
|
1086
|
+
Utils.polyfillParam(options);
|
|
1087
|
+
|
|
1088
|
+
if (Utils.checkParamKeyEmpty(options, 'to')) {
|
|
1089
|
+
return;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
var requestParam = {
|
|
1093
|
+
output: 'json',
|
|
1094
|
+
key: that.key
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
//to格式处理
|
|
1098
|
+
if (typeof options.to == 'string') {
|
|
1099
|
+
requestParam.to = options.to;
|
|
1100
|
+
} else {
|
|
1101
|
+
requestParam.to = options.to.latitude + ',' + options.to.longitude;
|
|
1102
|
+
}
|
|
1103
|
+
//初始化局部请求域名
|
|
1104
|
+
var SET_URL_DIRECTION = null;
|
|
1105
|
+
//设置默认mode属性
|
|
1106
|
+
options.mode = options.mode || MODE.driving;
|
|
1107
|
+
|
|
1108
|
+
//设置请求域名
|
|
1109
|
+
SET_URL_DIRECTION = URL_DIRECTION + options.mode;
|
|
1110
|
+
|
|
1111
|
+
if (options.from) {
|
|
1112
|
+
options.location = options.from;
|
|
1113
|
+
}
|
|
1114
|
+
|
|
1115
|
+
if (options.mode == MODE.driving) {
|
|
1116
|
+
if (options.from_poi) {
|
|
1117
|
+
requestParam.from_poi = options.from_poi;
|
|
1118
|
+
}
|
|
1119
|
+
if (options.heading) {
|
|
1120
|
+
requestParam.heading = options.heading;
|
|
1121
|
+
}
|
|
1122
|
+
if (options.speed) {
|
|
1123
|
+
requestParam.speed = options.speed;
|
|
1124
|
+
}
|
|
1125
|
+
if (options.accuracy) {
|
|
1126
|
+
requestParam.accuracy = options.accuracy;
|
|
1127
|
+
}
|
|
1128
|
+
if (options.road_type) {
|
|
1129
|
+
requestParam.road_type = options.road_type;
|
|
1130
|
+
}
|
|
1131
|
+
if (options.to_poi) {
|
|
1132
|
+
requestParam.to_poi = options.to_poi;
|
|
1133
|
+
}
|
|
1134
|
+
if (options.from_track) {
|
|
1135
|
+
requestParam.from_track = options.from_track;
|
|
1136
|
+
}
|
|
1137
|
+
if (options.waypoints) {
|
|
1138
|
+
requestParam.waypoints = options.waypoints;
|
|
1139
|
+
}
|
|
1140
|
+
if (options.policy) {
|
|
1141
|
+
requestParam.policy = options.policy;
|
|
1142
|
+
}
|
|
1143
|
+
if (options.plate_number) {
|
|
1144
|
+
requestParam.plate_number = options.plate_number;
|
|
1145
|
+
}
|
|
1146
|
+
}
|
|
1147
|
+
|
|
1148
|
+
if (options.mode == MODE.transit) {
|
|
1149
|
+
if (options.departure_time) {
|
|
1150
|
+
requestParam.departure_time = options.departure_time;
|
|
1151
|
+
}
|
|
1152
|
+
if (options.policy) {
|
|
1153
|
+
requestParam.policy = options.policy;
|
|
1154
|
+
}
|
|
1155
|
+
}
|
|
1156
|
+
|
|
1157
|
+
var locationsuccess = function (result) {
|
|
1158
|
+
requestParam.from = result.latitude + ',' + result.longitude;
|
|
1159
|
+
if (options.sig) {
|
|
1160
|
+
requestParam.sig = Utils.getSig(requestParam, options.sig, 'direction', options.mode);
|
|
1161
|
+
}
|
|
1162
|
+
wx.request(
|
|
1163
|
+
Utils.buildWxRequestConfig(
|
|
1164
|
+
options,
|
|
1165
|
+
{
|
|
1166
|
+
url: SET_URL_DIRECTION,
|
|
1167
|
+
data: requestParam
|
|
1168
|
+
},
|
|
1169
|
+
'direction'
|
|
1170
|
+
)
|
|
1171
|
+
);
|
|
1172
|
+
};
|
|
1173
|
+
|
|
1174
|
+
Utils.locationProcess(options, locationsuccess);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
|
|
1178
|
+
module.exports = QQMapWX;
|