@wemap/geo 10.7.0 → 10.9.0
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/index.d.ts +8 -2
- package/package.json +3 -3
- package/src/coordinates/GeoRef.js +10 -7
- package/src/coordinates/GeoRef.spec.js +43 -0
package/index.d.ts
CHANGED
|
@@ -69,6 +69,12 @@ declare module '@wemap/geo' {
|
|
|
69
69
|
}
|
|
70
70
|
|
|
71
71
|
|
|
72
|
+
export type GeoRefJson = {
|
|
73
|
+
origin: CoordinatesJson,
|
|
74
|
+
scale?: number,
|
|
75
|
+
heading?: number
|
|
76
|
+
};
|
|
77
|
+
|
|
72
78
|
export class GeoRef {
|
|
73
79
|
origin: Coordinates;
|
|
74
80
|
scale: number;
|
|
@@ -76,9 +82,9 @@ declare module '@wemap/geo' {
|
|
|
76
82
|
|
|
77
83
|
localToWorld(localPosition: [number, number, number]): Coordinates;
|
|
78
84
|
worldToLocal(coords: Coordinates): [number, number, number];
|
|
79
|
-
toJson():
|
|
85
|
+
toJson(): GeoRefJson;
|
|
80
86
|
|
|
81
|
-
static fromJson(json:
|
|
87
|
+
static fromJson(json: GeoRefJson): GeoRef;
|
|
82
88
|
}
|
|
83
89
|
|
|
84
90
|
export type UserPositionJson = CoordinatesJson & {
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"directory": "packages/geo"
|
|
14
14
|
},
|
|
15
15
|
"name": "@wemap/geo",
|
|
16
|
-
"version": "10.
|
|
16
|
+
"version": "10.9.0",
|
|
17
17
|
"bugs": {
|
|
18
18
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
19
19
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"license": "ISC",
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@wemap/logger": "^10.0.0",
|
|
32
|
-
"@wemap/maths": "^10.
|
|
32
|
+
"@wemap/maths": "^10.9.0"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "9cfaff0891646b7a7f888fe220011b3261884f15"
|
|
35
35
|
}
|
|
@@ -43,11 +43,14 @@ class GeoRef {
|
|
|
43
43
|
* @returns {Object}
|
|
44
44
|
*/
|
|
45
45
|
toJson() {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
scale
|
|
49
|
-
|
|
50
|
-
|
|
46
|
+
const obj = {origin: this.origin.toJson()};
|
|
47
|
+
if (this.scale !== 1) {
|
|
48
|
+
obj.scale = this.scale;
|
|
49
|
+
}
|
|
50
|
+
if (this.heading !== 0) {
|
|
51
|
+
obj.heading = this.heading;
|
|
52
|
+
}
|
|
53
|
+
return obj;
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
/**
|
|
@@ -57,8 +60,8 @@ class GeoRef {
|
|
|
57
60
|
static fromJson(json) {
|
|
58
61
|
const geoRef = new GeoRef();
|
|
59
62
|
geoRef.origin = Coordinates.fromJson(json.origin);
|
|
60
|
-
geoRef.scale = json.scale;
|
|
61
|
-
geoRef.heading = json.heading;
|
|
63
|
+
geoRef.scale = 'scale' in json ? json.scale : 1;
|
|
64
|
+
geoRef.heading = 'heading' in json ? json.heading : 0;
|
|
62
65
|
return geoRef;
|
|
63
66
|
}
|
|
64
67
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import chai from 'chai';
|
|
2
|
+
import Coordinates from './Coordinates.js';
|
|
3
|
+
import GeoRef from './GeoRef.js';
|
|
4
|
+
|
|
5
|
+
const { expect } = chai;
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
describe('GeoRef', () => {
|
|
9
|
+
|
|
10
|
+
it('toJson', () => {
|
|
11
|
+
const geoRef = new GeoRef();
|
|
12
|
+
geoRef.origin = new Coordinates(45, 5);
|
|
13
|
+
|
|
14
|
+
geoRef.scale = 2;
|
|
15
|
+
geoRef.heading = 1;
|
|
16
|
+
expect(geoRef.toJson()).deep.equals({ origin: { lat: 45, lng: 5 }, scale: 2, heading: 1 });
|
|
17
|
+
|
|
18
|
+
geoRef.scale = 1;
|
|
19
|
+
geoRef.heading = 0;
|
|
20
|
+
geoRef.origin.alt = 10;
|
|
21
|
+
expect(geoRef.toJson()).deep.equals({ origin: { lat: 45, lng: 5, alt: 10 }});
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it('fromJson', () => {
|
|
25
|
+
let geoRefJson;
|
|
26
|
+
|
|
27
|
+
geoRefJson = GeoRef.fromJson({ origin: { lat: 45, lng: 5 }, scale: 2, heading: 1 });
|
|
28
|
+
expect(geoRefJson.origin.lat).equals(45);
|
|
29
|
+
expect(geoRefJson.origin.lng).equals(5);
|
|
30
|
+
expect(geoRefJson.origin.alt).is.null;
|
|
31
|
+
expect(geoRefJson.origin.level).is.null;
|
|
32
|
+
expect(geoRefJson.scale).equals(2);
|
|
33
|
+
expect(geoRefJson.heading).equals(1);
|
|
34
|
+
|
|
35
|
+
geoRefJson = GeoRef.fromJson({ origin: { lat: 45, lng: 5, alt: 10 } });
|
|
36
|
+
expect(geoRefJson.origin.lat).equals(45);
|
|
37
|
+
expect(geoRefJson.origin.lng).equals(5);
|
|
38
|
+
expect(geoRefJson.origin.alt).equals(10);
|
|
39
|
+
expect(geoRefJson.origin.level).is.null;
|
|
40
|
+
expect(geoRefJson.scale).equals(1);
|
|
41
|
+
expect(geoRefJson.heading).equals(0);
|
|
42
|
+
});
|
|
43
|
+
});
|