@wemap/osm 5.8.0 → 6.2.2

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.
Files changed (59) hide show
  1. package/dist/wemap-osm.es.js +2 -1760
  2. package/dist/wemap-osm.es.js.map +1 -1
  3. package/index.js +5 -28
  4. package/package.json +4 -6
  5. package/src/{model/OsmParser.spec.js → OsmParser.spec.js} +1 -1
  6. package/assets/bureaux-wemap-montpellier-network.osm +0 -162
  7. package/assets/gare-de-lyon-extract.osm +0 -174
  8. package/assets/itinerary-deutsche-bahn-1.json +0 -368
  9. package/assets/itinerary-grenoble-otp-1.json +0 -1536
  10. package/assets/itinerary-grenoble-otp-2.json +0 -1092
  11. package/assets/itinerary-lehavre-cityway-1.json +0 -6799
  12. package/assets/itinerary-lehavre-cityway-2.json +0 -2133
  13. package/assets/itinerary-lehavre-cityway-3.json +0 -12577
  14. package/assets/itinerary-lehavre-cityway-4.json +0 -1451
  15. package/assets/itinerary-lehavre-cityway-5.json +0 -5925
  16. package/assets/itinerary-montpellier-osrm-3.json +0 -1
  17. package/assets/itinerary-montpellier-outdoor-without-steps.json +0 -110
  18. package/assets/itinerary-montpellier-outdoor.json +0 -513
  19. package/assets/itinerary-with-duplicate-nodes.json +0 -110
  20. package/assets/network-conveying-backward.osm +0 -74
  21. package/assets/network-elevator.osm +0 -48
  22. package/assets/network-simple.osm +0 -27
  23. package/assets/network-with-modifiers.osm +0 -39
  24. package/assets/one-way.osm +0 -46
  25. package/src/routers/Itinerary.js +0 -197
  26. package/src/routers/Itinerary.type.spec.js +0 -105
  27. package/src/routers/Leg.js +0 -113
  28. package/src/routers/LevelChange.js +0 -65
  29. package/src/routers/RouterResponse.js +0 -19
  30. package/src/routers/RouterResponse.type.spec.js +0 -24
  31. package/src/routers/Step.js +0 -118
  32. package/src/routers/Utils.js +0 -54
  33. package/src/routers/cityway/CitywayUtils.js +0 -240
  34. package/src/routers/cityway/CitywayUtils.spec.js +0 -109
  35. package/src/routers/custom/OsmNetworkUtils.js +0 -199
  36. package/src/routers/custom/OsmNetworkUtils.spec.js +0 -109
  37. package/src/routers/custom/OsmRouter.js +0 -27
  38. package/src/routers/custom/OsmRouter.spec.js +0 -222
  39. package/src/routers/custom/OsmRouterOptions.js +0 -33
  40. package/src/routers/custom/OsmRouterUtils.js +0 -46
  41. package/src/routers/custom/StepsGeneration.js +0 -104
  42. package/src/routers/deutsche-bahn/DeutscheBahnRouterUtils.js +0 -93
  43. package/src/routers/deutsche-bahn/DeutscheBahnRouterUtils.spec.js +0 -54
  44. package/src/routers/info/ItineraryInfo.js +0 -34
  45. package/src/routers/info/ItineraryInfoManager.js +0 -148
  46. package/src/routers/info/ItineraryInfoManager.spec.js +0 -54
  47. package/src/routers/osrm/OsrmUtils.js +0 -269
  48. package/src/routers/osrm/OsrmUtils.spec.js +0 -457
  49. package/src/routers/otp/OtpUtils.js +0 -150
  50. package/src/routers/otp/OtpUtils.spec.js +0 -97
  51. /package/src/{model/OsmElement.js → OsmElement.js} +0 -0
  52. /package/src/{model/OsmElement.spec.js → OsmElement.spec.js} +0 -0
  53. /package/src/{model/OsmModel.js → OsmModel.js} +0 -0
  54. /package/src/{model/OsmModel.spec.js → OsmModel.spec.js} +0 -0
  55. /package/src/{model/OsmNode.js → OsmNode.js} +0 -0
  56. /package/src/{model/OsmNode.spec.js → OsmNode.spec.js} +0 -0
  57. /package/src/{model/OsmParser.js → OsmParser.js} +0 -0
  58. /package/src/{model/OsmWay.js → OsmWay.js} +0 -0
  59. /package/src/{model/OsmWay.spec.js → OsmWay.spec.js} +0 -0
