@wemap/geo 3.1.4 → 3.1.7
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.7",
|
|
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": "57ceac64e857a53046b297774286024a157a57af"
|
|
37
37
|
}
|
|
@@ -109,6 +109,26 @@ class BoundingBox {
|
|
|
109
109
|
return this;
|
|
110
110
|
}
|
|
111
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Returns bounds created by extending or retracting the current bounds by a given ratio in each direction.
|
|
114
|
+
* For example, a ratio of 0.5 extends the bounds by 50% in each direction.
|
|
115
|
+
* Negative values will retract the bounds.
|
|
116
|
+
* @param {Number} bufferRatio
|
|
117
|
+
* @returns {BoundingBox} `this`
|
|
118
|
+
*/
|
|
119
|
+
pad(bufferRatio) {
|
|
120
|
+
const sw = this.southWest;
|
|
121
|
+
const ne = this.northEast;
|
|
122
|
+
|
|
123
|
+
const heightBuffer = Math.abs(sw.lat - ne.lat) * bufferRatio;
|
|
124
|
+
const widthBuffer = Math.abs(sw.lng - ne.lng) * bufferRatio;
|
|
125
|
+
|
|
126
|
+
this.southWest = new Coordinates(sw.lat - heightBuffer, sw.lng - widthBuffer);
|
|
127
|
+
this.northEast = new Coordinates(ne.lat + heightBuffer, ne.lng + widthBuffer);
|
|
128
|
+
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
|
|
112
132
|
/**
|
|
113
133
|
* Returns the southwest corner of the bounding box.
|
|
114
134
|
*
|
|
@@ -189,6 +209,18 @@ class BoundingBox {
|
|
|
189
209
|
equalsTo(other) {
|
|
190
210
|
return BoundingBox.equalsTo(this, other);
|
|
191
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
|
+
}
|
|
192
224
|
}
|
|
193
225
|
|
|
194
226
|
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
|
|
|
@@ -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', () => {
|