提交 f76cd009 编写于 作者: VK1688's avatar VK1688

升级uni-map-common模块

上级 79f151a0
## 1.1.4(2024-11-21)
新增 参数payload的接收和验证示例
## 1.1.3(2024-11-11)
优化 chooseLocation 函数供 uni-app x 的 uni.chooseLocation 使用
## 1.1.2(2024-10-21)
......
{
"id": "uni-map-common",
"displayName": "uni-map-common地图服务端API",
"version": "1.1.3",
"version": "1.1.4",
"description": "聚合了多家地图供应商的服务端API,几行代码即可快速接入地图API",
"keywords": [
"uni-map-common",
......@@ -32,7 +32,7 @@
"npmurl": ""
},
"uni_modules": {
"dependencies": [],
"dependencies": ["uni-config-center"],
"encrypt": [],
"platforms": {
"cloud": {
......
......@@ -13,7 +13,7 @@
"uni-config-center": "file:..\/..\/..\/..\/..\/uni-config-center\/uniCloud\/cloudfunctions\/common\/uni-config-center"
},
"origin-plugin-dev-name": "uni-map-common",
"origin-plugin-version": "1.1.3",
"origin-plugin-version": "1.1.4",
"plugin-dev-name": "uni-map-common",
"plugin-version": "1.1.3"
"plugin-version": "1.1.4"
}
\ No newline at end of file
......@@ -21,6 +21,16 @@ const $ = _.aggregate;
const opendbPoiDB = db.collection("opendb-poi");
class MyError extends Error {
constructor(errMsg, errCode = -1) {
super(errMsg);
this.err = {
errCode,
errMsg
}
}
}
module.exports = {
_before: function() {
// 如果配置中心不存在地图配置,则使用本地地图配置
......@@ -33,7 +43,6 @@ module.exports = {
provider = defaultProvider,
needOriginalResult = false
} = params[0] || {};
console.log('provider: ', provider)
const key = UniMapConfig.key[provider] || LocalMapConfig.key[provider];
if (!key) {
throw { errCode: -1, errMsg: `请在uni-config-center/uni-map/config.js中或LocalMapConfig中配置地图供应商${provider}对应的key` };
......@@ -45,10 +54,39 @@ module.exports = {
needOriginalResult
});
this.uniMap = uniMap;
// // 在这里可以做一些统一的前置处理,比如权限校验、参数校验等
// let {
// payload, // payload参数为前端传递的参数,可以在前端调用uni.chooseLocation时传递
// } = this.getParams()[0] || {};
// if (!payload) {
// throw new MyError("payload参数不能为空", -1);
// }
// // 如果业务在uniCloud上,则直接在这里写判断逻辑即可
// if (true) {
// throw new MyError("权限不足", -1);
// }
// // 如果业务不在uniCloud上,可通过 uniCloud.request 调用自己的服务进行校验
// const requestRes = await uniCloud.request({
// method: 'POST',
// url: '你自己的接口地址',
// data: payload,
// });
// // 约定errCode不为0代表校验失败,errMsg为失败原因
// if (requestRes.data.errCode !== 0) {
// throw new MyError(requestRes.data.errMsg, requestRes.data.errCode);
// }
},
_after: function(error, res) {
if (error) {
throw error; // 如果方法抛出错误,也直接抛出不处理
_after: function(err, res) {
if (err) {
if (err.err) {
return err.err;
}
if (err.errCode) {
return err;
}
throw err; // 如果方法抛出错误,也直接抛出不处理
}
console.log("result", res.result);
return res;
......@@ -58,15 +96,17 @@ module.exports = {
let res = {};
let {
action,
data,
data,
needOriginalResult
} = parame;
// 初始化实例
// 获取uniMap实例
const uniMap = this.uniMap;
// 调用API
let result = await uniMap[action](data);
res.result = needOriginalResult ? result.originalResult : result;
// 模拟错误
// res.errCode = 121;
// res.errMsg = '此key每日调用量已达到上限'
return res;
},
// 经纬度坐标转地址
......@@ -448,7 +488,7 @@ module.exports = {
/**
* 生成在指定经纬度圆内的随机坐标
const latitude = 39.908823; // 指定纬度
const longitude = 116.39747; // 指定经度
const radiusInKm = 10; // 指定圆的半径(单位:千米)
......@@ -484,7 +524,7 @@ function getRandomCoordinateWithinRadius(longitude, latitude, radiusInKm) {
/**
* 计算坐标B在坐标A的方向,0代表正西方 90 代表正北方
const latitude = 39.908823; // 指定纬度
const longitude = 116.39747; // 指定经度
const radiusInKm = 10; // 指定圆的半径(单位:千米)
......@@ -515,4 +555,4 @@ function calculateDirectionAngle(coordA, coordB) {
angleDegrees = (angleDegrees > 180) ? angleDegrees - 180 : angleDegrees + 180;
angleDegrees -= 90; // 以正西方为0°表示,因此需要-90
return angleDegrees;
}
\ No newline at end of file
}
{
"name": "uni-map-co",
"dependencies": {
"uni-config-center": "file:../../../../uni-config-center/uniCloud/cloudfunctions/common/uni-config-center",
"uni-map-common": "file:../common/uni-map-common",
"uni-id-common": "file:../../../../uni-id-common/uniCloud/cloudfunctions/common/uni-id-common"
},
"extensions": {}
"name": "uni-map-co",
"dependencies": {
"uni-config-center": "file:..\/..\/..\/..\/uni-config-center\/uniCloud\/cloudfunctions\/common\/uni-config-center",
"uni-map-common": "file:..\/common\/uni-map-common"
},
"extensions": {},
"origin-plugin-dev-name": "uni-map-common",
"origin-plugin-version": "1.1.4",
"plugin-dev-name": "uni-map-common",
"plugin-version": "1.1.4"
}
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册