@wemap/routers 6.2.1 → 6.2.3
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 +4 -4
- package/src/Constants.js +3 -2
- package/src/cityway/CitywayUtils.js +64 -7
- package/src/idfm/IdfmUtils.js +9 -0
- package/dist/wemap-routers.es.js +0 -1895
- package/dist/wemap-routers.es.js.map +0 -1
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"directory": "packages/routers"
|
|
12
12
|
},
|
|
13
13
|
"name": "@wemap/routers",
|
|
14
|
-
"version": "6.2.
|
|
14
|
+
"version": "6.2.3",
|
|
15
15
|
"bugs": {
|
|
16
16
|
"url": "https://github.com/wemap/wemap-modules-js/issues"
|
|
17
17
|
},
|
|
@@ -26,10 +26,10 @@
|
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@mapbox/polyline": "^1.1.1",
|
|
29
|
-
"@wemap/geo": "^6.
|
|
29
|
+
"@wemap/geo": "^6.2.3",
|
|
30
30
|
"@wemap/logger": "^6.0.0",
|
|
31
31
|
"@wemap/maths": "^6.0.0",
|
|
32
|
-
"@wemap/osm": "^6.
|
|
32
|
+
"@wemap/osm": "^6.2.3"
|
|
33
33
|
},
|
|
34
|
-
"gitHead": "
|
|
34
|
+
"gitHead": "e88b0f15de31c30588aaacdadcbad2da46f9673d"
|
|
35
35
|
}
|
package/src/Constants.js
CHANGED
|
@@ -9,10 +9,12 @@ Constants.ROUTING_MODE = {
|
|
|
9
9
|
FERRY: 'FERRY',
|
|
10
10
|
FUNICULAR: 'FUNICULAR',
|
|
11
11
|
METRO: 'METRO',
|
|
12
|
+
MOTO: 'MOTO',
|
|
12
13
|
TRAIN: 'TRAIN',
|
|
13
14
|
TAXI: 'TAXI',
|
|
14
15
|
TRAM: 'TRAM',
|
|
15
|
-
WALK: 'WALK'
|
|
16
|
+
WALK: 'WALK',
|
|
17
|
+
UNKNOWN: 'UNKNOWN'
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
Constants.PUBLIC_TRANSPORT = [
|
|
@@ -23,7 +25,6 @@ Constants.PUBLIC_TRANSPORT = [
|
|
|
23
25
|
Constants.ROUTING_MODE.FUNICULAR,
|
|
24
26
|
Constants.ROUTING_MODE.METRO,
|
|
25
27
|
Constants.ROUTING_MODE.TRAIN,
|
|
26
|
-
Constants.ROUTING_MODE.TAXI,
|
|
27
28
|
Constants.ROUTING_MODE.TRAM
|
|
28
29
|
];
|
|
29
30
|
|
|
@@ -13,10 +13,43 @@ import Constants from '../Constants.js';
|
|
|
13
13
|
const routingModeCorrespondance = new Map();
|
|
14
14
|
routingModeCorrespondance.set('WALK', Constants.ROUTING_MODE.WALK);
|
|
15
15
|
routingModeCorrespondance.set('BICYCLE', Constants.ROUTING_MODE.BIKE);
|
|
16
|
-
routingModeCorrespondance.set('BUS', Constants.ROUTING_MODE.BUS);
|
|
17
16
|
routingModeCorrespondance.set('TRAMWAY', Constants.ROUTING_MODE.TRAM);
|
|
17
|
+
routingModeCorrespondance.set('METRO', Constants.ROUTING_MODE.METRO);
|
|
18
18
|
routingModeCorrespondance.set('FUNICULAR', Constants.ROUTING_MODE.FUNICULAR);
|
|
19
|
+
routingModeCorrespondance.set('BUS', Constants.ROUTING_MODE.BUS);
|
|
20
|
+
routingModeCorrespondance.set('COACH', Constants.ROUTING_MODE.BUS);
|
|
21
|
+
routingModeCorrespondance.set('SCHOOL', Constants.ROUTING_MODE.BUS);
|
|
22
|
+
routingModeCorrespondance.set('BUS_PMR', Constants.ROUTING_MODE.BUS);
|
|
23
|
+
routingModeCorrespondance.set('MINIBUS', Constants.ROUTING_MODE.BUS);
|
|
24
|
+
routingModeCorrespondance.set('TROLLEY_BUS', Constants.ROUTING_MODE.BUS);
|
|
25
|
+
routingModeCorrespondance.set('TAXIBUS', Constants.ROUTING_MODE.BUS);
|
|
26
|
+
routingModeCorrespondance.set('SHUTTLE', Constants.ROUTING_MODE.BUS);
|
|
19
27
|
routingModeCorrespondance.set('TRAIN', Constants.ROUTING_MODE.TRAIN);
|
|
28
|
+
routingModeCorrespondance.set('HST', Constants.ROUTING_MODE.TRAIN);
|
|
29
|
+
routingModeCorrespondance.set('LOCAL_TRAIN', Constants.ROUTING_MODE.TRAIN);
|
|
30
|
+
routingModeCorrespondance.set('AIR', Constants.ROUTING_MODE.AIRPLANE);
|
|
31
|
+
routingModeCorrespondance.set('FERRY', Constants.ROUTING_MODE.BOAT);
|
|
32
|
+
routingModeCorrespondance.set('TAXI', Constants.ROUTING_MODE.UNKNOWN);
|
|
33
|
+
routingModeCorrespondance.set('CAR_POOL', Constants.ROUTING_MODE.UNKNOWN);
|
|
34
|
+
routingModeCorrespondance.set('PRIVATE_VEHICLE', Constants.ROUTING_MODE.CAR);
|
|
35
|
+
routingModeCorrespondance.set('SCOOTER', Constants.ROUTING_MODE.MOTO);
|
|
36
|
+
|
|
37
|
+
const planTripType = new Map();
|
|
38
|
+
planTripType.set(0, Constants.ROUTING_MODE.BUS);
|
|
39
|
+
planTripType.set(1, Constants.ROUTING_MODE.WALK);
|
|
40
|
+
planTripType.set(2, Constants.ROUTING_MODE.BIKE);
|
|
41
|
+
planTripType.set(3, Constants.ROUTING_MODE.CAR);
|
|
42
|
+
planTripType.set(4, Constants.ROUTING_MODE.UNKNOWN);
|
|
43
|
+
planTripType.set(5, Constants.ROUTING_MODE.UNKNOWN);
|
|
44
|
+
planTripType.set(6, Constants.ROUTING_MODE.UNKNOWN);
|
|
45
|
+
planTripType.set(7, Constants.ROUTING_MODE.UNKNOWN);
|
|
46
|
+
planTripType.set(8, Constants.ROUTING_MODE.UNKNOWN);
|
|
47
|
+
planTripType.set(9, Constants.ROUTING_MODE.UNKNOWN);
|
|
48
|
+
planTripType.set(10, Constants.ROUTING_MODE.UNKNOWN);
|
|
49
|
+
planTripType.set(11, Constants.ROUTING_MODE.UNKNOWN);
|
|
50
|
+
planTripType.set(12, Constants.ROUTING_MODE.UNKNOWN);
|
|
51
|
+
planTripType.set(13, Constants.ROUTING_MODE.UNKNOWN);
|
|
52
|
+
planTripType.set(14, Constants.ROUTING_MODE.UNKNOWN);
|
|
20
53
|
|
|
21
54
|
/**
|
|
22
55
|
* @param {object} json
|
|
@@ -51,9 +84,16 @@ function jsonDateToTimestamp(jsonDate) {
|
|
|
51
84
|
*/
|
|
52
85
|
function parseWKTGeometry(wktGeometry) {
|
|
53
86
|
const tmpCoordsStr = wktGeometry.match(/LINESTRING \((.*)\)/i);
|
|
54
|
-
|
|
87
|
+
const tmpCoordsPt = wktGeometry.match(/POINT \((.*)\)/i);
|
|
88
|
+
if (!tmpCoordsStr && !tmpCoordsPt) {
|
|
55
89
|
return null;
|
|
56
90
|
}
|
|
91
|
+
|
|
92
|
+
if (tmpCoordsPt) {
|
|
93
|
+
const [lng, lat] = tmpCoordsPt[1].split(' ');
|
|
94
|
+
return [new Coordinates(Number(lat), Number(lng))];
|
|
95
|
+
}
|
|
96
|
+
|
|
57
97
|
return tmpCoordsStr[1].split(',').map(str => {
|
|
58
98
|
const sp = str.trim().split(' ');
|
|
59
99
|
return new Coordinates(Number(sp[1]), Number(sp[0]));
|
|
@@ -105,12 +145,21 @@ export function createRouterResponseFromJson(json) {
|
|
|
105
145
|
|
|
106
146
|
// Do not know if it the best approach, but it works...
|
|
107
147
|
const allJsonTrips = json.Data.reduce((acc, dataObj) => {
|
|
108
|
-
acc.push(...dataObj.response.trips.Trip
|
|
148
|
+
acc.push(...dataObj.response.trips.Trip.map(trip => ({
|
|
149
|
+
...trip,
|
|
150
|
+
...(dataObj.hasOwnProperty('PlanTripType') ? {PlanTripType: dataObj.PlanTripType} : {})
|
|
151
|
+
})));
|
|
109
152
|
return acc;
|
|
110
153
|
}, []);
|
|
111
154
|
|
|
155
|
+
// eslint-disable-next-line no-labels
|
|
156
|
+
itineraryLoop:
|
|
112
157
|
for (const trip of allJsonTrips) {
|
|
113
158
|
|
|
159
|
+
if (trip.hasOwnProperty('PlanTripType') && planTripType.get(trip.PlanTripType) === Constants.ROUTING_MODE.UNKNOWN) {
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
|
|
114
163
|
const itinerary = new Itinerary();
|
|
115
164
|
|
|
116
165
|
itinerary.duration = parseDuration(trip.Duration);
|
|
@@ -118,7 +167,6 @@ export function createRouterResponseFromJson(json) {
|
|
|
118
167
|
itinerary.from = jsonToCoordinates(trip.Departure.Site.Position);
|
|
119
168
|
itinerary.endTime = jsonDateToTimestamp(trip.Arrival.Time);
|
|
120
169
|
itinerary.to = jsonToCoordinates(trip.Arrival.Site.Position);
|
|
121
|
-
routerResponse.itineraries.push(itinerary);
|
|
122
170
|
|
|
123
171
|
for (const jsonSection of trip.sections.Section) {
|
|
124
172
|
|
|
@@ -132,7 +180,14 @@ export function createRouterResponseFromJson(json) {
|
|
|
132
180
|
leg.endTime = jsonDateToTimestamp(jsonLeg.Arrival.Time);
|
|
133
181
|
leg.coords = [];
|
|
134
182
|
|
|
135
|
-
if (leg.mode === Constants.ROUTING_MODE.
|
|
183
|
+
if (leg.mode === Constants.ROUTING_MODE.UNKNOWN) {
|
|
184
|
+
// eslint-disable-next-line
|
|
185
|
+
continue itineraryLoop;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
if (leg.mode === Constants.ROUTING_MODE.WALK
|
|
189
|
+
|| leg.mode === Constants.ROUTING_MODE.BIKE
|
|
190
|
+
|| leg.mode === Constants.ROUTING_MODE.CAR) {
|
|
136
191
|
|
|
137
192
|
leg.from = {
|
|
138
193
|
name: jsonLeg.Departure.Site.Name,
|
|
@@ -185,7 +240,7 @@ export function createRouterResponseFromJson(json) {
|
|
|
185
240
|
};
|
|
186
241
|
|
|
187
242
|
let transportName = jsonLeg.Line.Number;
|
|
188
|
-
if (leg.mode === Constants.ROUTING_MODE.TRAM) {
|
|
243
|
+
if (leg.mode === Constants.ROUTING_MODE.TRAM && transportName.toLowerCase().includes('tram')) {
|
|
189
244
|
// In order to remove the "TRAM " prefix.
|
|
190
245
|
transportName = transportName.substr(5);
|
|
191
246
|
}
|
|
@@ -218,7 +273,7 @@ export function createRouterResponseFromJson(json) {
|
|
|
218
273
|
legStep.distance = jsonLeg.Distance;
|
|
219
274
|
leg.steps = [legStep];
|
|
220
275
|
} else {
|
|
221
|
-
Logger.warn(`[CitywayParser] Unknown leg mode: ${
|
|
276
|
+
Logger.warn(`[CitywayParser] Unknown leg mode: ${jsonLeg.TransportMode}`);
|
|
222
277
|
}
|
|
223
278
|
|
|
224
279
|
leg.distance = leg.coords.reduce((acc, coords, idx, arr) => {
|
|
@@ -232,6 +287,8 @@ export function createRouterResponseFromJson(json) {
|
|
|
232
287
|
|
|
233
288
|
}
|
|
234
289
|
|
|
290
|
+
routerResponse.itineraries.push(itinerary);
|
|
291
|
+
|
|
235
292
|
itinerary.distance = itinerary.coords.reduce((acc, coords, idx, arr) => {
|
|
236
293
|
if (idx === 0) {
|
|
237
294
|
return acc;
|
package/src/idfm/IdfmUtils.js
CHANGED
|
@@ -31,6 +31,7 @@ routingModeCorrespondance.set('Shuttle', Constants.ROUTING_MODE.BUS);
|
|
|
31
31
|
routingModeCorrespondance.set('SuspendedCableCar', Constants.ROUTING_MODE.FUNICULAR);
|
|
32
32
|
routingModeCorrespondance.set('Taxi', Constants.ROUTING_MODE.TAXI);
|
|
33
33
|
routingModeCorrespondance.set('Train', Constants.ROUTING_MODE.TRAIN);
|
|
34
|
+
routingModeCorrespondance.set('RER', Constants.ROUTING_MODE.TRAIN);
|
|
34
35
|
routingModeCorrespondance.set('Tramway', Constants.ROUTING_MODE.TRAM);
|
|
35
36
|
routingModeCorrespondance.set('walking', Constants.ROUTING_MODE.WALK);
|
|
36
37
|
routingModeCorrespondance.set('bike', Constants.ROUTING_MODE.BIKE);
|
|
@@ -83,6 +84,14 @@ function findStepsCoord(leg) {
|
|
|
83
84
|
} else if (idx === steps.length - 1) {
|
|
84
85
|
step._idCoordsInLeg = coords.length - 1;
|
|
85
86
|
newCoords = last(coords);
|
|
87
|
+
} else if (duplicatedCoords.length === 1) {
|
|
88
|
+
accumulatedIndex++;
|
|
89
|
+
|
|
90
|
+
step._idCoordsInLeg = accumulatedIndex;
|
|
91
|
+
|
|
92
|
+
newCoords = duplicatedCoords[0];
|
|
93
|
+
|
|
94
|
+
coords[step._idCoordsInLeg] = newCoords;
|
|
86
95
|
} else {
|
|
87
96
|
const result = GeoUtils.trimRoute(duplicatedCoords, duplicatedCoords[0], previousStep.distance);
|
|
88
97
|
accumulatedIndex += result.length - 1;
|