@wemap/geo 7.3.0 → 7.4.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/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "7.3.0",
15
+ "version": "7.4.0",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -30,5 +30,5 @@
30
30
  "@wemap/logger": "^7.0.0",
31
31
  "@wemap/maths": "^7.0.0"
32
32
  },
33
- "gitHead": "c79062ac53248f45aead5d4edd45b3efbc79755e"
33
+ "gitHead": "dfc8ea75a6e3a148e690b03945f69f880c4e9eb7"
34
34
  }
@@ -8,10 +8,10 @@ class GeoRef {
8
8
  origin;
9
9
 
10
10
  /** @type {number} */
11
- scale;
11
+ scale = 1;
12
12
 
13
13
  /** @type {number} */
14
- heading;
14
+ heading = 0;
15
15
 
16
16
 
17
17
  /**
@@ -19,8 +19,10 @@ class GeoRef {
19
19
  * @returns {Coordinates}
20
20
  */
21
21
  localToWorld(localPosition) {
22
- const ecefToEnuRotationOrigin = this.origin.ecefToEnuRotation;
23
- const ecefTranslation = Quaternion.rotate(ecefToEnuRotationOrigin, localPosition);
22
+ const localPositionScaled = Vector3.multiplyScalar(localPosition, this.scale);
23
+ const rotationOffset = Quaternion.fromAxisAngle([0, 0, 1], this.heading);
24
+ const ecefToEnuRotationOrigin = Quaternion.multiply(rotationOffset, this.origin.ecefToEnuRotation);
25
+ const ecefTranslation = Quaternion.rotate(ecefToEnuRotationOrigin, localPositionScaled);
24
26
  const ecef = Vector3.add(this.origin.ecef, ecefTranslation);
25
27
  return Coordinates.fromECEF(ecef);
26
28
  }
@@ -30,9 +32,34 @@ class GeoRef {
30
32
  * @returns {number[]} localPosition in ENU frame
31
33
  */
32
34
  worldToLocal(coords) {
33
- const enuToEcefRotationOrigin = this.origin.enuToEcefRotation;
35
+ const rotationOffset = Quaternion.fromAxisAngle([0, 0, 1], -this.heading);
36
+ const enuToEcefRotationOrigin = Quaternion.multiply(this.origin.enuToEcefRotation, rotationOffset);
34
37
  const ecefTranslation = Vector3.subtract(coords.ecef, this.origin.ecef);
35
- return Quaternion.rotate(enuToEcefRotationOrigin, ecefTranslation);
38
+ const ecefTranslationScaled = Vector3.multiplyScalar(ecefTranslation, 1 / this.scale);
39
+ return Quaternion.rotate(enuToEcefRotationOrigin, ecefTranslationScaled);
40
+ }
41
+
42
+ /**
43
+ * @returns {Object}
44
+ */
45
+ toJson() {
46
+ return {
47
+ origin: this.origin.toJson(),
48
+ scale: this.scale,
49
+ heading: this.heading
50
+ };
51
+ }
52
+
53
+ /**
54
+ * @param {Object} json
55
+ * @returns {GeoRef}
56
+ */
57
+ static fromJson(json) {
58
+ const geoRef = new GeoRef();
59
+ geoRef.origin = Coordinates.fromJson(json.origin);
60
+ geoRef.scale = json.scale;
61
+ geoRef.heading = json.heading;
62
+ return geoRef;
36
63
  }
37
64
  }
38
65