@wemap/geo 3.0.0 → 3.1.6
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 +2 -2
- package/src/Constants.js +1 -0
- package/src/coordinates/BoundingBox.js +20 -0
- package/src/coordinates/Level.js +41 -6
- package/src/coordinates/Level.spec.js +30 -12
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/geo"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/geo",
|
|
15
|
-
"version": "3.
|
|
15
|
+
"version": "3.1.6",
|
|
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": "f7967fd5b465e1e2be1c575ef0f2150adde4825f"
|
|
37
37
|
}
|
package/src/Constants.js
CHANGED
|
@@ -24,5 +24,6 @@ Constants.R_MAJOR_4 = Constants.R_MAJOR_2 * Constants.R_MAJOR_2;
|
|
|
24
24
|
Constants.R_MINOR_2 = Constants.R_MINOR * Constants.R_MINOR;
|
|
25
25
|
Constants.R_MINOR_4 = Constants.R_MINOR_2 * Constants.R_MINOR_2;
|
|
26
26
|
Constants.ECCENTRICITY_2 = Constants.ECCENTRICITY * Constants.ECCENTRICITY;
|
|
27
|
+
Constants.CIRCUMFERENCE = Constants.R_MAJOR * 2 * Math.PI;
|
|
27
28
|
|
|
28
29
|
export default Constants;
|
|
@@ -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
|
*
|
package/src/coordinates/Level.js
CHANGED
|
@@ -72,11 +72,46 @@ class Level {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
/**
|
|
75
|
-
*
|
|
76
|
-
* @param {
|
|
75
|
+
* Returns if the level is inside the given level
|
|
76
|
+
* @param {Level} level the container level
|
|
77
77
|
*/
|
|
78
|
-
isInside(
|
|
79
|
-
return
|
|
78
|
+
isInside(level) {
|
|
79
|
+
return Level.contains(level, this);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Returns if the level is inside the given level
|
|
84
|
+
* @param {Level} level the container level
|
|
85
|
+
*/
|
|
86
|
+
contains(level) {
|
|
87
|
+
return Level.contains(this, level);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Returns if a level is contained in another
|
|
93
|
+
* @param {Level} container The container level
|
|
94
|
+
* @param {Level} targeted The targeted level
|
|
95
|
+
*/
|
|
96
|
+
static contains(container, targeted) {
|
|
97
|
+
|
|
98
|
+
if (container === targeted) {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!container || !targeted) {
|
|
103
|
+
return false;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (!container.isRange) {
|
|
107
|
+
if (targeted.isRange) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return container.val === targeted.val;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return container.up >= (targeted.isRange ? targeted.up : targeted.val)
|
|
114
|
+
&& container.low <= (targeted.isRange ? targeted.low : targeted.val);
|
|
80
115
|
}
|
|
81
116
|
|
|
82
117
|
/**
|
|
@@ -110,13 +145,13 @@ class Level {
|
|
|
110
145
|
}
|
|
111
146
|
|
|
112
147
|
if (first.isRange && !second.isRange) {
|
|
113
|
-
if (first.
|
|
148
|
+
if (first.contains(second)) {
|
|
114
149
|
return second.clone();
|
|
115
150
|
}
|
|
116
151
|
return null;
|
|
117
152
|
}
|
|
118
153
|
if (!first.isRange && second.isRange) {
|
|
119
|
-
if (second.
|
|
154
|
+
if (second.contains(first)) {
|
|
120
155
|
return first.clone();
|
|
121
156
|
}
|
|
122
157
|
return null;
|
|
@@ -120,20 +120,38 @@ describe('Level', () => {
|
|
|
120
120
|
expect(Level.equalsTo(new Level(-1.5, 1).clone(), new Level(-1.5, 1))).true;
|
|
121
121
|
});
|
|
122
122
|
|
|
123
|
-
it('
|
|
124
|
-
expect(
|
|
125
|
-
expect(new Level(
|
|
126
|
-
expect(new Level(
|
|
127
|
-
|
|
128
|
-
expect(new Level(0)
|
|
129
|
-
expect(new Level(
|
|
130
|
-
expect(new Level(
|
|
131
|
-
expect(new Level(0,
|
|
132
|
-
expect(new Level(
|
|
133
|
-
expect(new Level(2, 0)
|
|
134
|
-
expect(new Level(2,
|
|
123
|
+
it('contains', () => {
|
|
124
|
+
expect(Level.contains(null, null)).true;
|
|
125
|
+
expect(Level.contains(new Level(0), null)).false;
|
|
126
|
+
expect(Level.contains(null, new Level(0))).false;
|
|
127
|
+
|
|
128
|
+
expect(Level.contains(new Level(0), new Level(0))).true;
|
|
129
|
+
expect(Level.contains(new Level(1), new Level(0))).false;
|
|
130
|
+
expect(Level.contains(new Level(-1), new Level(0))).false;
|
|
131
|
+
expect(Level.contains(new Level(0), new Level(1))).false;
|
|
132
|
+
expect(Level.contains(new Level(0), new Level(-1))).false;
|
|
133
|
+
expect(Level.contains(new Level(0, 2), new Level(0))).true;
|
|
134
|
+
expect(Level.contains(new Level(0, 2), new Level(1))).true;
|
|
135
|
+
expect(Level.contains(new Level(0, 2), new Level(-1))).false;
|
|
136
|
+
expect(Level.contains(new Level(2, 0), new Level(0))).true;
|
|
137
|
+
expect(Level.contains(new Level(2, 0), new Level(1))).true;
|
|
138
|
+
expect(Level.contains(new Level(2, 0), new Level(-1))).false;
|
|
139
|
+
|
|
140
|
+
expect(Level.contains(new Level(0), new Level(0, 1))).false;
|
|
141
|
+
expect(Level.contains(new Level(1), new Level(0, 1))).false;
|
|
142
|
+
expect(Level.contains(new Level(1), new Level(0, 2))).false;
|
|
143
|
+
|
|
144
|
+
expect(Level.contains(new Level(0, 1), new Level(0, 1))).true;
|
|
145
|
+
expect(Level.contains(new Level(0, 1), new Level(0, 2))).false;
|
|
146
|
+
expect(Level.contains(new Level(0, 2), new Level(0, 1))).true;
|
|
147
|
+
expect(Level.contains(new Level(0, 3), new Level(1, 2))).true;
|
|
148
|
+
expect(Level.contains(new Level(1, 2), new Level(0, 3))).false;
|
|
149
|
+
|
|
150
|
+
expect(new Level(0).isInside(new Level(0, 1))).true;
|
|
151
|
+
|
|
135
152
|
});
|
|
136
153
|
|
|
154
|
+
|
|
137
155
|
it('intersect', () => {
|
|
138
156
|
expect(Level.intersect(null, null)).is.null;
|
|
139
157
|
|