@wemap/geo 3.1.6 → 3.1.8
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": "3.1.
|
|
15
|
+
"version": "3.1.8",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
18
18
|
},
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"lodash.isnumber": "^3.0.3",
|
|
34
34
|
"lodash.isstring": "^4.0.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9e4ca5d422005858eca036b3e98ea3f854231fd0"
|
|
37
37
|
}
|
|
@@ -209,6 +209,26 @@ class BoundingBox {
|
|
|
209
209
|
equalsTo(other) {
|
|
210
210
|
return BoundingBox.equalsTo(this, other);
|
|
211
211
|
}
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Create a BoundingBox from a WSEN array
|
|
215
|
+
* @param {Number[4]} bounds a WSEN array
|
|
216
|
+
* @returns {BoundingBox} the corresponding BoundingBox
|
|
217
|
+
*/
|
|
218
|
+
static fromArray(bounds) {
|
|
219
|
+
return new BoundingBox(
|
|
220
|
+
new Coordinates(bounds[3], bounds[2]),
|
|
221
|
+
new Coordinates(bounds[1], bounds[0])
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Returns the WSEN array
|
|
227
|
+
* @returns {Number[4]} the WSEN array
|
|
228
|
+
*/
|
|
229
|
+
toArray() {
|
|
230
|
+
return [this.getWest(), this.getSouth(), this.getEast(), this.getNorth()];
|
|
231
|
+
}
|
|
212
232
|
}
|
|
213
233
|
|
|
214
234
|
export default BoundingBox;
|
|
@@ -33,6 +33,9 @@ describe('Bounding Box', () => {
|
|
|
33
33
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
34
34
|
expect(boundingBox.northEast).equals(northEast);
|
|
35
35
|
expect(boundingBox.southWest).equals(southWest);
|
|
36
|
+
|
|
37
|
+
const boundingBox2 = BoundingBox.fromArray([-20, -5, 40, 10]);
|
|
38
|
+
expect(boundingBox2.equalsTo(boundingBox)).is.true;
|
|
36
39
|
});
|
|
37
40
|
|
|
38
41
|
|
|
@@ -52,7 +55,6 @@ describe('Bounding Box', () => {
|
|
|
52
55
|
))).false;
|
|
53
56
|
});
|
|
54
57
|
|
|
55
|
-
|
|
56
58
|
it('bounds', () => {
|
|
57
59
|
boundingBox = new BoundingBox(northEast, southWest);
|
|
58
60
|
expect(boundingBox.getNorth()).equals(northEast.lat);
|
|
@@ -170,5 +172,7 @@ describe('Bounding Box', () => {
|
|
|
170
172
|
.be.closeTo(measure, 0.05 * measure);
|
|
171
173
|
});
|
|
172
174
|
|
|
173
|
-
|
|
175
|
+
it('toArray', () => {
|
|
176
|
+
expect(new BoundingBox(northEast, southWest).toArray()).deep.equals([-20, -5, 40, 10]);
|
|
177
|
+
});
|
|
174
178
|
});
|
|
@@ -57,10 +57,18 @@ class Coordinates {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
set lng(lng) {
|
|
60
|
-
if (isNumber(lng)
|
|
60
|
+
if (isNumber(lng)) {
|
|
61
61
|
this._lng = lng;
|
|
62
|
+
if (Math.abs(lng) >= 180) {
|
|
63
|
+
// from https://stackoverflow.com/a/2323034/2239938
|
|
64
|
+
this._lng = this._lng % 360;
|
|
65
|
+
this._lng = (this._lng + 360) % 360;
|
|
66
|
+
if (this._lng > 180) {
|
|
67
|
+
this._lng -= 360;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
62
70
|
} else {
|
|
63
|
-
throw new Error('lng argument is not
|
|
71
|
+
throw new Error('lng argument is not a number');
|
|
64
72
|
}
|
|
65
73
|
this._ecef = null;
|
|
66
74
|
}
|
|
@@ -17,7 +17,7 @@ describe('Coordinates', () => {
|
|
|
17
17
|
expect(() => new Coordinates(45)).throw(Error);
|
|
18
18
|
expect(() => new Coordinates(45, 5)).not.throw(Error);
|
|
19
19
|
expect(() => new Coordinates(-93, 5)).throw(Error);
|
|
20
|
-
expect(() => new Coordinates(45, 202)).throw(Error);
|
|
20
|
+
expect(() => new Coordinates(45, 202)).not.throw(Error);
|
|
21
21
|
|
|
22
22
|
expect(() => new Coordinates(45, 5, true)).throw(Error);
|
|
23
23
|
expect(() => new Coordinates(45, 5, false)).throw(Error);
|
|
@@ -52,6 +52,12 @@ describe('Coordinates', () => {
|
|
|
52
52
|
expect(Level.equalsTo(position.level, new Level(2))).true;
|
|
53
53
|
expect(position._ecef).equals(null);
|
|
54
54
|
expect(position.ecef).is.not.null;
|
|
55
|
+
|
|
56
|
+
position.lng = 202;
|
|
57
|
+
expect(position.lng).equals(-158);
|
|
58
|
+
|
|
59
|
+
position.lng = -202;
|
|
60
|
+
expect(position.lng).equals(158);
|
|
55
61
|
});
|
|
56
62
|
|
|
57
63
|
it('clone', () => {
|