@smart100/spu-web-plugin 1.0.12 → 1.0.13
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/dist/index.d.ts +5 -0
- package/dist/spu-web-plugin.mjs +194 -261
- package/package.json +1 -1
- package/src/index.ts +2 -1
- package/src/map/MapService.ts +38 -32
- package/src/map/index.ts +66 -41
- package/src/tenantSetting.ts +23 -5
- package/src/types/index.d.ts +5 -0
package/dist/index.d.ts
CHANGED
|
@@ -99,6 +99,11 @@ export const getLocation: () => Promise<{
|
|
|
99
99
|
[propName: string]: any
|
|
100
100
|
} | null>
|
|
101
101
|
export const getDistance: (p1: [number, number], p2: [number, number]) => Promise<any>
|
|
102
|
+
export const getAddress: (location: {
|
|
103
|
+
longitude: string
|
|
104
|
+
latitude: string
|
|
105
|
+
[propName: string]: any
|
|
106
|
+
}) => Promise<string>
|
|
102
107
|
export const spuAxios: any
|
|
103
108
|
export const apaasAxios: any
|
|
104
109
|
export const axios: any
|
package/dist/spu-web-plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var version = "1.0.
|
|
1
|
+
var version = "1.0.13";
|
|
2
2
|
|
|
3
3
|
/** Detect free variable `global` from Node.js. */
|
|
4
4
|
var freeGlobal$2 = typeof global == 'object' && global && global.Object === Object && global;
|
|
@@ -16162,11 +16162,27 @@ var TenantSetting = /*#__PURE__*/function () {
|
|
|
16162
16162
|
// }
|
|
16163
16163
|
// }
|
|
16164
16164
|
// }
|
|
16165
|
-
//
|
|
16166
|
-
//
|
|
16167
|
-
//
|
|
16168
|
-
// //
|
|
16169
|
-
// // tenantsetting.lbssetting.setting.
|
|
16165
|
+
// // 高德地图key配置错误
|
|
16166
|
+
// // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
|
|
16167
|
+
// // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
|
|
16168
|
+
// // // 高德地图公司key
|
|
16169
|
+
// // tenantsetting.lbssetting.setting.type = 'amap'
|
|
16170
|
+
// // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
|
|
16171
|
+
// // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
|
|
16172
|
+
// // // 高德地图个人key
|
|
16173
|
+
// // tenantsetting.lbssetting.setting.type = 'amap'
|
|
16174
|
+
// // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
|
|
16175
|
+
// // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
|
|
16176
|
+
// // tencent地图key配置错误
|
|
16177
|
+
// // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
|
|
16178
|
+
// // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
|
|
16179
|
+
// // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
|
|
16180
|
+
// // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
|
|
16181
|
+
// tenantsetting.lbssetting.setting.type = 'tencent'
|
|
16182
|
+
// tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
|
|
16183
|
+
// tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
|
|
16184
|
+
// // 百度地图key配置错误alert以下信息
|
|
16185
|
+
// // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
|
|
16170
16186
|
// // tenantsetting.lbssetting.setting.type = 'baidu'
|
|
16171
16187
|
// // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
|
|
16172
16188
|
// lsProxy.setItem('tenantsetting', JSON.stringify(tenantsetting))
|
|
@@ -17259,42 +17275,66 @@ var MapService = /*#__PURE__*/function () {
|
|
|
17259
17275
|
}, {
|
|
17260
17276
|
key: "initAmap",
|
|
17261
17277
|
value: function () {
|
|
17262
|
-
var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function
|
|
17263
|
-
var
|
|
17264
|
-
return _regeneratorRuntime$1().wrap(function
|
|
17265
|
-
while (1) switch (
|
|
17278
|
+
var _initAmap = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5() {
|
|
17279
|
+
var _this = this;
|
|
17280
|
+
return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
|
|
17281
|
+
while (1) switch (_context5.prev = _context5.next) {
|
|
17266
17282
|
case 0:
|
|
17267
|
-
|
|
17268
|
-
|
|
17269
|
-
|
|
17283
|
+
return _context5.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
17284
|
+
var _ref = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(resolve, reject) {
|
|
17285
|
+
var time, plugin, AMap;
|
|
17286
|
+
return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
|
|
17287
|
+
while (1) switch (_context4.prev = _context4.next) {
|
|
17288
|
+
case 0:
|
|
17289
|
+
// 高德地图api初始化失败 没有返回reject 因此用超时机制检测
|
|
17290
|
+
time = setTimeout(function () {
|
|
17291
|
+
console.error('initAmap fail: 请检查 AMap key 是否正确配置');
|
|
17292
|
+
resolve(null);
|
|
17293
|
+
}, 3000);
|
|
17294
|
+
if (_this.secretkey) {
|
|
17295
|
+
window._AMapSecurityConfig = {
|
|
17296
|
+
securityJsCode: _this.secretkey
|
|
17297
|
+
};
|
|
17298
|
+
}
|
|
17299
|
+
plugin = ['AMap.Geolocation', 'AMap.Geocoder']; // debugger
|
|
17300
|
+
_context4.next = 5;
|
|
17301
|
+
return AMapLoader$1.load({
|
|
17302
|
+
key: _this.key,
|
|
17303
|
+
version: '2.0',
|
|
17304
|
+
plugins: plugin,
|
|
17305
|
+
AMapUI: {
|
|
17306
|
+
version: '1.1',
|
|
17307
|
+
plugins: []
|
|
17308
|
+
}
|
|
17309
|
+
});
|
|
17310
|
+
case 5:
|
|
17311
|
+
AMap = _context4.sent;
|
|
17312
|
+
// debugger
|
|
17313
|
+
clearTimeout(time);
|
|
17314
|
+
window.AMap = AMap;
|
|
17315
|
+
_this.AMap = window.AMap;
|
|
17316
|
+
_this.MapCore = window.AMap;
|
|
17317
|
+
// console.log(window)
|
|
17318
|
+
// console.log(window.AMap)
|
|
17319
|
+
// console.log(window.AMapUI)
|
|
17320
|
+
// console.log(window.AMapLoader)
|
|
17321
|
+
// console.log(window.AMap === aaaa)
|
|
17322
|
+
resolve(window.AMap);
|
|
17323
|
+
case 11:
|
|
17324
|
+
case "end":
|
|
17325
|
+
return _context4.stop();
|
|
17326
|
+
}
|
|
17327
|
+
}, _callee4);
|
|
17328
|
+
}));
|
|
17329
|
+
return function (_x, _x2) {
|
|
17330
|
+
return _ref.apply(this, arguments);
|
|
17270
17331
|
};
|
|
17271
|
-
}
|
|
17272
|
-
|
|
17273
|
-
_context4.next = 4;
|
|
17274
|
-
return AMapLoader$1.load({
|
|
17275
|
-
key: this.key,
|
|
17276
|
-
version: '2.0',
|
|
17277
|
-
plugins: plugin,
|
|
17278
|
-
AMapUI: {
|
|
17279
|
-
version: '1.1',
|
|
17280
|
-
plugins: []
|
|
17281
|
-
}
|
|
17282
|
-
});
|
|
17283
|
-
case 4:
|
|
17284
|
-
AMap = _context4.sent;
|
|
17285
|
-
window.AMap = AMap;
|
|
17286
|
-
this.AMap = AMap;
|
|
17287
|
-
this.MapCore = window.AMap;
|
|
17288
|
-
// console.log(window)
|
|
17289
|
-
// console.log(window.AMap)
|
|
17290
|
-
// console.log(window.AMapUI)
|
|
17291
|
-
// console.log(window.AMapLoader)
|
|
17292
|
-
// console.log(window.AMap === aaaa)
|
|
17293
|
-
case 8:
|
|
17332
|
+
}()));
|
|
17333
|
+
case 1:
|
|
17294
17334
|
case "end":
|
|
17295
|
-
return
|
|
17335
|
+
return _context5.stop();
|
|
17296
17336
|
}
|
|
17297
|
-
},
|
|
17337
|
+
}, _callee5);
|
|
17298
17338
|
}));
|
|
17299
17339
|
function initAmap() {
|
|
17300
17340
|
return _initAmap.apply(this, arguments);
|
|
@@ -17304,15 +17344,17 @@ var MapService = /*#__PURE__*/function () {
|
|
|
17304
17344
|
}, {
|
|
17305
17345
|
key: "initBaidu",
|
|
17306
17346
|
value: function () {
|
|
17307
|
-
var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function
|
|
17308
|
-
var
|
|
17309
|
-
return _regeneratorRuntime$1().wrap(function
|
|
17310
|
-
while (1) switch (
|
|
17347
|
+
var _initBaidu = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6() {
|
|
17348
|
+
var _this2 = this;
|
|
17349
|
+
return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
|
|
17350
|
+
while (1) switch (_context6.prev = _context6.next) {
|
|
17311
17351
|
case 0:
|
|
17312
|
-
return
|
|
17313
|
-
window.BMAP_INITIAL_CALLBACK = function () {
|
|
17314
|
-
|
|
17315
|
-
|
|
17352
|
+
return _context6.abrupt("return", new Promise(function (resolve, reject) {
|
|
17353
|
+
window.BMAP_INITIAL_CALLBACK = function (e) {
|
|
17354
|
+
// console.log(e)
|
|
17355
|
+
// debugger
|
|
17356
|
+
_this2.BMap = window.BMap;
|
|
17357
|
+
_this2.MapCore = window.BMap;
|
|
17316
17358
|
// debugger
|
|
17317
17359
|
// 启用google标准坐标体系
|
|
17318
17360
|
// coordsType 指定输入输出的坐标类型,BMAP_COORD_GCJ02为gcj02坐标,BMAP_COORD_BD09为bd0ll坐标,默认为BMAP_COORD_BD09。
|
|
@@ -17321,7 +17363,7 @@ var MapService = /*#__PURE__*/function () {
|
|
|
17321
17363
|
};
|
|
17322
17364
|
var script = document.createElement('script');
|
|
17323
17365
|
// 使用最新 3.0 api https://lbsyun.baidu.com/index.php?title=jspopular3.0
|
|
17324
|
-
script.src = "https://api.map.baidu.com/api?v=3.0&ak=".concat(
|
|
17366
|
+
script.src = "https://api.map.baidu.com/api?v=3.0&ak=".concat(_this2.key, "&callback=BMAP_INITIAL_CALLBACK");
|
|
17325
17367
|
// script.src = `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}&callback=BMAP_INITIAL_CALLBACK`
|
|
17326
17368
|
script.onerror = function (err) {
|
|
17327
17369
|
reject(err);
|
|
@@ -17330,9 +17372,9 @@ var MapService = /*#__PURE__*/function () {
|
|
|
17330
17372
|
}));
|
|
17331
17373
|
case 1:
|
|
17332
17374
|
case "end":
|
|
17333
|
-
return
|
|
17375
|
+
return _context6.stop();
|
|
17334
17376
|
}
|
|
17335
|
-
},
|
|
17377
|
+
}, _callee6);
|
|
17336
17378
|
}));
|
|
17337
17379
|
function initBaidu() {
|
|
17338
17380
|
return _initBaidu.apply(this, arguments);
|
|
@@ -17436,9 +17478,9 @@ var getLocationByNative = /*#__PURE__*/function () {
|
|
|
17436
17478
|
}
|
|
17437
17479
|
}, 30000);
|
|
17438
17480
|
window.Native.getLocation(function (res, error, status) {
|
|
17439
|
-
// console.log('getLocation res', res)
|
|
17440
|
-
// console.log('getLocation error', error)
|
|
17441
|
-
// console.log('getLocation status', status)
|
|
17481
|
+
// console.log('window.Native.getLocation res', res)
|
|
17482
|
+
// console.log('window.Native.getLocation error', error)
|
|
17483
|
+
// console.log('window.Native.getLocation status', status)
|
|
17442
17484
|
isload = true;
|
|
17443
17485
|
if (res && res !== null && res !== void 0 && res.longitude && res !== null && res !== void 0 && res.latitude) {
|
|
17444
17486
|
var result = {
|
|
@@ -17516,139 +17558,24 @@ var getLocationByNavigator = /*#__PURE__*/function () {
|
|
|
17516
17558
|
return _ref2.apply(this, arguments);
|
|
17517
17559
|
};
|
|
17518
17560
|
}();
|
|
17519
|
-
// ipaas ip 定位
|
|
17520
|
-
var getIPLocationByIpaas = /*#__PURE__*/function () {
|
|
17521
|
-
var _ref3 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee3(ip) {
|
|
17522
|
-
return _regeneratorRuntime$1().wrap(function _callee3$(_context3) {
|
|
17523
|
-
while (1) switch (_context3.prev = _context3.next) {
|
|
17524
|
-
case 0:
|
|
17525
|
-
console.log('getIPLocationByIpaas start...');
|
|
17526
|
-
return _context3.abrupt("return", new Promise(function (resolve, reject) {
|
|
17527
|
-
var AMapKey = getAMapKey();
|
|
17528
|
-
normalAxios$1.post('https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001815271', {
|
|
17529
|
-
key: AMapKey.key,
|
|
17530
|
-
ip: ip || ''
|
|
17531
|
-
}).then(function (res) {
|
|
17532
|
-
// console.log(res)
|
|
17533
|
-
// debugger
|
|
17534
|
-
// res.data.rectangle = '113.1017375,22.93212254;113.6770499,23.3809537'
|
|
17535
|
-
if (res.data.rectangle) {
|
|
17536
|
-
var rectangle = res.data.rectangle;
|
|
17537
|
-
var rects = rectangle.split(';').map(function (rect) {
|
|
17538
|
-
var _rect$split = rect.split(','),
|
|
17539
|
-
_rect$split2 = _slicedToArray(_rect$split, 2),
|
|
17540
|
-
longitude = _rect$split2[0],
|
|
17541
|
-
latitude = _rect$split2[1];
|
|
17542
|
-
return {
|
|
17543
|
-
longitude: Number(longitude),
|
|
17544
|
-
latitude: Number(latitude)
|
|
17545
|
-
};
|
|
17546
|
-
});
|
|
17547
|
-
var result = {
|
|
17548
|
-
longitude: ((rects[0].longitude + rects[1].longitude) / 2).toString(),
|
|
17549
|
-
latitude: ((rects[0].latitude + rects[1].latitude) / 2).toString()
|
|
17550
|
-
};
|
|
17551
|
-
console.log("getIPLocationByIpaas success: ".concat(JSON.stringify(result)));
|
|
17552
|
-
resolve(result);
|
|
17553
|
-
} else {
|
|
17554
|
-
console.error('getIPLocationByIpaas fail');
|
|
17555
|
-
resolve(null);
|
|
17556
|
-
}
|
|
17557
|
-
})["catch"](function (err) {
|
|
17558
|
-
console.error(err);
|
|
17559
|
-
console.error('getIPLocationByIpaas fail');
|
|
17560
|
-
resolve(null);
|
|
17561
|
-
});
|
|
17562
|
-
}));
|
|
17563
|
-
case 2:
|
|
17564
|
-
case "end":
|
|
17565
|
-
return _context3.stop();
|
|
17566
|
-
}
|
|
17567
|
-
}, _callee3);
|
|
17568
|
-
}));
|
|
17569
|
-
return function getIPLocationByIpaas(_x) {
|
|
17570
|
-
return _ref3.apply(this, arguments);
|
|
17571
|
-
};
|
|
17572
|
-
}();
|
|
17573
|
-
// ipaas 逆地址解析
|
|
17574
|
-
var getAddressByIpaas = /*#__PURE__*/function () {
|
|
17575
|
-
var _ref4 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee5(position) {
|
|
17576
|
-
return _regeneratorRuntime$1().wrap(function _callee5$(_context5) {
|
|
17577
|
-
while (1) switch (_context5.prev = _context5.next) {
|
|
17578
|
-
case 0:
|
|
17579
|
-
console.log('getAddressByIpaas start...');
|
|
17580
|
-
// 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
|
|
17581
|
-
return _context5.abrupt("return", new Promise( /*#__PURE__*/function () {
|
|
17582
|
-
var _ref5 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee4(resolve, reject) {
|
|
17583
|
-
var _result$data, AMapKey, result, address;
|
|
17584
|
-
return _regeneratorRuntime$1().wrap(function _callee4$(_context4) {
|
|
17585
|
-
while (1) switch (_context4.prev = _context4.next) {
|
|
17586
|
-
case 0:
|
|
17587
|
-
if (!position) {
|
|
17588
|
-
_context4.next = 15;
|
|
17589
|
-
break;
|
|
17590
|
-
}
|
|
17591
|
-
_context4.prev = 1;
|
|
17592
|
-
AMapKey = getAMapKey();
|
|
17593
|
-
_context4.next = 5;
|
|
17594
|
-
return normalAxios$1.post('https://silkroad.wxchina.com/api/openapi/publishEvent?topic=xw-listener&subtopic=xw-listener&apicaseid=6684389338001809906', {
|
|
17595
|
-
longitude: position.longitude,
|
|
17596
|
-
latitude: position.latitude,
|
|
17597
|
-
key: AMapKey.key
|
|
17598
|
-
// extensions: 'all'
|
|
17599
|
-
});
|
|
17600
|
-
case 5:
|
|
17601
|
-
result = _context4.sent;
|
|
17602
|
-
// console.log(result)
|
|
17603
|
-
address = result === null || result === void 0 || (_result$data = result.data) === null || _result$data === void 0 ? void 0 : _result$data.formatted_address;
|
|
17604
|
-
if (address) {
|
|
17605
|
-
console.log("getAddressByIpaas success: ".concat(address));
|
|
17606
|
-
resolve(address);
|
|
17607
|
-
} else {
|
|
17608
|
-
console.error('getAddressByIpaas fail');
|
|
17609
|
-
resolve('');
|
|
17610
|
-
}
|
|
17611
|
-
_context4.next = 15;
|
|
17612
|
-
break;
|
|
17613
|
-
case 10:
|
|
17614
|
-
_context4.prev = 10;
|
|
17615
|
-
_context4.t0 = _context4["catch"](1);
|
|
17616
|
-
console.error(_context4.t0);
|
|
17617
|
-
console.error('getAddressByIpaas fail');
|
|
17618
|
-
resolve('');
|
|
17619
|
-
case 15:
|
|
17620
|
-
case "end":
|
|
17621
|
-
return _context4.stop();
|
|
17622
|
-
}
|
|
17623
|
-
}, _callee4, null, [[1, 10]]);
|
|
17624
|
-
}));
|
|
17625
|
-
return function (_x3, _x4) {
|
|
17626
|
-
return _ref5.apply(this, arguments);
|
|
17627
|
-
};
|
|
17628
|
-
}()));
|
|
17629
|
-
case 2:
|
|
17630
|
-
case "end":
|
|
17631
|
-
return _context5.stop();
|
|
17632
|
-
}
|
|
17633
|
-
}, _callee5);
|
|
17634
|
-
}));
|
|
17635
|
-
return function getAddressByIpaas(_x2) {
|
|
17636
|
-
return _ref4.apply(this, arguments);
|
|
17637
|
-
};
|
|
17638
|
-
}();
|
|
17639
17561
|
// 高德定位
|
|
17640
|
-
var
|
|
17562
|
+
var getLocationByAMap = /*#__PURE__*/function () {
|
|
17641
17563
|
var _ref6 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee6() {
|
|
17642
17564
|
return _regeneratorRuntime$1().wrap(function _callee6$(_context6) {
|
|
17643
17565
|
while (1) switch (_context6.prev = _context6.next) {
|
|
17644
17566
|
case 0:
|
|
17645
|
-
console.log('
|
|
17567
|
+
console.log('getLocationByAMap start...');
|
|
17646
17568
|
return _context6.abrupt("return", new Promise(function (resolve, reject) {
|
|
17647
|
-
var
|
|
17569
|
+
var _window;
|
|
17570
|
+
if (!((_window = window) !== null && _window !== void 0 && _window.AMap)) {
|
|
17571
|
+
console.error('getLocationByAMap fail: AMap is undefinded');
|
|
17572
|
+
resolve(null);
|
|
17573
|
+
return;
|
|
17574
|
+
}
|
|
17575
|
+
new window.AMap.Geolocation({
|
|
17648
17576
|
enableHighAccuracy: true,
|
|
17649
17577
|
timeout: 15000
|
|
17650
|
-
})
|
|
17651
|
-
geolocation.getCurrentPosition(function (status, res) {
|
|
17578
|
+
}).getCurrentPosition(function (status, res) {
|
|
17652
17579
|
// console.log(status, result)
|
|
17653
17580
|
// debugger
|
|
17654
17581
|
if (status === 'complete') {
|
|
@@ -17659,10 +17586,10 @@ var getLocationByAmap = /*#__PURE__*/function () {
|
|
|
17659
17586
|
longitude: lng.toString(),
|
|
17660
17587
|
latitude: lat.toString()
|
|
17661
17588
|
};
|
|
17662
|
-
console.log("
|
|
17589
|
+
console.log("getLocationByAMap success: ".concat(JSON.stringify(result)));
|
|
17663
17590
|
resolve(result);
|
|
17664
17591
|
} else {
|
|
17665
|
-
console.error('
|
|
17592
|
+
console.error('getLocationByAMap fail');
|
|
17666
17593
|
resolve(null);
|
|
17667
17594
|
}
|
|
17668
17595
|
});
|
|
@@ -17673,23 +17600,28 @@ var getLocationByAmap = /*#__PURE__*/function () {
|
|
|
17673
17600
|
}
|
|
17674
17601
|
}, _callee6);
|
|
17675
17602
|
}));
|
|
17676
|
-
return function
|
|
17603
|
+
return function getLocationByAMap() {
|
|
17677
17604
|
return _ref6.apply(this, arguments);
|
|
17678
17605
|
};
|
|
17679
17606
|
}();
|
|
17680
17607
|
// 高德城市定位
|
|
17681
|
-
var
|
|
17608
|
+
var getCityLocationByAMap = /*#__PURE__*/function () {
|
|
17682
17609
|
var _ref7 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee7() {
|
|
17683
17610
|
return _regeneratorRuntime$1().wrap(function _callee7$(_context7) {
|
|
17684
17611
|
while (1) switch (_context7.prev = _context7.next) {
|
|
17685
17612
|
case 0:
|
|
17686
|
-
console.log('
|
|
17613
|
+
console.log('getCityLocationByAMap start...');
|
|
17687
17614
|
return _context7.abrupt("return", new Promise(function (resolve, reject) {
|
|
17688
|
-
var
|
|
17615
|
+
var _window2;
|
|
17616
|
+
if (!((_window2 = window) !== null && _window2 !== void 0 && _window2.AMap)) {
|
|
17617
|
+
console.error('getCityLocationByAMap fail: AMap is undefinded');
|
|
17618
|
+
resolve(null);
|
|
17619
|
+
return;
|
|
17620
|
+
}
|
|
17621
|
+
new window.AMap.Geolocation({
|
|
17689
17622
|
enableHighAccuracy: true,
|
|
17690
17623
|
timeout: 15000
|
|
17691
|
-
})
|
|
17692
|
-
geolocation.getCityInfo(function (status, res) {
|
|
17624
|
+
}).getCityInfo(function (status, res) {
|
|
17693
17625
|
// console.log(res)
|
|
17694
17626
|
// debugger
|
|
17695
17627
|
if (status === 'complete') {
|
|
@@ -17699,10 +17631,10 @@ var getCityLocationByAmap = /*#__PURE__*/function () {
|
|
|
17699
17631
|
longitude: lng.toString(),
|
|
17700
17632
|
latitude: lat.toString()
|
|
17701
17633
|
};
|
|
17702
|
-
console.log("
|
|
17634
|
+
console.log("getCityLocationByAMap success: ".concat(JSON.stringify(result)));
|
|
17703
17635
|
resolve(result);
|
|
17704
17636
|
} else {
|
|
17705
|
-
console.error('
|
|
17637
|
+
console.error('getCityLocationByAMap fail');
|
|
17706
17638
|
resolve(null);
|
|
17707
17639
|
}
|
|
17708
17640
|
});
|
|
@@ -17713,19 +17645,25 @@ var getCityLocationByAmap = /*#__PURE__*/function () {
|
|
|
17713
17645
|
}
|
|
17714
17646
|
}, _callee7);
|
|
17715
17647
|
}));
|
|
17716
|
-
return function
|
|
17648
|
+
return function getCityLocationByAMap() {
|
|
17717
17649
|
return _ref7.apply(this, arguments);
|
|
17718
17650
|
};
|
|
17719
17651
|
}();
|
|
17720
17652
|
// 高德逆地址解析
|
|
17721
|
-
var
|
|
17653
|
+
var getAddressByAMap = /*#__PURE__*/function () {
|
|
17722
17654
|
var _ref8 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee8(position) {
|
|
17723
17655
|
return _regeneratorRuntime$1().wrap(function _callee8$(_context8) {
|
|
17724
17656
|
while (1) switch (_context8.prev = _context8.next) {
|
|
17725
17657
|
case 0:
|
|
17726
|
-
console.log('
|
|
17658
|
+
console.log('getAddressByAMap start...');
|
|
17727
17659
|
return _context8.abrupt("return", new Promise(function (resolve, reject) {
|
|
17728
17660
|
if (position) {
|
|
17661
|
+
var _window3;
|
|
17662
|
+
if (!((_window3 = window) !== null && _window3 !== void 0 && _window3.AMap)) {
|
|
17663
|
+
console.error('getAddressByAMap fail: AMap is undefinded');
|
|
17664
|
+
resolve('');
|
|
17665
|
+
return;
|
|
17666
|
+
}
|
|
17729
17667
|
new window.AMap.Geocoder({
|
|
17730
17668
|
city: '',
|
|
17731
17669
|
radius: 500
|
|
@@ -17736,10 +17674,10 @@ var getAddressByAmap = /*#__PURE__*/function () {
|
|
|
17736
17674
|
// debugger
|
|
17737
17675
|
if (status === 'complete' && result.info === 'OK' && result !== null && result !== void 0 && (_result$regeocode = result.regeocode) !== null && _result$regeocode !== void 0 && _result$regeocode.formattedAddress) {
|
|
17738
17676
|
var address = result.regeocode.formattedAddress || '';
|
|
17739
|
-
console.log("
|
|
17677
|
+
console.log("getAddressByAMap success: ".concat(address));
|
|
17740
17678
|
resolve(address);
|
|
17741
17679
|
} else {
|
|
17742
|
-
console.error("
|
|
17680
|
+
console.error("getAddressByAMap fail: status = ".concat(status, ", result = ").concat(result));
|
|
17743
17681
|
resolve('');
|
|
17744
17682
|
}
|
|
17745
17683
|
});
|
|
@@ -17751,7 +17689,7 @@ var getAddressByAmap = /*#__PURE__*/function () {
|
|
|
17751
17689
|
}
|
|
17752
17690
|
}, _callee8);
|
|
17753
17691
|
}));
|
|
17754
|
-
return function
|
|
17692
|
+
return function getAddressByAMap(_x5) {
|
|
17755
17693
|
return _ref8.apply(this, arguments);
|
|
17756
17694
|
};
|
|
17757
17695
|
}();
|
|
@@ -17763,11 +17701,12 @@ var getIPLocationByTMap = /*#__PURE__*/function () {
|
|
|
17763
17701
|
case 0:
|
|
17764
17702
|
console.log('getIPLocationByTMap start...');
|
|
17765
17703
|
return _context9.abrupt("return", new Promise(function (resolve, reject) {
|
|
17766
|
-
var ipLocation = new window.TMap.service.IPLocation();
|
|
17767
17704
|
var params = ip ? {
|
|
17768
17705
|
ip: ip
|
|
17769
17706
|
} : {};
|
|
17770
|
-
|
|
17707
|
+
new window.TMap.service.IPLocation().locate(_objectSpread2$1(_objectSpread2$1({}, params), {}, {
|
|
17708
|
+
servicesk: mapService.secretkey
|
|
17709
|
+
})).then(function (res) {
|
|
17771
17710
|
var result = {
|
|
17772
17711
|
longitude: res.result.location.lng.toString(),
|
|
17773
17712
|
latitude: res.result.location.lat.toString()
|
|
@@ -17799,13 +17738,11 @@ var getAddressByTMap = /*#__PURE__*/function () {
|
|
|
17799
17738
|
console.log('getAddressByTMap start...');
|
|
17800
17739
|
return _context10.abrupt("return", new Promise(function (resolve, reject) {
|
|
17801
17740
|
if (position) {
|
|
17802
|
-
var location = new window.TMap.LatLng(position.latitude, position.longitude);
|
|
17803
|
-
// console.log(position)
|
|
17804
|
-
// console.log(location)
|
|
17805
17741
|
// debugger
|
|
17806
17742
|
new window.TMap.service.Geocoder().getAddress({
|
|
17807
|
-
location:
|
|
17808
|
-
getPoi: false
|
|
17743
|
+
location: new window.TMap.LatLng(position.latitude, position.longitude),
|
|
17744
|
+
getPoi: false,
|
|
17745
|
+
servicesk: mapService.secretkey
|
|
17809
17746
|
}).then(function (res) {
|
|
17810
17747
|
var _res$result, _res$result2;
|
|
17811
17748
|
// console.log(res)
|
|
@@ -18015,6 +17952,7 @@ var getAddressByBmap = /*#__PURE__*/function () {
|
|
|
18015
17952
|
resolve(address);
|
|
18016
17953
|
} else {
|
|
18017
17954
|
console.error('getAddressByBmap fail');
|
|
17955
|
+
// console.error(result)
|
|
18018
17956
|
resolve('');
|
|
18019
17957
|
}
|
|
18020
17958
|
});
|
|
@@ -18040,7 +17978,7 @@ var getAddressByBmap = /*#__PURE__*/function () {
|
|
|
18040
17978
|
}();
|
|
18041
17979
|
var getLocationPromise = /*#__PURE__*/function () {
|
|
18042
17980
|
var _ref17 = _asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee17() {
|
|
18043
|
-
var
|
|
17981
|
+
var _window4;
|
|
18044
17982
|
var isuseiplocarion,
|
|
18045
17983
|
location,
|
|
18046
17984
|
_args17 = arguments;
|
|
@@ -18049,7 +17987,7 @@ var getLocationPromise = /*#__PURE__*/function () {
|
|
|
18049
17987
|
case 0:
|
|
18050
17988
|
isuseiplocarion = _args17.length > 0 && _args17[0] !== undefined ? _args17[0] : false;
|
|
18051
17989
|
location = null; // 在 SPU 容器里使用 Native-API 的定位
|
|
18052
|
-
if (!((
|
|
17990
|
+
if (!((_window4 = window) !== null && _window4 !== void 0 && (_window4 = _window4.Native) !== null && _window4 !== void 0 && _window4.getLocation)) {
|
|
18053
17991
|
_context17.next = 6;
|
|
18054
17992
|
break;
|
|
18055
17993
|
}
|
|
@@ -18068,15 +18006,15 @@ var getLocationPromise = /*#__PURE__*/function () {
|
|
|
18068
18006
|
location = _context17.sent;
|
|
18069
18007
|
case 10:
|
|
18070
18008
|
if (location) {
|
|
18071
|
-
_context17.next =
|
|
18009
|
+
_context17.next = 35;
|
|
18072
18010
|
break;
|
|
18073
18011
|
}
|
|
18074
18012
|
if (!(mapService.type === 'amap')) {
|
|
18075
|
-
_context17.next =
|
|
18013
|
+
_context17.next = 21;
|
|
18076
18014
|
break;
|
|
18077
18015
|
}
|
|
18078
18016
|
_context17.next = 14;
|
|
18079
|
-
return
|
|
18017
|
+
return getLocationByAMap();
|
|
18080
18018
|
case 14:
|
|
18081
18019
|
location = _context17.sent;
|
|
18082
18020
|
if (!(!location && isuseiplocarion)) {
|
|
@@ -18084,50 +18022,41 @@ var getLocationPromise = /*#__PURE__*/function () {
|
|
|
18084
18022
|
break;
|
|
18085
18023
|
}
|
|
18086
18024
|
_context17.next = 18;
|
|
18087
|
-
return
|
|
18025
|
+
return getCityLocationByAMap();
|
|
18088
18026
|
case 18:
|
|
18089
18027
|
location = _context17.sent;
|
|
18090
18028
|
case 19:
|
|
18091
|
-
|
|
18092
|
-
_context17.next = 23;
|
|
18093
|
-
break;
|
|
18094
|
-
}
|
|
18095
|
-
_context17.next = 22;
|
|
18096
|
-
return getIPLocationByIpaas();
|
|
18097
|
-
case 22:
|
|
18098
|
-
location = _context17.sent;
|
|
18099
|
-
case 23:
|
|
18100
|
-
_context17.next = 39;
|
|
18029
|
+
_context17.next = 35;
|
|
18101
18030
|
break;
|
|
18102
|
-
case
|
|
18031
|
+
case 21:
|
|
18103
18032
|
if (!(mapService.type === 'tencent' && isuseiplocarion)) {
|
|
18104
|
-
_context17.next =
|
|
18033
|
+
_context17.next = 27;
|
|
18105
18034
|
break;
|
|
18106
18035
|
}
|
|
18107
|
-
_context17.next =
|
|
18036
|
+
_context17.next = 24;
|
|
18108
18037
|
return getIPLocationByTMap();
|
|
18109
|
-
case
|
|
18038
|
+
case 24:
|
|
18110
18039
|
location = _context17.sent;
|
|
18111
|
-
_context17.next =
|
|
18040
|
+
_context17.next = 35;
|
|
18112
18041
|
break;
|
|
18113
|
-
case
|
|
18042
|
+
case 27:
|
|
18114
18043
|
if (!(mapService.type === 'baidu')) {
|
|
18115
|
-
_context17.next =
|
|
18044
|
+
_context17.next = 35;
|
|
18116
18045
|
break;
|
|
18117
18046
|
}
|
|
18118
|
-
_context17.next =
|
|
18047
|
+
_context17.next = 30;
|
|
18119
18048
|
return getLocationByBMap();
|
|
18120
|
-
case
|
|
18049
|
+
case 30:
|
|
18121
18050
|
location = _context17.sent;
|
|
18122
18051
|
if (!(!location && isuseiplocarion)) {
|
|
18123
|
-
_context17.next =
|
|
18052
|
+
_context17.next = 35;
|
|
18124
18053
|
break;
|
|
18125
18054
|
}
|
|
18126
|
-
_context17.next =
|
|
18055
|
+
_context17.next = 34;
|
|
18127
18056
|
return getCityLocationByBMap();
|
|
18128
|
-
case
|
|
18057
|
+
case 34:
|
|
18129
18058
|
location = _context17.sent;
|
|
18130
|
-
case
|
|
18059
|
+
case 35:
|
|
18131
18060
|
// 开发模式下为了方便测试提供虚拟定位
|
|
18132
18061
|
if (!location && urlquery.isvirtuallocation) {
|
|
18133
18062
|
location = {
|
|
@@ -18135,24 +18064,37 @@ var getLocationPromise = /*#__PURE__*/function () {
|
|
|
18135
18064
|
latitude: '39.908671'
|
|
18136
18065
|
};
|
|
18137
18066
|
}
|
|
18067
|
+
// if (location) {
|
|
18068
|
+
// for (let i = 0, len = 5000; i < len; i++) {
|
|
18069
|
+
// // location.latitude = (Number(location.latitude) + 0.02).toString()
|
|
18070
|
+
// location.longitude = (Number(location.longitude) + 0.002).toString()
|
|
18071
|
+
// await getAddress(location)
|
|
18072
|
+
// .then((res: any) => {
|
|
18073
|
+
// console.log(res)
|
|
18074
|
+
// }).catch((err: any) => {
|
|
18075
|
+
// console.error(err)
|
|
18076
|
+
// })
|
|
18077
|
+
// await delay(300)
|
|
18078
|
+
// }
|
|
18079
|
+
// }
|
|
18138
18080
|
if (!(location && !location.address)) {
|
|
18139
|
-
_context17.next =
|
|
18081
|
+
_context17.next = 43;
|
|
18140
18082
|
break;
|
|
18141
18083
|
}
|
|
18142
|
-
_context17.next =
|
|
18084
|
+
_context17.next = 39;
|
|
18143
18085
|
return getAddress(location);
|
|
18144
|
-
case
|
|
18086
|
+
case 39:
|
|
18145
18087
|
_context17.t0 = _context17.sent;
|
|
18146
18088
|
if (_context17.t0) {
|
|
18147
|
-
_context17.next =
|
|
18089
|
+
_context17.next = 42;
|
|
18148
18090
|
break;
|
|
18149
18091
|
}
|
|
18150
18092
|
_context17.t0 = '经纬度获取成功,但地址获取失败。';
|
|
18151
|
-
case
|
|
18093
|
+
case 42:
|
|
18152
18094
|
location.address = _context17.t0;
|
|
18153
|
-
case
|
|
18095
|
+
case 43:
|
|
18154
18096
|
return _context17.abrupt("return", location);
|
|
18155
|
-
case
|
|
18097
|
+
case 44:
|
|
18156
18098
|
case "end":
|
|
18157
18099
|
return _context17.stop();
|
|
18158
18100
|
}
|
|
@@ -18224,51 +18166,42 @@ var getAddress = /*#__PURE__*/function () {
|
|
|
18224
18166
|
case 2:
|
|
18225
18167
|
address = '';
|
|
18226
18168
|
if (address) {
|
|
18227
|
-
_context18.next =
|
|
18169
|
+
_context18.next = 20;
|
|
18228
18170
|
break;
|
|
18229
18171
|
}
|
|
18230
18172
|
if (!(mapService.type === 'amap')) {
|
|
18231
|
-
_context18.next =
|
|
18173
|
+
_context18.next = 10;
|
|
18232
18174
|
break;
|
|
18233
18175
|
}
|
|
18234
18176
|
_context18.next = 7;
|
|
18235
|
-
return
|
|
18177
|
+
return getAddressByAMap(position);
|
|
18236
18178
|
case 7:
|
|
18237
18179
|
address = _context18.sent;
|
|
18238
|
-
|
|
18239
|
-
_context18.next = 12;
|
|
18240
|
-
break;
|
|
18241
|
-
}
|
|
18242
|
-
_context18.next = 11;
|
|
18243
|
-
return getAddressByIpaas(position);
|
|
18244
|
-
case 11:
|
|
18245
|
-
address = _context18.sent;
|
|
18246
|
-
case 12:
|
|
18247
|
-
_context18.next = 24;
|
|
18180
|
+
_context18.next = 20;
|
|
18248
18181
|
break;
|
|
18249
|
-
case
|
|
18182
|
+
case 10:
|
|
18250
18183
|
if (!(mapService.type === 'tencent')) {
|
|
18251
|
-
_context18.next =
|
|
18184
|
+
_context18.next = 16;
|
|
18252
18185
|
break;
|
|
18253
18186
|
}
|
|
18254
|
-
_context18.next =
|
|
18187
|
+
_context18.next = 13;
|
|
18255
18188
|
return getAddressByTMap(position);
|
|
18256
|
-
case
|
|
18189
|
+
case 13:
|
|
18257
18190
|
address = _context18.sent;
|
|
18258
|
-
_context18.next =
|
|
18191
|
+
_context18.next = 20;
|
|
18259
18192
|
break;
|
|
18260
|
-
case
|
|
18193
|
+
case 16:
|
|
18261
18194
|
if (!(mapService.type === 'baidu')) {
|
|
18262
|
-
_context18.next =
|
|
18195
|
+
_context18.next = 20;
|
|
18263
18196
|
break;
|
|
18264
18197
|
}
|
|
18265
|
-
_context18.next =
|
|
18198
|
+
_context18.next = 19;
|
|
18266
18199
|
return getAddressByBmap(position);
|
|
18267
|
-
case
|
|
18200
|
+
case 19:
|
|
18268
18201
|
address = _context18.sent;
|
|
18269
|
-
case
|
|
18202
|
+
case 20:
|
|
18270
18203
|
return _context18.abrupt("return", address);
|
|
18271
|
-
case
|
|
18204
|
+
case 21:
|
|
18272
18205
|
case "end":
|
|
18273
18206
|
return _context18.stop();
|
|
18274
18207
|
}
|
|
@@ -70051,4 +69984,4 @@ var SPUWebPlugin = {
|
|
|
70051
69984
|
version: version
|
|
70052
69985
|
};
|
|
70053
69986
|
|
|
70054
|
-
export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getDistance, getLocation, getRefreshToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
|
|
69987
|
+
export { AMapLoader, Module, normalAxios$1 as apaasAxios, normalAxios$1 as axios, checkLogin, index as components, SPUWebPlugin as default, downloadService, expandexp, functionCheck, getAddress, getDistance, getLocation, getRefreshToken, getToken, getTokenExpires, getUniqueid, getUser, v4 as getUuid, globalConfig, globalOptions, isInApp, isdebugger, isvirtuallocation, lsProxy, mapService, setTitle, singleLogin, spuAxios, spuConfig, ssProxy, updateToken, uploadService, wxworkSuite };
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { version } from '../package.json'
|
|
|
2
2
|
import { merge } from 'lodash-es'
|
|
3
3
|
import { v4 as getUuid } from 'uuid'
|
|
4
4
|
import { installStorageProxy, lsProxy, ssProxy } from './storageProxy'
|
|
5
|
-
import { getLocation, getDistance } from './map/index'
|
|
5
|
+
import { getLocation, getDistance, getAddress } from './map/index'
|
|
6
6
|
import { installAxios, spuAxios, axios } from './axios'
|
|
7
7
|
import { installSpuConfig, spuConfig } from './spuConfig'
|
|
8
8
|
import { globalConfig } from './globalConfig'
|
|
@@ -101,6 +101,7 @@ export {
|
|
|
101
101
|
ssProxy,
|
|
102
102
|
getLocation,
|
|
103
103
|
getDistance,
|
|
104
|
+
getAddress,
|
|
104
105
|
spuAxios,
|
|
105
106
|
axios,
|
|
106
107
|
axios as apaasAxios,
|
package/src/map/MapService.ts
CHANGED
|
@@ -127,45 +127,51 @@ class MapService {
|
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
private async initAmap() {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
const plugin = ['AMap.Geolocation', 'AMap.Geocoder']
|
|
130
|
+
return new Promise(async (resolve, reject) => {
|
|
131
|
+
// 高德地图api初始化失败 没有返回reject 因此用超时机制检测
|
|
132
|
+
const time = setTimeout(() => {
|
|
133
|
+
console.error('initAmap fail: 请检查 AMap key 是否正确配置')
|
|
134
|
+
resolve(null)
|
|
135
|
+
}, 3000)
|
|
137
136
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
AMapUI: {
|
|
143
|
-
version: '1.1',
|
|
144
|
-
plugins: []
|
|
137
|
+
if (this.secretkey) {
|
|
138
|
+
window._AMapSecurityConfig = {
|
|
139
|
+
securityJsCode: this.secretkey
|
|
140
|
+
}
|
|
145
141
|
}
|
|
142
|
+
|
|
143
|
+
const plugin = ['AMap.Geolocation', 'AMap.Geocoder']
|
|
144
|
+
// debugger
|
|
145
|
+
|
|
146
|
+
const AMap = await AMapLoader.load({
|
|
147
|
+
key: this.key,
|
|
148
|
+
version: '2.0',
|
|
149
|
+
plugins: plugin,
|
|
150
|
+
AMapUI: {
|
|
151
|
+
version: '1.1',
|
|
152
|
+
plugins: []
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
// debugger
|
|
156
|
+
clearTimeout(time)
|
|
157
|
+
|
|
158
|
+
window.AMap = AMap
|
|
159
|
+
this.AMap = window.AMap
|
|
160
|
+
this.MapCore = window.AMap
|
|
161
|
+
// console.log(window)
|
|
162
|
+
// console.log(window.AMap)
|
|
163
|
+
// console.log(window.AMapUI)
|
|
164
|
+
// console.log(window.AMapLoader)
|
|
165
|
+
// console.log(window.AMap === aaaa)
|
|
166
|
+
resolve(window.AMap)
|
|
146
167
|
})
|
|
147
|
-
window.AMap = AMap
|
|
148
|
-
this.AMap = AMap
|
|
149
|
-
this.MapCore = window.AMap
|
|
150
|
-
// console.log(window)
|
|
151
|
-
// console.log(window.AMap)
|
|
152
|
-
// console.log(window.AMapUI)
|
|
153
|
-
// console.log(window.AMapLoader)
|
|
154
|
-
// console.log(window.AMap === aaaa)
|
|
155
168
|
}
|
|
156
169
|
|
|
157
170
|
private async initBaidu() {
|
|
158
|
-
// await importJS(
|
|
159
|
-
// `https://api.map.baidu.com/api?v=1.0&&type=webgl&ak=${this.key}`,
|
|
160
|
-
// 'BMap'
|
|
161
|
-
// )
|
|
162
|
-
// await delay(300)
|
|
163
|
-
// function initialize() {
|
|
164
|
-
// const mp = new BMap.Map('map')
|
|
165
|
-
// mp.centerAndZoom(new BMap.Point(121.491, 31.233), 11)
|
|
166
|
-
// }
|
|
167
171
|
return new Promise((resolve, reject) => {
|
|
168
|
-
window.BMAP_INITIAL_CALLBACK = () => {
|
|
172
|
+
window.BMAP_INITIAL_CALLBACK = (e: any) => {
|
|
173
|
+
// console.log(e)
|
|
174
|
+
// debugger
|
|
169
175
|
this.BMap = window.BMap
|
|
170
176
|
this.MapCore = window.BMap
|
|
171
177
|
// debugger
|
package/src/map/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { cloneDeep } from 'lodash-es'
|
|
|
3
3
|
import { mapService } from './MapService'
|
|
4
4
|
import { getAMapKey } from './AMapKey'
|
|
5
5
|
import { axios } from '../axios'
|
|
6
|
+
import { delay } from '../utils'
|
|
6
7
|
import { wgs84ToGcj02, BMapTransformBD09ToGCJ02Points } from './utils'
|
|
7
8
|
|
|
8
9
|
type Location = {
|
|
@@ -30,9 +31,9 @@ const getLocationByNative = async (): Promise<Location> => {
|
|
|
30
31
|
}
|
|
31
32
|
}, 30000)
|
|
32
33
|
window.Native.getLocation((res: any, error: any, status: any) => {
|
|
33
|
-
// console.log('getLocation res', res)
|
|
34
|
-
// console.log('getLocation error', error)
|
|
35
|
-
// console.log('getLocation status', status)
|
|
34
|
+
// console.log('window.Native.getLocation res', res)
|
|
35
|
+
// console.log('window.Native.getLocation error', error)
|
|
36
|
+
// console.log('window.Native.getLocation status', status)
|
|
36
37
|
isload = true
|
|
37
38
|
if (res && res?.longitude && res?.latitude) {
|
|
38
39
|
const result = {
|
|
@@ -174,15 +175,18 @@ const getAddressByIpaas = async (position: Location): Promise<string> => {
|
|
|
174
175
|
}
|
|
175
176
|
|
|
176
177
|
// 高德定位
|
|
177
|
-
const
|
|
178
|
-
console.log('
|
|
178
|
+
const getLocationByAMap = async (): Promise<Location> => {
|
|
179
|
+
console.log('getLocationByAMap start...')
|
|
179
180
|
return new Promise((resolve, reject) => {
|
|
180
|
-
|
|
181
|
+
if (!window?.AMap) {
|
|
182
|
+
console.error('getLocationByAMap fail: AMap is undefinded')
|
|
183
|
+
resolve(null)
|
|
184
|
+
return
|
|
185
|
+
}
|
|
186
|
+
new window.AMap.Geolocation({
|
|
181
187
|
enableHighAccuracy: true,
|
|
182
188
|
timeout: 15000
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
geolocation.getCurrentPosition((status: string, res: any) => {
|
|
189
|
+
}).getCurrentPosition((status: string, res: any) => {
|
|
186
190
|
// console.log(status, result)
|
|
187
191
|
// debugger
|
|
188
192
|
if (status === 'complete') {
|
|
@@ -191,10 +195,10 @@ const getLocationByAmap = async (): Promise<Location> => {
|
|
|
191
195
|
longitude: lng.toString(),
|
|
192
196
|
latitude: lat.toString()
|
|
193
197
|
}
|
|
194
|
-
console.log(`
|
|
198
|
+
console.log(`getLocationByAMap success: ${JSON.stringify(result)}`)
|
|
195
199
|
resolve(result)
|
|
196
200
|
} else {
|
|
197
|
-
console.error('
|
|
201
|
+
console.error('getLocationByAMap fail')
|
|
198
202
|
resolve(null)
|
|
199
203
|
}
|
|
200
204
|
})
|
|
@@ -202,14 +206,18 @@ const getLocationByAmap = async (): Promise<Location> => {
|
|
|
202
206
|
}
|
|
203
207
|
|
|
204
208
|
// 高德城市定位
|
|
205
|
-
const
|
|
206
|
-
console.log('
|
|
209
|
+
const getCityLocationByAMap = async (): Promise<Location> => {
|
|
210
|
+
console.log('getCityLocationByAMap start...')
|
|
207
211
|
return new Promise((resolve, reject) => {
|
|
208
|
-
|
|
212
|
+
if (!window?.AMap) {
|
|
213
|
+
console.error('getCityLocationByAMap fail: AMap is undefinded')
|
|
214
|
+
resolve(null)
|
|
215
|
+
return
|
|
216
|
+
}
|
|
217
|
+
new window.AMap.Geolocation({
|
|
209
218
|
enableHighAccuracy: true,
|
|
210
219
|
timeout: 15000
|
|
211
|
-
})
|
|
212
|
-
geolocation.getCityInfo((status: string, res: any) => {
|
|
220
|
+
}).getCityInfo((status: string, res: any) => {
|
|
213
221
|
// console.log(res)
|
|
214
222
|
// debugger
|
|
215
223
|
if (status === 'complete') {
|
|
@@ -219,10 +227,10 @@ const getCityLocationByAmap = async (): Promise<Location> => {
|
|
|
219
227
|
longitude: lng.toString(),
|
|
220
228
|
latitude: lat.toString()
|
|
221
229
|
}
|
|
222
|
-
console.log(`
|
|
230
|
+
console.log(`getCityLocationByAMap success: ${JSON.stringify(result)}`)
|
|
223
231
|
resolve(result)
|
|
224
232
|
} else {
|
|
225
|
-
console.error('
|
|
233
|
+
console.error('getCityLocationByAMap fail')
|
|
226
234
|
resolve(null)
|
|
227
235
|
}
|
|
228
236
|
})
|
|
@@ -230,10 +238,15 @@ const getCityLocationByAmap = async (): Promise<Location> => {
|
|
|
230
238
|
}
|
|
231
239
|
|
|
232
240
|
// 高德逆地址解析
|
|
233
|
-
const
|
|
234
|
-
console.log('
|
|
241
|
+
const getAddressByAMap = async (position: Location): Promise<string> => {
|
|
242
|
+
console.log('getAddressByAMap start...')
|
|
235
243
|
return new Promise((resolve, reject) => {
|
|
236
244
|
if (position) {
|
|
245
|
+
if (!window?.AMap) {
|
|
246
|
+
console.error('getAddressByAMap fail: AMap is undefinded')
|
|
247
|
+
resolve('')
|
|
248
|
+
return
|
|
249
|
+
}
|
|
237
250
|
new window.AMap.Geocoder({
|
|
238
251
|
city: '',
|
|
239
252
|
radius: 500
|
|
@@ -243,10 +256,10 @@ const getAddressByAmap = async (position: Location): Promise<string> => {
|
|
|
243
256
|
// debugger
|
|
244
257
|
if (status === 'complete' && result.info === 'OK' && result?.regeocode?.formattedAddress) {
|
|
245
258
|
const address = result.regeocode.formattedAddress || ''
|
|
246
|
-
console.log(`
|
|
259
|
+
console.log(`getAddressByAMap success: ${address}`)
|
|
247
260
|
resolve(address)
|
|
248
261
|
} else {
|
|
249
|
-
console.error(`
|
|
262
|
+
console.error(`getAddressByAMap fail: status = ${status}, result = ${result}`)
|
|
250
263
|
resolve('')
|
|
251
264
|
}
|
|
252
265
|
})
|
|
@@ -258,10 +271,9 @@ const getAddressByAmap = async (position: Location): Promise<string> => {
|
|
|
258
271
|
const getIPLocationByTMap = async (ip?: string): Promise<Location> => {
|
|
259
272
|
console.log('getIPLocationByTMap start...')
|
|
260
273
|
return new Promise((resolve, reject) => {
|
|
261
|
-
const ipLocation = new window.TMap.service.IPLocation()
|
|
262
274
|
const params = ip ? { ip } : {}
|
|
263
|
-
|
|
264
|
-
.locate(params)
|
|
275
|
+
new window.TMap.service.IPLocation()
|
|
276
|
+
.locate({ ...params, servicesk: mapService.secretkey })
|
|
265
277
|
.then((res: any) => {
|
|
266
278
|
const result = {
|
|
267
279
|
longitude: res.result.location.lng.toString(),
|
|
@@ -283,14 +295,12 @@ const getAddressByTMap = async (position: Location): Promise<string> => {
|
|
|
283
295
|
console.log('getAddressByTMap start...')
|
|
284
296
|
return new Promise((resolve, reject) => {
|
|
285
297
|
if (position) {
|
|
286
|
-
const location = new window.TMap.LatLng(position.latitude, position.longitude)
|
|
287
|
-
// console.log(position)
|
|
288
|
-
// console.log(location)
|
|
289
298
|
// debugger
|
|
290
299
|
new window.TMap.service.Geocoder()
|
|
291
300
|
.getAddress({
|
|
292
|
-
location,
|
|
293
|
-
getPoi: false
|
|
301
|
+
location: new window.TMap.LatLng(position.latitude, position.longitude),
|
|
302
|
+
getPoi: false,
|
|
303
|
+
servicesk: mapService.secretkey
|
|
294
304
|
})
|
|
295
305
|
.then((res: any) => {
|
|
296
306
|
// console.log(res)
|
|
@@ -432,6 +442,7 @@ const getAddressByBmap = async (position: Location): Promise<string> => {
|
|
|
432
442
|
resolve(address)
|
|
433
443
|
} else {
|
|
434
444
|
console.error('getAddressByBmap fail')
|
|
445
|
+
// console.error(result)
|
|
435
446
|
resolve('')
|
|
436
447
|
}
|
|
437
448
|
})
|
|
@@ -453,13 +464,14 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
|
|
|
453
464
|
|
|
454
465
|
if (!location) {
|
|
455
466
|
if (mapService.type === 'amap') {
|
|
456
|
-
location = await
|
|
457
|
-
if (!location && isuseiplocarion) {
|
|
458
|
-
location = await getCityLocationByAmap()
|
|
459
|
-
}
|
|
467
|
+
location = await getLocationByAMap()
|
|
460
468
|
if (!location && isuseiplocarion) {
|
|
461
|
-
location = await
|
|
469
|
+
location = await getCityLocationByAMap()
|
|
462
470
|
}
|
|
471
|
+
// 改成不使用ipaas了
|
|
472
|
+
// if (!location && isuseiplocarion) {
|
|
473
|
+
// location = await getIPLocationByIpaas()
|
|
474
|
+
// }
|
|
463
475
|
} else if (mapService.type === 'tencent' && isuseiplocarion) {
|
|
464
476
|
location = await getIPLocationByTMap()
|
|
465
477
|
} else if (mapService.type === 'baidu') {
|
|
@@ -478,6 +490,20 @@ const getLocationPromise = async (isuseiplocarion = false): Promise<Location> =>
|
|
|
478
490
|
}
|
|
479
491
|
}
|
|
480
492
|
|
|
493
|
+
// if (location) {
|
|
494
|
+
// for (let i = 0, len = 5000; i < len; i++) {
|
|
495
|
+
// // location.latitude = (Number(location.latitude) + 0.02).toString()
|
|
496
|
+
// location.longitude = (Number(location.longitude) + 0.002).toString()
|
|
497
|
+
// await getAddress(location)
|
|
498
|
+
// .then((res: any) => {
|
|
499
|
+
// console.log(res)
|
|
500
|
+
// }).catch((err: any) => {
|
|
501
|
+
// console.error(err)
|
|
502
|
+
// })
|
|
503
|
+
// await delay(300)
|
|
504
|
+
// }
|
|
505
|
+
// }
|
|
506
|
+
|
|
481
507
|
if (location && !location.address) {
|
|
482
508
|
location.address = (await getAddress(location)) || '经纬度获取成功,但地址获取失败。'
|
|
483
509
|
}
|
|
@@ -519,12 +545,11 @@ const getAddress = async (position: Location): Promise<string> => {
|
|
|
519
545
|
|
|
520
546
|
if (!address) {
|
|
521
547
|
if (mapService.type === 'amap') {
|
|
522
|
-
address = await
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
}
|
|
548
|
+
address = await getAddressByAMap(position)
|
|
549
|
+
// if (!address) {
|
|
550
|
+
// // 如果不设置安全秘钥的话 js-api的逆地址查询不成功 返回 INVALID_USER_SCODE 改成用ipaas服务查询
|
|
551
|
+
// address = await getAddressByIpaas(position)
|
|
552
|
+
// }
|
|
528
553
|
} else if (mapService.type === 'tencent') {
|
|
529
554
|
address = await getAddressByTMap(position)
|
|
530
555
|
} else if (mapService.type === 'baidu') {
|
package/src/tenantSetting.ts
CHANGED
|
@@ -60,13 +60,31 @@ class TenantSetting {
|
|
|
60
60
|
// }
|
|
61
61
|
// }
|
|
62
62
|
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
63
|
+
// // 高德地图key配置错误
|
|
64
|
+
// // 1 如果是key格式不对 那么没返回promise 连window.AMap都拿不到 地图和都不能用
|
|
65
|
+
// // 1 如果是key对式对 但key不对 有返回 window.AMap 但api定位调用失败 地图可以渲染空白地图
|
|
66
66
|
|
|
67
|
-
// //
|
|
68
|
-
// // tenantsetting.lbssetting.setting.
|
|
67
|
+
// // // 高德地图公司key
|
|
68
|
+
// // tenantsetting.lbssetting.setting.type = 'amap'
|
|
69
|
+
// // tenantsetting.lbssetting.setting.key.web = '1993ac213d2f4675ac1bffb1b03ef1f0'
|
|
70
|
+
// // tenantsetting.lbssetting.setting.secretkey.web = '816fe46b7b7bce145940b93c1e4818fa'
|
|
69
71
|
|
|
72
|
+
// // // 高德地图个人key
|
|
73
|
+
// // tenantsetting.lbssetting.setting.type = 'amap'
|
|
74
|
+
// // tenantsetting.lbssetting.setting.key.web = 'e4d25fe4661a34198c4e6f79abe9afac'
|
|
75
|
+
// // tenantsetting.lbssetting.setting.secretkey.web = 'a6b674affd9a3278c68602cf7ba02fcb'
|
|
76
|
+
|
|
77
|
+
// // tencent地图key配置错误
|
|
78
|
+
// // 1 如果是地图 会在地图上明确文字提示 鉴权失败,请传入正确的key
|
|
79
|
+
// // 2 如果是调用定位等api 会返回 catch 和详细的错误信息
|
|
80
|
+
// // getIPLocationByTMap fail: {"status":311,"message":"key格式错误","request_id":"ccedb04fd95e4f3f9cd45cfbad729d10","id":"cbm919vjdj0"}
|
|
81
|
+
// // getIPLocationByTMap fail: {"status":190,"message":"无效的key","request_id":"b6ca9d0749eb4c91a47db9412b1253ca","id":"cbm919wxo40"}
|
|
82
|
+
// tenantsetting.lbssetting.setting.type = 'tencent'
|
|
83
|
+
// tenantsetting.lbssetting.setting.key.web = 'NHBBZ-K5LCQ-LF35M-2CTDP-E4OO7-AIBFT'
|
|
84
|
+
// tenantsetting.lbssetting.setting.secretkey.web = 'zowvV5I2pSxqgGb2Sgr1x62HGXbqdxT0'
|
|
85
|
+
|
|
86
|
+
// // 百度地图key配置错误alert以下信息
|
|
87
|
+
// // 您提供的密钥不是有效的百度LBS开放平台密钥,或此密钥未对本应用的百度地图JavaScriptAPI授权。您可以访问如下网址了解如何获取有效的密钥:http://lbsyun.baidu.com/apiconsole/key#。
|
|
70
88
|
// // tenantsetting.lbssetting.setting.type = 'baidu'
|
|
71
89
|
// // tenantsetting.lbssetting.setting.key.web = '7r3bsPeQqJ74vsxf3EOXg7C1AM4lOWA1'
|
|
72
90
|
|
package/src/types/index.d.ts
CHANGED
|
@@ -99,6 +99,11 @@ export const getLocation: () => Promise<{
|
|
|
99
99
|
[propName: string]: any
|
|
100
100
|
} | null>
|
|
101
101
|
export const getDistance: (p1: [number, number], p2: [number, number]) => Promise<any>
|
|
102
|
+
export const getAddress: (location: {
|
|
103
|
+
longitude: string
|
|
104
|
+
latitude: string
|
|
105
|
+
[propName: string]: any
|
|
106
|
+
}) => Promise<string>
|
|
102
107
|
export const spuAxios: any
|
|
103
108
|
export const apaasAxios: any
|
|
104
109
|
export const axios: any
|