@@ -1,110 +0,0 @@
1
- {
2
- "code": "Ok",
3
- "routes": [
4
- {
5
- "geometry": {
6
- "coordinates": [
7
- [
8
- 4.931728,
9
- 44.799761
10
- ],
11
- [
12
- 4.927543,
13
- 44.799052
14
- ],
15
- [
16
- 4.927543,
17
- 44.799052
18
- ],
19
- [
20
- 4.927385,
21
- 44.799037
22
- ],
23
- [
24
- 4.923283,
25
- 44.798721
26
- ]
27
- ],
28
- "type": "LineString"
29
- },
30
- "legs": [
31
- {
32
- "steps": [
33
- {
34
- "driving_side": "right",
35
- "geometry": {
36
- "coordinates": [
37
- [
38
- 4.931728,
39
- 44.799761
40
- ],
41
- [
42
- 4.927543,
43
- 44.799052
44
- ],
45
- [
46
- 4.927543,
47
- 44.799052
48
- ],
49
- [
50
- 4.927385,
51
- 44.799037
52
- ],
53
- [
54
- 4.923283,
55
- 44.798721
56
- ]
57
- ],
58
- "type": "LineString"
59
- },
60
- "mode": "walking",
61
- "duration": 496.9,
62
- "maneuver": {
63
- "bearing_after": 264,
64
- "type": "end of road",
65
- "modifier": "left",
66
- "bearing_before": 338,
67
- "location": [
68
- 4.931728,
69
- 44.799761
70
- ]
71
- },
72
- "weight": 496.9,
73
- "distance": 689.7,
74
- "name": "Route d'Ambonil"
75
- },
76
- {
77
- "driving_side": "right",
78
- "geometry": {
79
- "coordinates": [
80
- [
81
- 4.931728,
82
- 44.799761
83
- ],
84
- [
85
- 4.931728,
86
- 44.799761
87
- ]
88
- ]
89
- },
90
- "maneuver": {
91
- "bearing_after": 0,
92
- "type": "arrive",
93
- "modifier": "left",
94
- "bearing_before": 291,
95
- "location": [
96
- 4.556421,
97
- 44.302754
98
- ]
99
- }
100
- }
101
- ]
102
- }
103
- ],
104
- "distance": 75006.7,
105
- "duration": 54016.6,
106
- "weight_name": "duration",
107
- "weight": 54016.6
108
- }
109
- ]
110
- }
@@ -1,74 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?>
2
- <osm version='0.6' generator='JOSM'>
3
- <node id='-519157' action='modify' visible='true' lat='48.84445412307' lon='2.37216128192'>
4
- <tag k='name' v='p6' />
5
- </node>
6
- <node id='-519158' action='modify' visible='true' lat='48.84456231196' lon='2.37194113366'>
7
- <tag k='name' v='p11' />
8
- </node>
9
- <node id='-519161' action='modify' visible='true' lat='48.84459094139' lon='2.37200629832'>
10
- <tag k='name' v='p13' />
11
- </node>
12
- <node id='-519164' action='modify' visible='true' lat='48.8445706698' lon='2.3719601573'>
13
- <tag k='name' v='p12' />
14
- </node>
15
- <node id='1395307661' action='modify' timestamp='2019-09-19T15:44:48Z' uid='439947' user='StephaneP' visible='true' version='11' changeset='74681133' lat='48.8444657' lon='2.3720493'>
16
- <tag k='name' v='p7' />
17
- </node>
18
- <node id='1395307662' action='modify' timestamp='2019-09-19T15:44:48Z' uid='439947' user='StephaneP' visible='true' version='3' changeset='74681133' lat='48.8445534' lon='2.3719505'>
19
- <tag k='name' v='p10' />
20
- </node>
21
- <node id='4086374112' action='modify' timestamp='2019-09-19T16:18:40Z' uid='439947' user='StephaneP' visible='true' version='3' changeset='74683089' lat='48.8444961' lon='2.3720441'>
22
- <tag k='name' v='p8' />
23
- </node>
24
- <node id='4086374115' action='modify' timestamp='2019-09-19T15:44:48Z' uid='439947' user='StephaneP' visible='true' version='2' changeset='74681133' lat='48.844562' lon='2.3719702'>
25
- <tag k='name' v='p9' />
26
- </node>
27
- <node id='4086374120' action='delete' timestamp='2019-09-19T16:18:40Z' uid='439947' user='StephaneP' visible='true' version='3' changeset='74683089' lat='48.8446803' lon='2.3718155'>
28
- <tag k='level' v='-1' />
29
- <tag k='name' v='p1' />
30
- <tag k='railway' v='subway_entrance' />
31
- <tag k='ref' v='13' />
32
- <tag k='source' v='cadastre-dgi-fr source : Direction Générale des Impôts - Cadastre. Mise à jour : 2011' />
33
- <tag k='wheelchair' v='no' />
34
- </node>
35
- <way id='-519165' action='modify' visible='true'>
36
- <nd ref='-519164' />
37
- <nd ref='4086374115' />
38
- <tag k='highway' v='footway' />
39
- <tag k='level' v='0' />
40
- </way>
41
- <way id='-519168' action='modify' visible='true'>
42
- <nd ref='1395307662' />
43
- <nd ref='-519158' />
44
- <nd ref='-519164' />
45
- <nd ref='-519161' />
46
- <tag k='highway' v='footway' />
47
- <tag k='level' v='0' />
48
- </way>
49
- <way id='-519174' action='modify' visible='true'>
50
- <nd ref='-519157' />
51
- <nd ref='4086374112' />
52
- <tag k='highway' v='footway' />
53
- <tag k='level' v='-1' />
54
- </way>
55
- <way id='-519225' action='modify' visible='true'>
56
- <nd ref='1395307661' />
57
- <nd ref='-519157' />
58
- <tag k='highway' v='footway' />
59
- <tag k='level' v='-1' />
60
- </way>
61
- <way id='125679471' action='modify' timestamp='2016-04-15T07:37:33Z' uid='1908665' user='naomap' visible='true' version='4' changeset='38579747'>
62
- <nd ref='1395307661' />
63
- <nd ref='1395307662' />
64
- <tag k='highway' v='steps' />
65
- <tag k='level' v='-1;0' />
66
- </way>
67
- <way id='406582305' action='modify' timestamp='2016-04-15T07:37:40Z' uid='1908665' user='naomap' visible='true' version='2' changeset='38579747'>
68
- <nd ref='4086374112' />
69
- <nd ref='4086374115' />
70
- <tag k='conveying' v='backward' />
71
- <tag k='highway' v='steps' />
72
- <tag k='level' v='-1;0' />
73
- </way>
74
- </osm>
@@ -1,48 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?>
2
- <osm version='0.6'>
3
- <node id='-1' lat='43.60933232537' lon='3.88424831515' version='1'>
4
- <tag k='highway' v='elevator' />
5
- <tag k='level' v='1;3' />
6
- <tag k='name' v='px' />
7
- </node>
8
- <node id='1' lat='43.60932786117' lon='3.88427765877' version='1'>
9
- <tag k='name' v='p1' />
10
- </node>
11
- <node id='2' lat='43.60932786111' lon='3.8842776591' version='1'>
12
- <tag k='name' v='p2' />
13
- </node>
14
- <node id='3' lat='43.60932198746' lon='3.8843159771' version='1'>
15
- <tag k='name' v='p3-1' />
16
- </node>
17
- <node id='4' lat='43.60932198746' lon='3.8843159771' version='1'>
18
- <tag k='name' v='p3-2' />
19
- </node>
20
- <way id='101' version='1'>
21
- <nd ref='-1' />
22
- <nd ref='1' />
23
- <tag k='highway' v='footway' />
24
- <tag k='level' v='1' />
25
- <tag k='name' v='w1' />
26
- </way>
27
- <way id='102' version='1'>
28
- <nd ref='-1' />
29
- <nd ref='2' />
30
- <tag k='highway' v='footway' />
31
- <tag k='level' v='2' />
32
- <tag k='name' v='w2' />
33
- </way>
34
- <way id='103' version='1'>
35
- <nd ref='-1' />
36
- <nd ref='3' />
37
- <tag k='highway' v='footway' />
38
- <tag k='level' v='3' />
39
- <tag k='name' v='w3-1' />
40
- </way>
41
- <way id='104' version='1'>
42
- <nd ref='-1' />
43
- <nd ref='4' />
44
- <tag k='highway' v='footway' />
45
- <tag k='level' v='3' />
46
- <tag k='name' v='w3-2' />
47
- </way>
48
- </osm>
@@ -1,27 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?>
2
- <osm>
3
- <node id='1' lat='43.6093335' lon='3.88428'>
4
- <tag k='name' v='p1' />
5
- </node>
6
- <node id='2' lat='43.60933232537' lon='3.88424831515'>
7
- <tag k='name' v='p2' />
8
- </node>
9
- <node id='3' lat='43.60932786111' lon='3.8842776591'>
10
- <tag k='name' v='p3' />
11
- </node>
12
- <node id='4' lat='43.60932198746' lon='3.8843159771'>
13
- <tag k='name' v='p4' />
14
- </node>
15
- <way id='101'>
16
- <nd ref='1' />
17
- <nd ref='2' />
18
- <nd ref='3' />
19
- <tag k='name' v='w1' />
20
- <tag k='highway' v='footway' />
21
- </way>
22
- <way id='102'>
23
- <nd ref='3' />
24
- <nd ref='4' />
25
- <tag k='name' v='w2' />
26
- </way>
27
- </osm>
@@ -1,39 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?>
2
- <osm version='0.6' generator='JOSM'>
3
- <node id='-519658' action='modify' visible='true' lat='48.84421815274' lon='2.37214171465'>
4
- <tag k='name' v='start' />
5
- </node>
6
- <node id='-519659' action='modify' visible='true' lat='48.84493822092' lon='2.37214171465' />
7
- <node id='-519661' action='modify' visible='true' lat='48.84431552103' lon='2.37268800579' />
8
- <node id='-519663' action='modify' visible='true' lat='48.84395581937' lon='2.37174132231' />
9
- <node id='-519665' action='modify' visible='true' lat='48.84395581937' lon='2.37064538259' />
10
- <node id='-519667' action='modify' visible='true' lat='48.84395581937' lon='2.36955122674' />
11
- <node id='-519669' action='modify' visible='true' lat='48.84359604217' lon='2.36860435126' />
12
- <node id='-519671' action='modify' visible='true' lat='48.84297192036' lon='2.36915187515' />
13
- <node id='-519673' action='modify' visible='true' lat='48.84368879871' lon='2.36915187515'>
14
- <tag k='name' v='end' />
15
- </node>
16
- <way id='-519660' action='modify' visible='true'>
17
- <nd ref='-519658' />
18
- <nd ref='-519659' />
19
- <nd ref='-519661' />
20
- <nd ref='-519663' />
21
- <nd ref='-519665' />
22
- <tag k='highway' v='footway' />
23
- <tag k='level' v='0' />
24
- </way>
25
- <way id='-519746' action='modify' visible='true'>
26
- <nd ref='-519665' />
27
- <nd ref='-519667' />
28
- <tag k='highway' v='steps' />
29
- <tag k='level' v='0;1' />
30
- </way>
31
- <way id='-519747' action='modify' visible='true'>
32
- <nd ref='-519667' />
33
- <nd ref='-519669' />
34
- <nd ref='-519671' />
35
- <nd ref='-519673' />
36
- <tag k='highway' v='footway' />
37
- <tag k='level' v='1' />
38
- </way>
39
- </osm>
@@ -1,46 +0,0 @@
1
- <?xml version='1.0' encoding='UTF-8'?>
2
- <osm version='0.6' generator='JOSM'>
3
- <node id='-441557' action='modify' visible='true' lat='43.60942861314' lon='3.88420107589'>
4
- <tag k='name' v='p1' />
5
- </node>
6
- <node id='-441558' action='modify' visible='true' lat='43.60938929783' lon='3.8841913836'>
7
- <tag k='name' v='p3' />
8
- </node>
9
- <node id='-441559' action='modify' visible='true' lat='43.60940277907' lon='3.88421907562'>
10
- <tag k='name' v='p5' />
11
- </node>
12
- <node id='-441560' action='modify' visible='true' lat='43.60937924953' lon='3.88418893318' />
13
- <node id='-441561' action='modify' visible='true' lat='43.6094255609' lon='3.88422469196'>
14
- <tag k='name' v='p4' />
15
- </node>
16
- <node id='-441562' action='modify' visible='true' lat='43.60945421917' lon='3.88420719584' />
17
- <node id='-441563' action='modify' visible='true' lat='43.60940583132' lon='3.88419545955'>
18
- <tag k='name' v='p2' />
19
- </node>
20
- <node id='-441564' action='modify' visible='true' lat='43.60944417022' lon='3.88420491113'>
21
- <tag k='name' v='p0' />
22
- </node>
23
- <way id='-441565' action='modify' visible='true'>
24
- <nd ref='-441557' />
25
- <nd ref='-441563' />
26
- <tag k='highway' v='footway' />
27
- <tag k='oneway' v='yes' />
28
- </way>
29
- <way id='-441566' action='modify' visible='true'>
30
- <nd ref='-441563' />
31
- <nd ref='-441558' />
32
- <tag k='highway' v='footway' />
33
- </way>
34
- <way id='-441567' action='modify' visible='true'>
35
- <nd ref='-441564' />
36
- <nd ref='-441557' />
37
- <tag k='highway' v='footway' />
38
- </way>
39
- <way id='-441568' action='modify' visible='true'>
40
- <nd ref='-441557' />
41
- <nd ref='-441561' />
42
- <nd ref='-441559' />
43
- <nd ref='-441563' />
44
- <tag k='highway' v='footway' />
45
- </way>
46
- </osm>
@@ -1,197 +0,0 @@
1
- /* eslint-disable max-statements */
2
- import { Coordinates, Network } from '@wemap/geo';
3
- import Leg from './Leg.js';
4
- import Step from './Step.js';
5
- import OsmRouterOptions from './custom/OsmRouterOptions.js';
6
-
7
- /**
8
- * Main attributes are:
9
- * nodes: the ordered list of Node
10
- * edges: the ordered list of Edge
11
- * start: the start point (Coordinates)
12
- * end: the end point (Coordinates)
13
- * length: the route length
14
- */
15
- class Itinerary {
16
-
17
- /** @type {!Coordinates} */
18
- from;
19
-
20
- /** @type {!Coordinates} */
21
- to;
22
-
23
- /** @type {!number} */
24
- distance;
25
-
26
- /** @type {!number} */
27
- duration;
28
-
29
- /** @type {?number} */
30
- startTime = null;
31
-
32
- /** @type {?number} */
33
- endTime = null;
34
-
35
- /** @type {!(Leg[])} */
36
- legs = [];
37
-
38
- /** @type {?Coordinates[]} */
39
- _coords = null;
40
-
41
- set coords(_) {
42
- throw new Error('Itinerary.coords cannot be set. They are calculated from Itinerary.legs.');
43
- }
44
-
45
- /** @type {!(Coordinates[])} */
46
- get coords() {
47
- if (!this._coords) {
48
- // Returns the coordinates contained in all legs and remove duplicates between array
49
- this._coords = this.legs.reduce((acc, val) => {
50
- const isDuplicate = acc.length && val.coords.length && acc[acc.length - 1].equalsTo(val.coords[0]);
51
- acc.push(...val.coords.slice(isDuplicate ? 1 : 0));
52
- return acc;
53
- }, []);
54
- }
55
- return this._coords;
56
- }
57
-
58
- set steps(_) {
59
- throw new Error('Itinerary.step cannot be set. They are calculated from Itinerary.legs.');
60
- }
61
-
62
- /** @type {!(Step[])} */
63
- get steps() {
64
- return this.legs.map(leg => leg.steps).flat();
65
- }
66
-
67
- /**
68
- * @returns {Network}
69
- */
70
- toNetwork() {
71
- return Network.fromCoordinates([this.coords]);
72
- }
73
-
74
- /**
75
- * @param {Itinerary[]} itineraries
76
- * @returns {Itinerary}
77
- */
78
- static fromItineraries(...itineraries) {
79
- const itinerary = new Itinerary();
80
- itinerary.from = itineraries[0].from;
81
- itinerary.to = itineraries[itineraries.length - 1].to;
82
- itinerary.distance = 0;
83
- itinerary.duration = 0;
84
- itinerary.legs = [];
85
-
86
- itineraries.forEach(_itinerary => {
87
- itinerary.distance += _itinerary.distance;
88
- itinerary.duration += _itinerary.duration;
89
- itinerary.legs.push(..._itinerary.legs);
90
- itinerary.legs.forEach(leg => {
91
- leg.steps[0].firstStep = false;
92
- leg.steps[leg.steps.length - 1].lastStep = false;
93
- });
94
- });
95
-
96
- itinerary.legs[0].steps[0].firstStep = true;
97
- const lastLeg = itinerary.legs[itinerary.legs.length - 1];
98
- lastLeg.steps[lastLeg.steps.length - 1].lastStep = true;
99
-
100
- return itinerary;
101
- }
102
-
103
- /**
104
- * Convert lat/lng/level points to Itinerary
105
- * @param {number[][]} points 2D points array of lat/lng/level (level is optional)
106
- * @param {Coordinates} from
107
- * @param {Coordinates} to
108
- * @param {string} mode
109
- * @returns {Itinerary}
110
- */
111
- static fromOrderedPointsArray(points, start, end) {
112
-
113
- const pointToCoordinates = point => new Coordinates(point[0], point[1], null, point[2]);
114
-
115
- return this.fromOrderedCoordinates(
116
- points.map(pointToCoordinates),
117
- pointToCoordinates(start),
118
- pointToCoordinates(end)
119
- );
120
- }
121
-
122
- /**
123
- * Convert ordered Coordinates to Itinerary
124
- * @param {Coordinates[]} points
125
- * @param {Coordinates} from
126
- * @param {Coordinates} to
127
- * @param {string} mode
128
- * @returns {Itinerary}
129
- */
130
- static fromOrderedCoordinates(points, from, to, mode = 'WALK') {
131
-
132
- const itinerary = new Itinerary();
133
- itinerary.from = from;
134
- itinerary.to = to;
135
-
136
- const leg = new Leg();
137
- leg.mode = mode;
138
- leg.from = { name: null, coords: from };
139
- leg.to = { name: null, coords: to };
140
-
141
- leg.coords = points;
142
- leg.distance = points.reduce((acc, coords, idx, arr) => {
143
- if (idx !== 0) {
144
- return acc + arr[idx - 1].distanceTo(coords);
145
- }
146
- return acc;
147
- }, 0);
148
- leg.duration = OsmRouterOptions.getDurationFromLength(leg.distance);
149
- itinerary.legs.push(leg);
150
-
151
- itinerary.distance = leg.distance;
152
- itinerary.duration = leg.duration;
153
-
154
- return itinerary;
155
- }
156
-
157
- /**
158
- * @returns {object}
159
- */
160
- toJson() {
161
- const output = {
162
- from: this.from.toCompressedJson(),
163
- to: this.to.toCompressedJson(),
164
- distance: this.distance,
165
- duration: this.duration,
166
- legs: this.legs.map(leg => leg.toJson())
167
- };
168
- if (this.startTime !== null) {
169
- output.startTime = this.startTime;
170
- }
171
- if (this.endTime !== null) {
172
- output.endTime = this.endTime;
173
- }
174
- return output;
175
- }
176
-
177
- /**
178
- * @param {object} json
179
- * @returns {Itinerary}
180
- */
181
- static fromJson(json) {
182
- const itinerary = new Itinerary();
183
- itinerary.from = Coordinates.fromCompressedJson(json.from);
184
- itinerary.to = Coordinates.fromCompressedJson(json.to);
185
- itinerary.distance = json.distance;
186
- itinerary.duration = json.duration;
187
- itinerary.legs = json.legs.map(Leg.fromJson);
188
- if (json.startTime) {
189
- itinerary.startTime = json.startTime;
190
- }
191
- if (json.endTime) {
192
- itinerary.endTime = json.endTime;
193
- }
194
- return itinerary;
195
- }
196
- }
197
- export default Itinerary;
@@ -1,105 +0,0 @@
1
- import chai from 'chai';
2
-
3
- import { Coordinates } from '@wemap/geo';
4
-
5
- import LevelChange from './LevelChange.js';
6
- import Leg from './Leg.js';
7
- import Itinerary from './Itinerary.js';
8
- import Step from './Step.js';
9
-
10
- const { expect } = chai;
11
-
12
-
13
- const isNullOrNumber = val => val === null || typeof val === 'number';
14
- const isNullOrString = val => val === null || typeof val === 'string';
15
- const isNullOrObject = val => val === null || typeof val === 'object';
16
- const isNullOrArray = val => val === null || Array.isArray(val);
17
- const isNullOrLevelChange = val => val === null || val instanceof LevelChange;
18
-
19
- const isUndefinedOrBoolean = val => typeof val === 'undefined' || typeof val === 'boolean';
20
- const isUndefinedOrString = val => typeof val === 'undefined' || typeof val === 'string';
21
-
22
- const stepExtraProperties = ['subwayEntrance', 'subwayEntranceRef'];
23
-
24
- /**
25
- * @param {Step} step
26
- */
27
- export function verifyStepData(step) {
28
-
29
- expect(step).instanceOf(Step);
30
- expect(step.firstStep).be.a('boolean');
31
- expect(step.lastStep).be.a('boolean');
32
- expect(step.number).be.a('number');
33
- expect(step.coords).instanceOf(Coordinates);
34
- expect(step.angle).be.a('number');
35
- expect(step.previousBearing).be.a('number');
36
- expect(step.nextBearing).be.a('number');
37
- expect(step.distance).be.a('number');
38
- expect(step.duration).satisfies(isNullOrNumber);
39
- expect(step.name).satisfies(isNullOrString);
40
- expect(step.levelChange).satisfies(isNullOrLevelChange);
41
- expect(step._idCoordsInLeg).be.a('number');
42
-
43
- expect(step.extras).satisfies(isNullOrObject);
44
- if (step.extras !== null) {
45
- for (const key of Object.keys(step.extras)) {
46
- expect(stepExtraProperties).includes(key);
47
- }
48
- expect(step.extras.subwayEntrance).satisfies(isUndefinedOrBoolean);
49
- expect(step.extras.subwayEntranceRef).satisfies(isUndefinedOrString);
50
- }
51
- }
52
-
53
- /**
54
- * @param {Leg} routerResponse
55
- */
56
- export function verifyLegData(leg) {
57
-
58
- expect(leg).instanceOf(Leg);
59
- expect(leg.mode).be.a('string');
60
- expect(leg.distance).be.a('number');
61
- expect(leg.duration).be.a('number');
62
- expect(leg.startTime).satisfies(isNullOrNumber);
63
- expect(leg.endTime).satisfies(isNullOrNumber);
64
- expect(leg.from).be.an('object');
65
- expect(leg.from.name).satisfies(isNullOrString);
66
- expect(leg.from.coords).instanceOf(Coordinates);
67
- expect(leg.to).be.an('object');
68
- expect(leg.to.name).satisfies(isNullOrString);
69
- expect(leg.to.coords).instanceOf(Coordinates);
70
- expect(leg.coords).be.an('array');
71
- leg.coords.forEach(coords => expect(coords).instanceOf(Coordinates));
72
-
73
- expect(leg.transportInfo).satisfies(isNullOrObject);
74
- if (leg.transportInfo !== null) {
75
- expect(leg.transportInfo.name).be.a('string');
76
- expect(leg.transportInfo.routeColor).satisfies(isNullOrString);
77
- expect(leg.transportInfo.routeTextColor).satisfies(isNullOrString);
78
- expect(leg.transportInfo.directionName).satisfies(isNullOrString);
79
- }
80
- expect(leg.steps).satisfies(isNullOrArray);
81
- if (leg.steps !== null) {
82
- leg.steps.forEach(verifyStepData);
83
- }
84
- }
85
-
86
-
87
- /**
88
- * @param {Itinerary} itinerary
89
- */
90
- export function verifyItineraryData(itinerary) {
91
-
92
- expect(itinerary).instanceOf(Itinerary);
93
- expect(itinerary.from).instanceOf(Coordinates);
94
- expect(itinerary.to).instanceOf(Coordinates);
95
- expect(itinerary.coords).be.an('array');
96
- for (const coords of itinerary.coords) {
97
- expect(coords).instanceOf(Coordinates);
98
- }
99
- expect(itinerary.distance).be.a('number');
100
- expect(itinerary.duration).be.a('number');
101
- expect(itinerary.startTime).satisfies(isNullOrNumber);
102
- expect(itinerary.endTime).satisfies(isNullOrNumber);
103
- expect(itinerary.legs).be.an('array');
104
- itinerary.legs.forEach(verifyLegData);
105
- }