@wemap/geo 0.2.1 → 0.3.1
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 +5 -4
- package/src/coordinates/Level.js +150 -36
- package/src/coordinates/Level.spec.js +164 -0
- package/src/coordinates/WGS84.js +17 -35
- package/src/coordinates/WGS84UserPosition.js +13 -6
- package/src/graph/Edge.js +8 -3
- package/src/graph/GraphRouter.js +1 -5
- package/src/graph/GraphRouter.spec.js +72 -0
- package/src/graph/Itinerary.js +294 -22
- package/src/graph/Itinerary.spec.js +168 -0
- package/src/graph/MapMatching.js +10 -1
- package/src/graph/MapMatching.spec.js +113 -57
- package/src/graph/Step.js +57 -0
- package/tests/CommonTest.js +57 -0
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"directory": "packages/geo"
|
|
13
13
|
},
|
|
14
14
|
"name": "@wemap/geo",
|
|
15
|
-
"version": "0.
|
|
15
|
+
"version": "0.3.1",
|
|
16
16
|
"bugs": {
|
|
17
17
|
"url": "https://github.com/wemap/wemap-utils-js/issues"
|
|
18
18
|
},
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
],
|
|
28
28
|
"license": "ISC",
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@wemap/maths": "^0.2.
|
|
31
|
-
"lodash.isnumber": "^3.0.3"
|
|
30
|
+
"@wemap/maths": "^0.2.1",
|
|
31
|
+
"lodash.isnumber": "^3.0.3",
|
|
32
|
+
"lodash.isstring": "^4.0.1"
|
|
32
33
|
},
|
|
33
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "7b84c9d55646761f75f19235a15be8a1b73b3dbf"
|
|
34
35
|
}
|
package/src/coordinates/Level.js
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import Logger from '@wemap/logger';
|
|
2
|
+
import isNumber from 'lodash/isnumber';
|
|
3
|
+
import isString from 'lodash/isstring';
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* A Level is the representation of a building floor number
|
|
@@ -7,18 +9,37 @@ import Logger from '@wemap/logger';
|
|
|
7
9
|
*/
|
|
8
10
|
class Level {
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Level constructor
|
|
14
|
+
* 1 argument: level is not a range and first argument is the level
|
|
15
|
+
* 2 arguments: level is a range
|
|
16
|
+
* @param {Number} arg1 if arg2: low value, otherwise: level
|
|
17
|
+
* @param {Number} arg2 (optional) up value
|
|
18
|
+
*/
|
|
19
|
+
constructor(arg1, arg2) {
|
|
20
|
+
if (!isNumber(arg1)) {
|
|
21
|
+
throw new Error('first argument is mandatory');
|
|
22
|
+
}
|
|
23
|
+
if (isNumber(arg2)) {
|
|
24
|
+
if (arg1 === arg2) {
|
|
25
|
+
this.isRange = false;
|
|
26
|
+
this.val = arg1;
|
|
27
|
+
} else {
|
|
28
|
+
this.isRange = true;
|
|
29
|
+
this.low = Math.min(arg1, arg2);
|
|
30
|
+
this.up = Math.max(arg1, arg2);
|
|
31
|
+
}
|
|
32
|
+
} else {
|
|
33
|
+
this.isRange = false;
|
|
34
|
+
this.val = arg1;
|
|
35
|
+
}
|
|
13
36
|
}
|
|
14
37
|
|
|
15
38
|
clone() {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
output.low = this.low;
|
|
21
|
-
return output;
|
|
39
|
+
if (this.isRange) {
|
|
40
|
+
return new Level(this.low, this.up);
|
|
41
|
+
}
|
|
42
|
+
return new Level(this.val);
|
|
22
43
|
}
|
|
23
44
|
|
|
24
45
|
/**
|
|
@@ -26,12 +47,13 @@ class Level {
|
|
|
26
47
|
* @param {*} str level in str format (eg. 1, -2, 1;2, -2;3, 2;-1, 0.5;1 ...)
|
|
27
48
|
*/
|
|
28
49
|
static fromString(str) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
50
|
+
|
|
51
|
+
if (!isString(str)) {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (!isNaN(Number(str))) {
|
|
56
|
+
return new Level(Number(str));
|
|
35
57
|
}
|
|
36
58
|
|
|
37
59
|
const splited = str.split(';');
|
|
@@ -39,10 +61,7 @@ class Level {
|
|
|
39
61
|
const num1 = Number(splited[0]);
|
|
40
62
|
const num2 = Number(splited[1]);
|
|
41
63
|
if (!isNaN(num1) && !isNaN(num2)) {
|
|
42
|
-
|
|
43
|
-
level.low = Math.min(num1, num2);
|
|
44
|
-
level.isRange = true;
|
|
45
|
-
return level;
|
|
64
|
+
return new Level(num1, num2);
|
|
46
65
|
}
|
|
47
66
|
}
|
|
48
67
|
|
|
@@ -63,31 +82,95 @@ class Level {
|
|
|
63
82
|
* @param {Level} other The other level
|
|
64
83
|
*/
|
|
65
84
|
intersect(other) {
|
|
85
|
+
return Level.intersect(this, other);
|
|
86
|
+
}
|
|
66
87
|
|
|
67
|
-
|
|
68
|
-
|
|
88
|
+
/**
|
|
89
|
+
* Retrieve the intersection of two levels
|
|
90
|
+
* @param {Level} other The other level
|
|
91
|
+
*/
|
|
92
|
+
static intersect(first, second) {
|
|
93
|
+
|
|
94
|
+
if (first === second) {
|
|
95
|
+
return first;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!second) {
|
|
99
|
+
return first;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (!first) {
|
|
103
|
+
return second;
|
|
69
104
|
}
|
|
70
105
|
|
|
71
|
-
if (
|
|
72
|
-
if (
|
|
73
|
-
return
|
|
106
|
+
if (first.isRange && !second.isRange) {
|
|
107
|
+
if (first.isInside(second.val)) {
|
|
108
|
+
return second;
|
|
74
109
|
}
|
|
75
110
|
return null;
|
|
76
111
|
}
|
|
77
|
-
if (!
|
|
78
|
-
if (
|
|
79
|
-
return
|
|
112
|
+
if (!first.isRange && second.isRange) {
|
|
113
|
+
if (second.isInside(first.val)) {
|
|
114
|
+
return first;
|
|
80
115
|
}
|
|
81
|
-
return
|
|
116
|
+
return first;
|
|
82
117
|
}
|
|
83
|
-
if (
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
118
|
+
if (first.isRange && second.isRange) {
|
|
119
|
+
const up = Math.min(first.up, second.up);
|
|
120
|
+
const low = Math.max(first.low, second.low);
|
|
121
|
+
if (up < low) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return new Level(low, up);
|
|
89
125
|
}
|
|
90
|
-
return
|
|
126
|
+
return first.val === second.val ? first : null;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Retrieve the union of two levels
|
|
131
|
+
* @param {Level} other The other level
|
|
132
|
+
*/
|
|
133
|
+
union(other) {
|
|
134
|
+
return Level.union(this, other);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Retrieve the union of two levels
|
|
139
|
+
* @param {Level} other The other level
|
|
140
|
+
*/
|
|
141
|
+
static union(first, second) {
|
|
142
|
+
|
|
143
|
+
if (first === second) {
|
|
144
|
+
return first;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (!second) {
|
|
148
|
+
return first;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!first) {
|
|
152
|
+
return second;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
let low, up;
|
|
156
|
+
if (!first.isRange && !second.isRange) {
|
|
157
|
+
low = Math.min(first.val, second.val);
|
|
158
|
+
up = Math.max(first.val, second.val);
|
|
159
|
+
} else if (first.isRange && !second.isRange) {
|
|
160
|
+
low = Math.min(first.low, second.val);
|
|
161
|
+
up = Math.max(first.up, second.val);
|
|
162
|
+
} else if (!first.isRange && second.isRange) {
|
|
163
|
+
low = Math.min(second.low, first.val);
|
|
164
|
+
up = Math.max(second.up, first.val);
|
|
165
|
+
} else if (first.isRange && second.isRange) {
|
|
166
|
+
low = Math.min(second.low, first.low);
|
|
167
|
+
up = Math.max(second.up, first.up);
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (low === up) {
|
|
171
|
+
return new Level(low);
|
|
172
|
+
}
|
|
173
|
+
return new Level(low, up);
|
|
91
174
|
}
|
|
92
175
|
|
|
93
176
|
multiplyBy(factor) {
|
|
@@ -100,7 +183,38 @@ class Level {
|
|
|
100
183
|
}
|
|
101
184
|
|
|
102
185
|
toString() {
|
|
103
|
-
return this.isRange ? this.low + ';' + this.up : this.val;
|
|
186
|
+
return this.isRange ? this.low + ';' + this.up : String(this.val);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
static equalsTo(first, second) {
|
|
190
|
+
|
|
191
|
+
if (first === second) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
if (!first && !second) {
|
|
195
|
+
return true;
|
|
196
|
+
}
|
|
197
|
+
if (!first && second) {
|
|
198
|
+
return false;
|
|
199
|
+
}
|
|
200
|
+
if (first && !second) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
if (!first.isRange && second.isRange) {
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
if (first.isRange && !second.isRange) {
|
|
207
|
+
return false;
|
|
208
|
+
}
|
|
209
|
+
if (first.isRange && second.isRange) {
|
|
210
|
+
return first.low === second.low && first.up === second.up;
|
|
211
|
+
}
|
|
212
|
+
if (!first.isRange && !second.isRange) {
|
|
213
|
+
return first.val === second.val;
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Should never happen.
|
|
217
|
+
return false;
|
|
104
218
|
}
|
|
105
219
|
|
|
106
220
|
}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/* eslint-disable max-nested-callbacks */
|
|
2
|
+
import { expect } from 'chai';
|
|
3
|
+
|
|
4
|
+
import Level from './Level';
|
|
5
|
+
import Logger from '@wemap/logger';
|
|
6
|
+
|
|
7
|
+
Logger.enable(false);
|
|
8
|
+
|
|
9
|
+
const checkSingle = (_level, _value) => {
|
|
10
|
+
expect(_level.isRange).false;
|
|
11
|
+
expect(_level.val).equals(_value);
|
|
12
|
+
expect(_level.low).undefined;
|
|
13
|
+
expect(_level.up).undefined;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const checkRange = (_level, _value1, _value2) => {
|
|
17
|
+
expect(_level.isRange).true;
|
|
18
|
+
expect(_level.val).undefined;
|
|
19
|
+
expect(_level.low).equals(Math.min(_value1, _value2));
|
|
20
|
+
expect(_level.up).equals(Math.max(_value1, _value2));
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
describe('Level', () => {
|
|
25
|
+
|
|
26
|
+
it('creation', () => {
|
|
27
|
+
|
|
28
|
+
const listOfInvalidLevel = ['toto', true, false, NaN, null];
|
|
29
|
+
const listOfValidLevel = [-1, 1, 0, 1.5, -2.3];
|
|
30
|
+
const listOfLevels = [].concat(listOfInvalidLevel, listOfValidLevel);
|
|
31
|
+
|
|
32
|
+
listOfLevels.forEach(value1 => {
|
|
33
|
+
if (listOfInvalidLevel.includes(value1)) {
|
|
34
|
+
expect(() => new Level(value1)).is.throw;
|
|
35
|
+
} else {
|
|
36
|
+
checkSingle(new Level(value1), value1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
listOfLevels.forEach(value2 => {
|
|
40
|
+
if (listOfInvalidLevel.includes(value1)
|
|
41
|
+
|| listOfInvalidLevel.includes(value2)) {
|
|
42
|
+
expect(() => new Level(value1, value2)).is.throw;
|
|
43
|
+
expect(() => new Level(value2, value1)).is.throw;
|
|
44
|
+
} else if (value1 === value2) {
|
|
45
|
+
checkSingle(new Level(value1), value1);
|
|
46
|
+
} else {
|
|
47
|
+
checkRange(new Level(value1, value2), value1, value2);
|
|
48
|
+
checkRange(new Level(value2, value1), value1, value2);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it('fromString', () => {
|
|
57
|
+
const listOfInvalidLevel = ['toto', 'toto;toto', '1;toto', 'toto;1',
|
|
58
|
+
true, false, NaN, null];
|
|
59
|
+
|
|
60
|
+
listOfInvalidLevel.forEach(value1 => {
|
|
61
|
+
expect(Level.fromString(value1)).is.null;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
checkSingle(Level.fromString('0'), 0);
|
|
65
|
+
checkSingle(Level.fromString('1'), 1);
|
|
66
|
+
checkSingle(Level.fromString('-1'), -1);
|
|
67
|
+
checkSingle(Level.fromString('1.5'), 1.5);
|
|
68
|
+
checkSingle(Level.fromString('-1.5'), -1.5);
|
|
69
|
+
checkRange(Level.fromString('0;1'), 0, 1);
|
|
70
|
+
checkRange(Level.fromString('1;0'), 0, 1);
|
|
71
|
+
checkSingle(Level.fromString('1;1'), 1);
|
|
72
|
+
checkRange(Level.fromString('-1;0'), -1, 0);
|
|
73
|
+
checkRange(Level.fromString('-1;1'), -1, 1);
|
|
74
|
+
checkSingle(Level.fromString('-1;-1'), -1);
|
|
75
|
+
checkRange(Level.fromString('-1;1.5'), -1, 1.5);
|
|
76
|
+
checkRange(Level.fromString('-1.5;1'), -1.5, 1);
|
|
77
|
+
checkRange(Level.fromString('-1.5;1.5'), -1.5, 1.5);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
it('toString', () => {
|
|
82
|
+
expect(new Level(0).toString()).equals('0');
|
|
83
|
+
expect(new Level(1).toString()).equals('1');
|
|
84
|
+
expect(new Level(-1).toString()).equals('-1');
|
|
85
|
+
expect(new Level(1.5).toString()).equals('1.5');
|
|
86
|
+
expect(new Level(-1.5).toString()).equals('-1.5');
|
|
87
|
+
expect(new Level(0, 1).toString()).equals('0;1');
|
|
88
|
+
expect(new Level(1, 0).toString()).equals('0;1');
|
|
89
|
+
expect(new Level(1, 1).toString()).equals('1');
|
|
90
|
+
expect(new Level(-1, 0).toString()).equals('-1;0');
|
|
91
|
+
expect(new Level(-1, 1).toString()).equals('-1;1');
|
|
92
|
+
expect(new Level(-1, -1).toString()).equals('-1');
|
|
93
|
+
expect(new Level(-1, 1.5).toString()).equals('-1;1.5');
|
|
94
|
+
expect(new Level(-1.5, 1).toString()).equals('-1.5;1');
|
|
95
|
+
expect(new Level(-1.5, 1.5).toString()).equals('-1.5;1.5');
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it('equalsTo', () => {
|
|
99
|
+
const level = new Level(1);
|
|
100
|
+
expect(Level.equalsTo(null, null)).true;
|
|
101
|
+
expect(Level.equalsTo(level, level)).true;
|
|
102
|
+
expect(Level.equalsTo(level, null)).false;
|
|
103
|
+
expect(Level.equalsTo(null, level)).false;
|
|
104
|
+
expect(Level.equalsTo(new Level(1), new Level(1))).true;
|
|
105
|
+
expect(Level.equalsTo(new Level(-1), new Level(1))).false;
|
|
106
|
+
expect(Level.equalsTo(new Level(1), new Level(0, 1))).false;
|
|
107
|
+
expect(Level.equalsTo(new Level(0, 1), new Level(1))).false;
|
|
108
|
+
expect(Level.equalsTo(new Level(1), new Level(1, 1))).true;
|
|
109
|
+
expect(Level.equalsTo(new Level(1, 0), new Level(1, 0))).true;
|
|
110
|
+
expect(Level.equalsTo(new Level(0, 1), new Level(1, 0))).true;
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('clone', () => {
|
|
114
|
+
expect(Level.equalsTo(new Level(0).clone(), new Level(0))).true;
|
|
115
|
+
expect(Level.equalsTo(new Level(1).clone(), new Level(1))).true;
|
|
116
|
+
expect(Level.equalsTo(new Level(-1).clone(), new Level(-1))).true;
|
|
117
|
+
expect(Level.equalsTo(new Level(0, 1).clone(), new Level(0, 1))).true;
|
|
118
|
+
expect(Level.equalsTo(new Level(1, 0).clone(), new Level(1, 0))).true;
|
|
119
|
+
expect(Level.equalsTo(new Level(-1.5, 1).clone(), new Level(-1.5, 1))).true;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('intersect', () => {
|
|
123
|
+
expect(Level.intersect(null, null)).is.null;
|
|
124
|
+
|
|
125
|
+
const level = new Level(1);
|
|
126
|
+
expect(Level.intersect(level, null)).equals(level);
|
|
127
|
+
expect(Level.intersect(null, level)).equals(level);
|
|
128
|
+
expect(Level.intersect(level, level)).equals(level);
|
|
129
|
+
|
|
130
|
+
expect(Level.equalsTo(Level.intersect(new Level(0, 1), new Level(1)), new Level(1)));
|
|
131
|
+
expect(Level.equalsTo(Level.intersect(new Level(0, 2), new Level(1)), new Level(1)));
|
|
132
|
+
expect(Level.equalsTo(Level.intersect(new Level(-1, 2), new Level(1)), new Level(1)));
|
|
133
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(0, 1)), new Level(1)));
|
|
134
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(0, 2)), new Level(1)));
|
|
135
|
+
expect(Level.equalsTo(Level.intersect(new Level(1), new Level(-1, 2)), new Level(1)));
|
|
136
|
+
expect(Level.equalsTo(Level.intersect(new Level(1, 2), new Level(-1, 2)), new Level(1, 2)));
|
|
137
|
+
expect(Level.equalsTo(Level.intersect(new Level(-3, 1), new Level(-1, 2)), new Level(-1, 1)));
|
|
138
|
+
expect(Level.equalsTo(Level.intersect(new Level(-3, -1), new Level(-1, 2)), new Level(-1)));
|
|
139
|
+
expect(Level.intersect(new Level(-3, -2), new Level(-1, 2))).is.null;
|
|
140
|
+
expect(Level.intersect(new Level(-1, 2), new Level(-3, -2))).is.null;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it('union', () => {
|
|
144
|
+
expect(Level.union(null, null)).is.null;
|
|
145
|
+
|
|
146
|
+
const level = new Level(1);
|
|
147
|
+
expect(Level.union(level, null)).equals(level);
|
|
148
|
+
expect(Level.union(null, level)).equals(level);
|
|
149
|
+
expect(Level.union(level, level)).equals(level);
|
|
150
|
+
|
|
151
|
+
expect(Level.equalsTo(Level.union(new Level(0, 1), new Level(1)), new Level(0, 1)));
|
|
152
|
+
expect(Level.equalsTo(Level.union(new Level(0, 2), new Level(1)), new Level(0, 2)));
|
|
153
|
+
expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(1)), new Level(-1, 2)));
|
|
154
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(0, 1)), new Level(0, 1)));
|
|
155
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(0, 2)), new Level(0, 2)));
|
|
156
|
+
expect(Level.equalsTo(Level.union(new Level(1), new Level(-1, 2)), new Level(-1, 2)));
|
|
157
|
+
expect(Level.equalsTo(Level.union(new Level(1, 2), new Level(-1, 2)), new Level(-1, 2)));
|
|
158
|
+
expect(Level.equalsTo(Level.union(new Level(-3, 1), new Level(-1, 2)), new Level(-3, 2)));
|
|
159
|
+
expect(Level.equalsTo(Level.union(new Level(-3, -1), new Level(-1, 2)), new Level(-3, 2)));
|
|
160
|
+
expect(Level.equalsTo(Level.union(new Level(-3, -2), new Level(-1, 2)), new Level(-3, 2)));
|
|
161
|
+
expect(Level.equalsTo(Level.union(new Level(-1, 2), new Level(-3, -2)), new Level(-3, 2)));
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
});
|
package/src/coordinates/WGS84.js
CHANGED
|
@@ -3,14 +3,7 @@ import {
|
|
|
3
3
|
} from '@wemap/maths';
|
|
4
4
|
import Constants from '../Constants';
|
|
5
5
|
import isNumber from 'lodash/isnumber';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* JSON output formats:
|
|
9
|
-
* - FORMAT_LAT_LNG_ELE (default)
|
|
10
|
-
* - FORMAT_LNG_LAT_STRLEVEL
|
|
11
|
-
*/
|
|
12
|
-
const FORMAT_LAT_LNG_ELE = 0;
|
|
13
|
-
const FORMAT_LNG_LAT_STRLEVEL = 1;
|
|
6
|
+
import Level from './Level';
|
|
14
7
|
|
|
15
8
|
/**
|
|
16
9
|
* A WGS84 position using at least latitude (lat) and longitude (lng).
|
|
@@ -21,11 +14,11 @@ const FORMAT_LNG_LAT_STRLEVEL = 1;
|
|
|
21
14
|
*/
|
|
22
15
|
class WGS84 {
|
|
23
16
|
|
|
24
|
-
constructor(lat, lng, alt) {
|
|
17
|
+
constructor(lat, lng, alt, level) {
|
|
25
18
|
this._lat = lat;
|
|
26
19
|
this._lng = lng;
|
|
27
20
|
this._alt = alt;
|
|
28
|
-
this._level =
|
|
21
|
+
this._level = level;
|
|
29
22
|
this._ecef = null;
|
|
30
23
|
}
|
|
31
24
|
|
|
@@ -78,7 +71,7 @@ class WGS84 {
|
|
|
78
71
|
return false;
|
|
79
72
|
}
|
|
80
73
|
|
|
81
|
-
return other.lat === this.lat && other.lng === this.lng;
|
|
74
|
+
return other.lat === this.lat && other.lng === this.lng && Level.equalsTo(other.level, this.level);
|
|
82
75
|
}
|
|
83
76
|
|
|
84
77
|
toString() {
|
|
@@ -86,21 +79,13 @@ class WGS84 {
|
|
|
86
79
|
if (this._alt) {
|
|
87
80
|
str += ', ' + this._alt.toFixed(2);
|
|
88
81
|
}
|
|
82
|
+
if (this._level) {
|
|
83
|
+
str += ', [' + this._level.toString() + ']';
|
|
84
|
+
}
|
|
89
85
|
str += ']';
|
|
90
86
|
return str;
|
|
91
87
|
}
|
|
92
88
|
|
|
93
|
-
toJson(format = FORMAT_LAT_LNG_ELE) {
|
|
94
|
-
switch (format) {
|
|
95
|
-
case FORMAT_LNG_LAT_STRLEVEL:
|
|
96
|
-
return [this.lng, this.lat, this.level ? this.level.toString() : null];
|
|
97
|
-
|
|
98
|
-
case FORMAT_LAT_LNG_ELE:
|
|
99
|
-
default:
|
|
100
|
-
return [this.lat, this.lng, this.ele];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
89
|
destinationPoint(distance, bearing, elevation = 0) {
|
|
105
90
|
const newPoint = this.clone();
|
|
106
91
|
newPoint.move(distance, bearing, elevation);
|
|
@@ -279,15 +264,21 @@ class WGS84 {
|
|
|
279
264
|
}
|
|
280
265
|
|
|
281
266
|
toMessage() {
|
|
282
|
-
|
|
267
|
+
const output = {
|
|
283
268
|
lat: this.lat,
|
|
284
|
-
lng: this.lng
|
|
285
|
-
alt: this.alt
|
|
269
|
+
lng: this.lng
|
|
286
270
|
};
|
|
271
|
+
if (isNumber(this.alt)) {
|
|
272
|
+
output.alt = this.alt;
|
|
273
|
+
}
|
|
274
|
+
if (this.level) {
|
|
275
|
+
output.level = this.level;
|
|
276
|
+
}
|
|
277
|
+
return output;
|
|
287
278
|
}
|
|
288
279
|
|
|
289
280
|
static fromMessage(message) {
|
|
290
|
-
return new WGS84(message.lat, message.lng, message.alt);
|
|
281
|
+
return new WGS84(message.lat, message.lng, message.alt, Level.fromString(message.level));
|
|
291
282
|
}
|
|
292
283
|
|
|
293
284
|
static fromPinpoint(pinpoint) {
|
|
@@ -329,15 +320,6 @@ class WGS84 {
|
|
|
329
320
|
|
|
330
321
|
return sampledRoute;
|
|
331
322
|
}
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
static get FORMAT_LNG_LAT_STRLEVEL() {
|
|
335
|
-
return FORMAT_LNG_LAT_STRLEVEL;
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
static get FORMAT_LAT_LNG_ELE() {
|
|
339
|
-
return FORMAT_LAT_LNG_ELE;
|
|
340
|
-
}
|
|
341
323
|
}
|
|
342
324
|
|
|
343
325
|
export default WGS84;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import WGS84 from './WGS84';
|
|
2
|
+
import Level from './Level';
|
|
2
3
|
|
|
3
4
|
const MESSAGE_TYPE = 'WGS84UserPosition';
|
|
4
5
|
|
|
@@ -7,9 +8,9 @@ const MESSAGE_TYPE = 'WGS84UserPosition';
|
|
|
7
8
|
*/
|
|
8
9
|
class WGS84UserPosition extends WGS84 {
|
|
9
10
|
|
|
10
|
-
constructor(lat, lng, alt = null, time = null,
|
|
11
|
+
constructor(lat, lng, alt = null, level = null, time = null,
|
|
11
12
|
accuracy = null, bearing = null, provider = null) {
|
|
12
|
-
super(lat, lng, alt);
|
|
13
|
+
super(lat, lng, alt, level);
|
|
13
14
|
this.bearing = bearing;
|
|
14
15
|
this.provider = provider;
|
|
15
16
|
this.time = time;
|
|
@@ -21,15 +22,20 @@ class WGS84UserPosition extends WGS84 {
|
|
|
21
22
|
static fromWGS84(wgs84Coordinates, userPosition) {
|
|
22
23
|
|
|
23
24
|
if (userPosition) {
|
|
24
|
-
return new WGS84UserPosition(
|
|
25
|
-
|
|
25
|
+
return new WGS84UserPosition(
|
|
26
|
+
wgs84Coordinates.lat, wgs84Coordinates.lng,
|
|
27
|
+
wgs84Coordinates.alt, wgs84Coordinates.level,
|
|
28
|
+
userPosition.time, userPosition.accuracy,
|
|
29
|
+
userPosition.bearing, userPosition.provider);
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
return new WGS84UserPosition(wgs84Coordinates.lat, wgs84Coordinates.lng,
|
|
32
|
+
return new WGS84UserPosition(wgs84Coordinates.lat, wgs84Coordinates.lng,
|
|
33
|
+
wgs84Coordinates.alt, wgs84Coordinates.level);
|
|
29
34
|
}
|
|
30
35
|
|
|
31
36
|
clone() {
|
|
32
|
-
return new WGS84UserPosition(this.lat, this.lng, this.alt, this.
|
|
37
|
+
return new WGS84UserPosition(this.lat, this.lng, this.alt, this.level,
|
|
38
|
+
this.time, this.accuracy, this.bearing, this.provider);
|
|
33
39
|
}
|
|
34
40
|
|
|
35
41
|
static get MESSAGE_TYPE() {
|
|
@@ -48,6 +54,7 @@ class WGS84UserPosition extends WGS84 {
|
|
|
48
54
|
|
|
49
55
|
static fromMessage(message) {
|
|
50
56
|
return new WGS84UserPosition(message.lat, message.lng, message.alt,
|
|
57
|
+
Level.fromString(message.level),
|
|
51
58
|
message.time, message.accuracy, message.bearing, message.provider);
|
|
52
59
|
}
|
|
53
60
|
}
|
package/src/graph/Edge.js
CHANGED
|
@@ -7,7 +7,7 @@ import Node from './Node';
|
|
|
7
7
|
*/
|
|
8
8
|
class Edge {
|
|
9
9
|
|
|
10
|
-
constructor(node1, node2, data) {
|
|
10
|
+
constructor(node1, node2, data, level) {
|
|
11
11
|
|
|
12
12
|
if (!(node1 instanceof Node)) {
|
|
13
13
|
throw new TypeError('node1 is not an instance of Node');
|
|
@@ -20,7 +20,10 @@ class Edge {
|
|
|
20
20
|
this.node1 = node1;
|
|
21
21
|
this.node2 = node2;
|
|
22
22
|
this.data = data;
|
|
23
|
-
this.level =
|
|
23
|
+
this.level = level;
|
|
24
|
+
|
|
25
|
+
this.node1.edges.push(this);
|
|
26
|
+
this.node2.edges.push(this);
|
|
24
27
|
|
|
25
28
|
this.computedSizeAndBearing = false;
|
|
26
29
|
}
|
|
@@ -61,7 +64,9 @@ class Edge {
|
|
|
61
64
|
}
|
|
62
65
|
|
|
63
66
|
clone(node1, node2) {
|
|
64
|
-
|
|
67
|
+
const edge = new Edge(node1, node2, this.data);
|
|
68
|
+
edge.level = this.level;
|
|
69
|
+
return edge;
|
|
65
70
|
}
|
|
66
71
|
}
|
|
67
72
|
|
package/src/graph/GraphRouter.js
CHANGED
|
@@ -107,9 +107,6 @@ class GraphRouter {
|
|
|
107
107
|
v.level = edge.level;
|
|
108
108
|
v.data = edge.data;
|
|
109
109
|
|
|
110
|
-
m.edges.push(u, v);
|
|
111
|
-
a.edges.push(u);
|
|
112
|
-
b.edges.push(v);
|
|
113
110
|
a.edges = a.edges.filter(_edge => _edge !== edge);
|
|
114
111
|
b.edges = b.edges.filter(_edge => _edge !== edge);
|
|
115
112
|
|
|
@@ -132,9 +129,8 @@ class GraphRouter {
|
|
|
132
129
|
|
|
133
130
|
const oldEdge = new Edge(u.node1, v.node1);
|
|
134
131
|
oldEdge.data = u.data;
|
|
132
|
+
oldEdge.level = u.level;
|
|
135
133
|
this.network.edges.push(oldEdge);
|
|
136
|
-
u.node1.edges.push(oldEdge);
|
|
137
|
-
v.node1.edges.push(oldEdge);
|
|
138
134
|
|
|
139
135
|
this.network.nodes = this.network.nodes.filter(node => node !== _node);
|
|
140
136
|
this.network.edges = this.network.edges.filter(
|