@tmsfe/tms-core 0.0.46 → 0.0.47
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/package.json +1 -1
- package/src/distanceUtils.ts +37 -0
- package/src/index-proxy.js +2 -0
- package/src/index.js +3 -0
package/package.json
CHANGED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 经纬度距离计算
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
// 将角度换算为弧度
|
|
7
|
+
function convertDegreesToRadians(degrees: number): number {
|
|
8
|
+
return (degrees * Math.PI) / 180;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function haverSin(theta: number): number {
|
|
12
|
+
const val = Math.sin(theta / 2);
|
|
13
|
+
return val * val;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// 计算两点间距离,单位 m
|
|
17
|
+
function calCoordinateDistance(
|
|
18
|
+
a: { latitude: number, longitude: number },
|
|
19
|
+
b: { latitude: number, longitude: number },
|
|
20
|
+
): number {
|
|
21
|
+
// 地球半径 平均值,千米
|
|
22
|
+
const earthRadius = 6371;
|
|
23
|
+
const lat1 = convertDegreesToRadians(a.latitude);
|
|
24
|
+
const lon1 = convertDegreesToRadians(a.longitude);
|
|
25
|
+
const lat2 = convertDegreesToRadians(b.latitude);
|
|
26
|
+
const lon2 = convertDegreesToRadians(b.longitude);
|
|
27
|
+
// 差值
|
|
28
|
+
const vLon = Math.abs(lon1 - lon2);
|
|
29
|
+
const vLat = Math.abs(lat1 - lat2);
|
|
30
|
+
const h = haverSin(vLat) + (Math.cos(lat1) * Math.cos(lat2) * haverSin(vLon));
|
|
31
|
+
const distance = 2 * earthRadius * Math.asin(Math.sqrt(h));
|
|
32
|
+
return distance * 1000;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export {
|
|
36
|
+
calCoordinateDistance,
|
|
37
|
+
};
|
package/src/index-proxy.js
CHANGED
|
@@ -10,6 +10,7 @@ import AutoReport from './report/proxy/index';
|
|
|
10
10
|
import md5 from './md5';
|
|
11
11
|
import { rpxToPx } from './rpx';
|
|
12
12
|
import { serialize } from './objUtils';
|
|
13
|
+
import { calCoordinateDistance } from './distanceUtils';
|
|
13
14
|
import * as stringUtils from './stringUtils';
|
|
14
15
|
import * as timeUtils from './timeUtils';
|
|
15
16
|
import * as ipxHelper from './ipxHelper';
|
|
@@ -210,6 +211,7 @@ const api = {
|
|
|
210
211
|
getLocationManager,
|
|
211
212
|
rpxToPx,
|
|
212
213
|
serialize,
|
|
214
|
+
calCoordinateDistance,
|
|
213
215
|
createRequest,
|
|
214
216
|
getEnvInfo,
|
|
215
217
|
isAppPageExist,
|
package/src/index.js
CHANGED
|
@@ -10,6 +10,7 @@ import md5 from './md5';
|
|
|
10
10
|
import { callCloudFunc } from './cloudService';
|
|
11
11
|
import EventDispatcher from './eventDispatcher';
|
|
12
12
|
import { serialize } from './objUtils';
|
|
13
|
+
import { calCoordinateDistance } from './distanceUtils';
|
|
13
14
|
import { rpxToPx } from './rpx';
|
|
14
15
|
import {
|
|
15
16
|
formatPlate,
|
|
@@ -169,6 +170,8 @@ const api = {
|
|
|
169
170
|
/* 处理对象方法 */
|
|
170
171
|
serialize,
|
|
171
172
|
|
|
173
|
+
calCoordinateDistance,
|
|
174
|
+
|
|
172
175
|
/* 获取外部合作商openid */
|
|
173
176
|
getMpOpenId, // 变更为 getOuterOpenId
|
|
174
177
|
getOuterOpenId,
|