@wemap/routers 6.0.0 → 6.0.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 CHANGED
@@ -11,7 +11,7 @@
11
11
  "directory": "packages/routers"
12
12
  },
13
13
  "name": "@wemap/routers",
14
- "version": "6.0.0",
14
+ "version": "6.0.1",
15
15
  "bugs": {
16
16
  "url": "https://github.com/wemap/wemap-modules-js/issues"
17
17
  },
@@ -31,5 +31,5 @@
31
31
  "@wemap/maths": "^6.0.0",
32
32
  "@wemap/osm": "^6.0.0"
33
33
  },
34
- "gitHead": "a377d6fd98b48ce0e083ece1c695642947c456cc"
34
+ "gitHead": "e1440c56752edb5c31f46a61f49ab0ff1270176b"
35
35
  }
@@ -160,7 +160,7 @@ export function createRouterResponseFromJson(json) {
160
160
  leg.steps.push(step);
161
161
  }
162
162
 
163
- } else if (leg.mode === 'BUS' || leg.mode === 'TRAMWAY' || leg.mode === 'FUNICULAR') {
163
+ } else if (leg.mode === 'BUS' || leg.mode === 'TRAMWAY' || leg.mode === 'FUNICULAR' || leg.mode === 'TRAIN') {
164
164
 
165
165
  leg.from = {
166
166
  name: jsonLeg.Departure.StopPlace.Name,
@@ -34,6 +34,7 @@ describe('CitywayUtils - createRouterResponseFromJson', () => {
34
34
  const itinerary1 = routerResponse.itineraries[0];
35
35
  expect(itinerary1.distance).to.be.closeTo(6887, 1);
36
36
  expect(itinerary1.duration).equal(2379);
37
+ expect(itinerary1.mode).equal('PT');
37
38
  // Do not work because of the input time format
38
39
  // expect(itinerary1.startTime).equal(1620659156000);
39
40
  // expect(itinerary1.endTime).equal(1620661535000);
@@ -69,6 +70,7 @@ describe('CitywayUtils - createRouterResponseFromJson', () => {
69
70
  verifyRouterResponseData(routerResponse);
70
71
 
71
72
  expect(routerResponse.itineraries.length).equal(1);
73
+ expect(routerResponse.itineraries[0].mode).equal('WALK');
72
74
  });
73
75
 
74
76
  it('RouterResponse - 3', () => {
@@ -79,6 +81,7 @@ describe('CitywayUtils - createRouterResponseFromJson', () => {
79
81
  const routerResponse = createRouterResponseFromJson(json);
80
82
  verifyRouterResponseData(routerResponse);
81
83
 
84
+ expect(routerResponse.itineraries[0].mode).equal('PT');
82
85
  expect(routerResponse.itineraries[0].legs[1].mode).equal('FUNICULAR');
83
86
  });
84
87
 
@@ -90,6 +93,7 @@ describe('CitywayUtils - createRouterResponseFromJson', () => {
90
93
  const routerResponse = createRouterResponseFromJson(json);
91
94
  verifyRouterResponseData(routerResponse);
92
95
 
96
+ expect(routerResponse.itineraries[0].mode).equal('BIKE');
93
97
  expect(routerResponse.itineraries[0].legs[0].mode).equal('BICYCLE');
94
98
  });
95
99
 
@@ -101,6 +105,7 @@ describe('CitywayUtils - createRouterResponseFromJson', () => {
101
105
  const routerResponse = createRouterResponseFromJson(json);
102
106
  verifyRouterResponseData(routerResponse);
103
107
 
108
+ expect(routerResponse.itineraries[1].mode).equal('PT');
104
109
  expect(routerResponse.itineraries[1].legs[1].mode).equal('TRAM');
105
110
  expect(routerResponse.itineraries[1].legs[1].transportInfo.name).equal('B');
106
111
  });
@@ -40,6 +40,7 @@ describe('OtpUtils - createRouterResponseFromJson', () => {
40
40
  expect(itinerary1.coords.length).equal(77);
41
41
  expect(itinerary1.distance).almost.equal(129.673);
42
42
  expect(itinerary1.duration).almost.equal(93.365);
43
+ expect(itinerary1.mode).equal('WALK');
43
44
 
44
45
  const itinerary1leg1 = itinerary1.legs[0];
45
46
  expect(itinerary1leg1.distance).almost.equal(129.673);
@@ -26,6 +26,9 @@ class Itinerary {
26
26
  /** @type {!number} */
27
27
  duration;
28
28
 
29
+ /** @type {!string} can be WALK, BIKE, CAR, PT */
30
+ _mode;
31
+
29
32
  /** @type {?number} */
30
33
  startTime = null;
31
34
 
@@ -64,6 +67,37 @@ class Itinerary {
64
67
  return this.legs.map(leg => leg.steps).flat();
65
68
  }
66
69
 
70
+ set mode(_) {
71
+ throw new Error('Itinerary.mode cannot be set. They are calculated from Itinerary.legs.');
72
+ }
73
+
74
+ get mode() {
75
+ if (!this._mode) {
76
+ let isPublicTransport;
77
+ let isBicycle;
78
+ let isDriving;
79
+
80
+ this.legs.forEach((leg) => {
81
+ isPublicTransport = isPublicTransport || ['BUS', 'FUNICULAR', 'TRAM', 'TRAIN'].includes(leg.mode);
82
+ isBicycle = isBicycle || ['BIKE', 'BICYCLE'].includes(leg.mode);
83
+ isDriving = isDriving || leg.mode === 'CAR';
84
+ });
85
+
86
+ if (isPublicTransport) {
87
+ this._mode = 'PT';
88
+ } else if (isDriving) {
89
+ this._mode = 'CAR';
90
+ } else if (isBicycle) {
91
+ this._mode = 'BIKE';
92
+ } else {
93
+ this._mode = 'WALK';
94
+ }
95
+ }
96
+
97
+ return this._mode;
98
+
99
+ }
100
+
67
101
  /**
68
102
  * @returns {Network}
69
103
  */
@@ -163,6 +197,7 @@ class Itinerary {
163
197
  to: this.to.toCompressedJson(),
164
198
  distance: this.distance,
165
199
  duration: this.duration,
200
+ mode: this.mode,
166
201
  legs: this.legs.map(leg => leg.toJson())
167
202
  };
168
203
  if (this.startTime !== null) {
@@ -90,6 +90,7 @@ export function verifyLegData(leg) {
90
90
  export function verifyItineraryData(itinerary) {
91
91
 
92
92
  expect(itinerary).instanceOf(Itinerary);
93
+ expect(itinerary.mode).be.a('string');
93
94
  expect(itinerary.from).instanceOf(Coordinates);
94
95
  expect(itinerary.to).instanceOf(Coordinates);
95
96
  expect(itinerary.coords).be.an('array');
@@ -413,6 +413,7 @@ describe('OsrmUtils - createRouterResponseFromJson', () => {
413
413
  expect(itinerary1.endTime).is.null;
414
414
  expect(itinerary1.legs.length).equal(1);
415
415
  expect(itinerary1.coords.length).equal(19);
416
+ expect(itinerary1.mode).equal('WALK');
416
417
 
417
418
  const itinerary1leg1 = itinerary1.legs[0];
418
419
  expect(itinerary1leg1.startTime).is.null;
@@ -39,6 +39,7 @@ describe('OtpUtils - createRouterResponseFromJson', () => {
39
39
  expect(itinerary1.startTime).equal(1614607210000);
40
40
  expect(itinerary1.endTime).equal(1614608416000);
41
41
  expect(itinerary1.legs.length).equal(3);
42
+ expect(itinerary1.mode).equal('PT');
42
43
 
43
44
  const itinerary1leg1 = itinerary1.legs[0];
44
45
  expect(itinerary1leg1.startTime).equal(1614607210000);
@@ -78,6 +79,8 @@ describe('OtpUtils - createRouterResponseFromJson', () => {
78
79
  const itinerary1 = routerResponse.itineraries[0];
79
80
  expect(itinerary1.legs.length).equal(5);
80
81
 
82
+ expect(itinerary1.mode).equal('PT');
83
+
81
84
  expect(itinerary1.legs[0].mode).equal('WALK');
82
85
 
83
86
  expect(itinerary1.legs[1].mode).equal('TRAM');