@tmsfe/tms-core 0.0.24 → 0.0.25

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tmsfe/tms-core",
3
- "version": "0.0.24",
3
+ "version": "0.0.25",
4
4
  "description": "tms运行时框架",
5
5
  "repository": {
6
6
  "type": "git",
@@ -0,0 +1,73 @@
1
+
2
+ // 墨卡托坐标转经纬度
3
+ function mercator2LonLat(p) {
4
+ const r = p.y / 111319.49077777778;
5
+ const n = Math.atan(Math.exp(0.017453292519943295 * r)) / 0.008726646259971648 - 90;
6
+ return {
7
+ x: p.x / 111319.49077777778,
8
+ y: n,
9
+ };
10
+ }
11
+
12
+
13
+ // 角度转弧度
14
+ function angle2Rad(t) {
15
+ return (t * Math.PI) / 180;
16
+ }
17
+
18
+
19
+ function client2ServerX(t) {
20
+ return t - 20037508;
21
+ }
22
+
23
+ function client2ServerY(t) {
24
+ return t - 30240971;
25
+ }
26
+
27
+ function longitude2ClientX(t) {
28
+ return Number(111319.49077777778 * Number(t) + 20037508).toFixed(0);
29
+ }
30
+
31
+ function latitude2ClientY(t) {
32
+ const n = Math.log(Math.tan(0.008726646259971648 * (90 + Number(t)))) / 0.017453292519943295;
33
+ return Number(111319.49077777778 * n + 30240971).toFixed(0);
34
+ }
35
+
36
+ function geoPointToServerPoint(t) {
37
+ let n = {};
38
+ if (t) {
39
+ n = {
40
+ x: client2ServerX(longitude2ClientX(t.longitude)),
41
+ y: client2ServerY(latitude2ClientY(t.latitude)),
42
+ };
43
+ }
44
+ return n;
45
+ }
46
+
47
+
48
+ /**
49
+ * 两个经纬度间地理距离(单位:米)
50
+ * @param {*} start {longitude, latitude}
51
+ * @param {*} end {longitude, latitude}
52
+ * @returns
53
+ */
54
+ function distanceBetweenPoints(start, end) {
55
+ let s = geoPointToServerPoint(start);
56
+ let t = geoPointToServerPoint(end);
57
+ s = mercator2LonLat(s); // eslint-disable-line
58
+ t = mercator2LonLat(t); // eslint-disable-line
59
+ const deltaY = angle2Rad(s.y) - angle2Rad(t.y);
60
+ const deltaX = angle2Rad(s.x) - angle2Rad(t.x);
61
+ let res = 2
62
+ * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaY / 2), 2) // eslint-disable-line
63
+ + Math.cos(angle2Rad(s.y))
64
+ * Math.cos(angle2Rad(t.y))
65
+ * Math.pow(Math.sin(deltaX / 2), 2))); // eslint-disable-line
66
+ res *= 6378137;
67
+ res = Math.floor(res * 10000 + 0.5) / 10000;
68
+ return res;
69
+ }
70
+
71
+ export {
72
+ distanceBetweenPoints,
73
+ };
package/src/index.js CHANGED
@@ -11,6 +11,7 @@ import { cache as report, startListenApp } from './report';
11
11
  import EventDispatcher from './eventDispatcher';
12
12
  import { serialize } from './objUtils';
13
13
  import { rpxToPx } from './rpx';
14
+ import { distanceBetweenPoints } from './distanceBetweenPoints';
14
15
  import {
15
16
  formatPlate,
16
17
  subStr,
@@ -180,6 +181,7 @@ const api = {
180
181
 
181
182
  /** rpx转px */
182
183
  rpxToPx,
184
+ distanceBetweenPoints,
183
185
 
184
186
  storage,
185
187
 
@@ -90,6 +90,7 @@ class Location extends LocationBase {
90
90
  const { ad_info: adInfo = {} } = result;
91
91
 
92
92
  const loc = {
93
+ nationCode: adInfo.nation_code,
93
94
  province: adInfo.province,
94
95
  cityName: adInfo.city,
95
96
  adCode: adInfo.adcode,