@wemap/routers 12.8.8 → 12.8.10

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.
@@ -0,0 +1,50 @@
1
+ <?xml version='1.0' encoding='UTF-8'?>
2
+ <osm version='0.6' generator='JOSM'>
3
+ <node id='-43815' action='modify' visible='true' lat='48.89073902269' lon='2.23810233326'>
4
+ <tag k='name' v='v2' />
5
+ </node>
6
+ <node id='-43816' action='modify' visible='true' lat='48.8907166353' lon='2.23808642232'>
7
+ <tag k='name' v='v3' />
8
+ </node>
9
+ <node id='-43817' action='modify' visible='true' lat='48.89054309994' lon='2.23798341388'>
10
+ <tag k='name' v='v5' />
11
+ </node>
12
+ <node id='-43818' action='modify' visible='true' lat='48.89060187357' lon='2.23800066233'>
13
+ <tag k='name' v='v4' />
14
+ </node>
15
+ <node id='-43819' action='modify' visible='true' lat='48.89108123139' lon='2.23733246058' />
16
+ <node id='-43820' action='modify' visible='true' lat='48.89109533964' lon='2.23923682898' />
17
+ <node id='-43821' action='modify' visible='true' lat='48.89001604646' lon='2.23910540074' />
18
+ <node id='-43822' action='modify' visible='true' lat='48.89003015502' lon='2.23708837956' />
19
+ <way id='-8258' action='modify' visible='true'>
20
+ <nd ref='-43815' />
21
+ <nd ref='-43816' />
22
+ <tag k='highway' v='footway' />
23
+ <tag k='level' v='0' />
24
+ <tag k='name' v='w1' />
25
+ </way>
26
+ <way id='-8259' action='modify' visible='true'>
27
+ <nd ref='-43818' />
28
+ <nd ref='-43817' />
29
+ <tag k='highway' v='footway' />
30
+ <tag k='level' v='1' />
31
+ <tag k='name' v='w3' />
32
+ </way>
33
+ <way id='-8260' action='modify' visible='true'>
34
+ <nd ref='-43816' />
35
+ <nd ref='-43818' />
36
+ <tag k='conveying' v='forward' />
37
+ <tag k='highway' v='steps' />
38
+ <tag k='incline' v='up' />
39
+ <tag k='level' v='0;1' />
40
+ <tag k='name' v='w2' />
41
+ </way>
42
+ <way id='-8261' action='modify' visible='true'>
43
+ <nd ref='-43819' />
44
+ <nd ref='-43820' />
45
+ <nd ref='-43821' />
46
+ <nd ref='-43822' />
47
+ <nd ref='-43819' />
48
+ <tag k='wemap:routing-bounds' v='yes' />
49
+ </way>
50
+ </osm>
package/dist/index.js CHANGED
@@ -449,7 +449,7 @@ class StepsBuilder {
449
449
  const forceEndOfLevelChange = Boolean(
450
450
  previousEdgeProperties.incline && previousEdgeProperties.areStairs && (!incline || !areStairs)
451
451
  );
452
- const createNewStep = vertex.properties.isSubwayEntrance;
452
+ const isEntrance = vertex.properties.isSubwayEntrance;
453
453
  const stepName = edge.properties.name || null;
454
454
  const duration = graphRoute.edgesWeights[i];
455
455
  const stepExtras = {
@@ -461,7 +461,7 @@ class StepsBuilder {
461
461
  const splitByLevel = geo.Level.isRange(edge.level) && !geo.Level.isRange(currentCoords.level) || forceLevelChange;
462
462
  splitByAngle = splitByAngle && !(currentCoords.level && geo.Level.isRange(currentCoords.level));
463
463
  const splitByEndOfLevelChange = (previousStep == null ? void 0 : previousStep.levelChange) && !geo.Level.isRange(currentCoords.level) || forceEndOfLevelChange;
464
- const splitStepCondition = splitByAngle || splitByLevel || splitByEndOfLevelChange || createNewStep;
464
+ const splitStepCondition = splitByAngle || splitByLevel || splitByEndOfLevelChange || isEntrance;
465
465
  if (isFirstStep || splitStepCondition) {
466
466
  let levelChange;
467
467
  if (splitByLevel) {
@@ -2788,7 +2788,10 @@ const _OsmGraphUtils = class _OsmGraphUtils {
2788
2788
  })) == null ? void 0 : _a[1]) || null;
2789
2789
  if (vertex) {
2790
2790
  if (!geo.Level.equals(vertex.coords.level, nodeLevel)) {
2791
- vertex.coords.level = geo.Level.intersection(vertex.coords.level, nodeLevel) || nodeLevel;
2791
+ vertex.coords.level = geo.Level.intersection(vertex.coords.level, nodeLevel);
2792
+ if (vertex.coords.level === null) {
2793
+ vertex.coords.level = nodeLevel;
2794
+ }
2792
2795
  }
2793
2796
  return vertex;
2794
2797
  }
@@ -2875,6 +2878,7 @@ var StatusCode = /* @__PURE__ */ ((StatusCode2) => {
2875
2878
  StatusCode2[StatusCode2["UNIMPLEMENTED"] = 12] = "UNIMPLEMENTED";
2876
2879
  StatusCode2[StatusCode2["INTERNAL"] = 13] = "INTERNAL";
2877
2880
  StatusCode2[StatusCode2["UNAVAILABLE"] = 14] = "UNAVAILABLE";
2881
+ StatusCode2[StatusCode2["UNAUTHENTICATED"] = 16] = "UNAUTHENTICATED";
2878
2882
  return StatusCode2;
2879
2883
  })(StatusCode || {});
2880
2884
  class RoutingError extends Error {
@@ -2908,6 +2912,9 @@ class RemoteRoutingError extends RoutingError {
2908
2912
  static notFound(routerName, details) {
2909
2913
  return new RemoteRoutingError(StatusCode.NOT_FOUND, routerName, `Cannot found an itinerary with ${routerName}. Details: ${details}`);
2910
2914
  }
2915
+ static missingApiKey(routerName, details) {
2916
+ return new RemoteRoutingError(StatusCode.UNAUTHENTICATED, routerName, `API key is missing for ${routerName}. Details: ${details}`);
2917
+ }
2911
2918
  static unreachableServer(routerName, url) {
2912
2919
  return new RemoteRoutingError(StatusCode.NOT_FOUND, routerName, `Remote router server ${routerName} is unreachable. URL: ${url}`);
2913
2920
  }
@@ -2926,7 +2933,7 @@ function dateWithTimeZone(year, month, day, hour, minute, second, timeZone = "Eu
2926
2933
  date.setTime(date.getTime() + offset);
2927
2934
  return date;
2928
2935
  }
2929
- function jsonToCoordinates$2(json) {
2936
+ function jsonToCoordinates$3(json) {
2930
2937
  return new geo.Coordinates(json.Lat, json.Long);
2931
2938
  }
2932
2939
  function jsonDateToTimestamp(jsonDate) {
@@ -2947,29 +2954,29 @@ inputModeCorrespondance$1.set("CAR", "Car");
2947
2954
  inputModeCorrespondance$1.set("WALK", "Walk");
2948
2955
  inputModeCorrespondance$1.set("BIKE", "Bike");
2949
2956
  inputModeCorrespondance$1.set("TRANSIT", "PT");
2950
- const transitModeCorrespondance$2 = /* @__PURE__ */ new Map();
2951
- transitModeCorrespondance$2.set("WALK", "WALK");
2952
- transitModeCorrespondance$2.set("BICYCLE", "BIKE");
2953
- transitModeCorrespondance$2.set("TRAMWAY", "TRAM");
2954
- transitModeCorrespondance$2.set("METRO", "METRO");
2955
- transitModeCorrespondance$2.set("FUNICULAR", "FUNICULAR");
2956
- transitModeCorrespondance$2.set("BUS", "BUS");
2957
- transitModeCorrespondance$2.set("COACH", "BUS");
2958
- transitModeCorrespondance$2.set("SCHOOL", "BUS");
2959
- transitModeCorrespondance$2.set("BUS_PMR", "BUS");
2960
- transitModeCorrespondance$2.set("MINIBUS", "BUS");
2961
- transitModeCorrespondance$2.set("TROLLEY_BUS", "BUS");
2962
- transitModeCorrespondance$2.set("TAXIBUS", "BUS");
2963
- transitModeCorrespondance$2.set("SHUTTLE", "BUS");
2964
- transitModeCorrespondance$2.set("TRAIN", "TRAIN");
2965
- transitModeCorrespondance$2.set("HST", "TRAIN");
2966
- transitModeCorrespondance$2.set("LOCAL_TRAIN", "TRAIN");
2967
- transitModeCorrespondance$2.set("AIR", "AIRPLANE");
2968
- transitModeCorrespondance$2.set("FERRY", "BOAT");
2969
- transitModeCorrespondance$2.set("TAXI", "UNKNOWN");
2970
- transitModeCorrespondance$2.set("CAR_POOL", "UNKNOWN");
2971
- transitModeCorrespondance$2.set("PRIVATE_VEHICLE", "CAR");
2972
- transitModeCorrespondance$2.set("SCOOTER", "MOTO");
2957
+ const transitModeCorrespondance$3 = /* @__PURE__ */ new Map();
2958
+ transitModeCorrespondance$3.set("WALK", "WALK");
2959
+ transitModeCorrespondance$3.set("BICYCLE", "BIKE");
2960
+ transitModeCorrespondance$3.set("TRAMWAY", "TRAM");
2961
+ transitModeCorrespondance$3.set("METRO", "METRO");
2962
+ transitModeCorrespondance$3.set("FUNICULAR", "FUNICULAR");
2963
+ transitModeCorrespondance$3.set("BUS", "BUS");
2964
+ transitModeCorrespondance$3.set("COACH", "BUS");
2965
+ transitModeCorrespondance$3.set("SCHOOL", "BUS");
2966
+ transitModeCorrespondance$3.set("BUS_PMR", "BUS");
2967
+ transitModeCorrespondance$3.set("MINIBUS", "BUS");
2968
+ transitModeCorrespondance$3.set("TROLLEY_BUS", "BUS");
2969
+ transitModeCorrespondance$3.set("TAXIBUS", "BUS");
2970
+ transitModeCorrespondance$3.set("SHUTTLE", "BUS");
2971
+ transitModeCorrespondance$3.set("TRAIN", "TRAIN");
2972
+ transitModeCorrespondance$3.set("HST", "TRAIN");
2973
+ transitModeCorrespondance$3.set("LOCAL_TRAIN", "TRAIN");
2974
+ transitModeCorrespondance$3.set("AIR", "AIRPLANE");
2975
+ transitModeCorrespondance$3.set("FERRY", "BOAT");
2976
+ transitModeCorrespondance$3.set("TAXI", "UNKNOWN");
2977
+ transitModeCorrespondance$3.set("CAR_POOL", "UNKNOWN");
2978
+ transitModeCorrespondance$3.set("PRIVATE_VEHICLE", "CAR");
2979
+ transitModeCorrespondance$3.set("SCOOTER", "MOTO");
2973
2980
  const planTripType = /* @__PURE__ */ new Map();
2974
2981
  planTripType.set(0, "BUS");
2975
2982
  planTripType.set(1, "WALK");
@@ -3052,7 +3059,7 @@ class CitywayRemoteRouter extends RemoteRouter {
3052
3059
  const legs = [];
3053
3060
  for (const jsonSection of trip.sections.Section) {
3054
3061
  const jsonLeg = jsonSection.Leg ? jsonSection.Leg : jsonSection.PTRide;
3055
- const legMode = transitModeCorrespondance$2.get(jsonLeg.TransportMode);
3062
+ const legMode = transitModeCorrespondance$3.get(jsonLeg.TransportMode);
3056
3063
  const legCoords = [];
3057
3064
  let legStart, legEnd;
3058
3065
  let transportInfo;
@@ -3063,11 +3070,11 @@ class CitywayRemoteRouter extends RemoteRouter {
3063
3070
  if (legMode === "WALK" || legMode === "BIKE" || legMode === "CAR") {
3064
3071
  legStart = {
3065
3072
  name: jsonLeg.Departure.Site.Name,
3066
- coords: jsonToCoordinates$2(jsonLeg.Departure.Site.Position)
3073
+ coords: jsonToCoordinates$3(jsonLeg.Departure.Site.Position)
3067
3074
  };
3068
3075
  legEnd = {
3069
3076
  name: jsonLeg.Arrival.Site.Name,
3070
- coords: jsonToCoordinates$2(jsonLeg.Arrival.Site.Position)
3077
+ coords: jsonToCoordinates$3(jsonLeg.Arrival.Site.Position)
3071
3078
  };
3072
3079
  for (const jsonPathLink of jsonLeg.pathLinks.PathLink) {
3073
3080
  let stepCoords;
@@ -3095,11 +3102,11 @@ class CitywayRemoteRouter extends RemoteRouter {
3095
3102
  } else if (isTransitModePublicTransport(legMode)) {
3096
3103
  legStart = {
3097
3104
  name: jsonLeg.Departure.StopPlace.Name,
3098
- coords: jsonToCoordinates$2(jsonLeg.Departure.StopPlace.Position)
3105
+ coords: jsonToCoordinates$3(jsonLeg.Departure.StopPlace.Position)
3099
3106
  };
3100
3107
  legEnd = {
3101
3108
  name: jsonLeg.Arrival.StopPlace.Name,
3102
- coords: jsonToCoordinates$2(jsonLeg.Arrival.StopPlace.Position)
3109
+ coords: jsonToCoordinates$3(jsonLeg.Arrival.StopPlace.Position)
3103
3110
  };
3104
3111
  let transportName = jsonLeg.Line.Number;
3105
3112
  if (legMode === "TRAM" && transportName.toLowerCase().includes("tram")) {
@@ -3147,9 +3154,9 @@ class CitywayRemoteRouter extends RemoteRouter {
3147
3154
  const itinerary = new Itinerary({
3148
3155
  duration: this.parseDuration(trip.Duration),
3149
3156
  startTime: jsonDateToTimestamp(trip.Departure.Time),
3150
- origin: jsonToCoordinates$2(trip.Departure.Site.Position),
3157
+ origin: jsonToCoordinates$3(trip.Departure.Site.Position),
3151
3158
  endTime: jsonDateToTimestamp(trip.Arrival.Time),
3152
- destination: jsonToCoordinates$2(trip.Arrival.Site.Position),
3159
+ destination: jsonToCoordinates$3(trip.Arrival.Site.Position),
3153
3160
  legs
3154
3161
  });
3155
3162
  itineraries.push(itinerary);
@@ -3174,6 +3181,336 @@ class CitywayRemoteRouter extends RemoteRouter {
3174
3181
  }
3175
3182
  }
3176
3183
  const CitywayRemoteRouter$1 = new CitywayRemoteRouter();
3184
+ const transitModeCorrespondance$2 = /* @__PURE__ */ new Map();
3185
+ transitModeCorrespondance$2.set("Air", "AIRPLANE");
3186
+ transitModeCorrespondance$2.set("Boat", "BOAT");
3187
+ transitModeCorrespondance$2.set("Bus", "BUS");
3188
+ transitModeCorrespondance$2.set("BusRapidTransit", "BUS");
3189
+ transitModeCorrespondance$2.set("Coach", "BUS");
3190
+ transitModeCorrespondance$2.set("Ferry", "FERRY");
3191
+ transitModeCorrespondance$2.set("Funicular", "FUNICULAR");
3192
+ transitModeCorrespondance$2.set("LocalTrain", "TRAIN");
3193
+ transitModeCorrespondance$2.set("LongDistanceTrain", "TRAIN");
3194
+ transitModeCorrespondance$2.set("Metro", "METRO");
3195
+ transitModeCorrespondance$2.set("Métro", "METRO");
3196
+ transitModeCorrespondance$2.set("RailShuttle", "TRAIN");
3197
+ transitModeCorrespondance$2.set("RapidTransit", "BUS");
3198
+ transitModeCorrespondance$2.set("Shuttle", "BUS");
3199
+ transitModeCorrespondance$2.set("SuspendedCableCar", "FUNICULAR");
3200
+ transitModeCorrespondance$2.set("Taxi", "TAXI");
3201
+ transitModeCorrespondance$2.set("Train", "TRAIN");
3202
+ transitModeCorrespondance$2.set("RER", "TRAIN");
3203
+ transitModeCorrespondance$2.set("Tramway", "TRAM");
3204
+ transitModeCorrespondance$2.set("walking", "WALK");
3205
+ transitModeCorrespondance$2.set("bike", "BIKE");
3206
+ const TRANSPORT_IDS$1 = [
3207
+ "physical_mode:Air",
3208
+ "physical_mode:Boat",
3209
+ "physical_mode:Bus",
3210
+ "physical_mode:BusRapidTransit",
3211
+ "physical_mode:Coach",
3212
+ "physical_mode:Ferry",
3213
+ "physical_mode:Funicular",
3214
+ "physical_mode:LocalTrain",
3215
+ "physical_mode:LongDistanceTrain",
3216
+ "physical_mode:Metro",
3217
+ "physical_mode:RailShuttle",
3218
+ "physical_mode:RapidTransit",
3219
+ "physical_mode:Shuttle",
3220
+ "physical_mode:SuspendedCableCar",
3221
+ "physical_mode:Taxi",
3222
+ "physical_mode:Train",
3223
+ "physical_mode:Tramway"
3224
+ ];
3225
+ function jsonToCoordinates$2(json) {
3226
+ return new geo.Coordinates(Number(json.lat), Number(json.lon));
3227
+ }
3228
+ function last$2(array) {
3229
+ return array[array.length - 1];
3230
+ }
3231
+ function dateStringToTimestamp$1(stringDate, timeZone) {
3232
+ const yearStr = stringDate.substr(0, 4);
3233
+ const monthStr = stringDate.substr(4, 2);
3234
+ const dayStr = stringDate.substr(6, 2);
3235
+ const hoursStr = stringDate.substr(9, 2);
3236
+ const minutesStr = stringDate.substr(11, 2);
3237
+ const secondsStr = stringDate.substr(13, 2);
3238
+ return dateWithTimeZone(
3239
+ Number(yearStr),
3240
+ Number(monthStr) - 1,
3241
+ Number(dayStr),
3242
+ Number(hoursStr),
3243
+ Number(minutesStr),
3244
+ Number(secondsStr),
3245
+ timeZone
3246
+ ).getTime();
3247
+ }
3248
+ class NavitiaRemoteRouter extends RemoteRouter {
3249
+ get rname() {
3250
+ return "navitia";
3251
+ }
3252
+ async getItineraries(endpointUrl, routerRequest) {
3253
+ const url = this.getURL(endpointUrl, routerRequest);
3254
+ const api_key = url.searchParams.get("api_key");
3255
+ if (!api_key) {
3256
+ throw RemoteRoutingError.missingApiKey(this.rname);
3257
+ }
3258
+ const res = await fetch(url, {
3259
+ method: "GET",
3260
+ headers: {
3261
+ "Authorization": api_key
3262
+ }
3263
+ }).catch(() => {
3264
+ throw RemoteRoutingError.unreachableServer(this.rname, url.toString());
3265
+ });
3266
+ const jsonResponse = await res.json().catch(() => {
3267
+ throw RemoteRoutingError.responseNotParsing(this.rname, url.toString());
3268
+ });
3269
+ if (jsonResponse && jsonResponse.error) {
3270
+ throw RemoteRoutingError.notFound(this.rname, jsonResponse.error.message);
3271
+ }
3272
+ const itineraries = this.parseResponse(jsonResponse);
3273
+ const sameModeFound = itineraries.some((itinerary) => areTransitAndTravelModeConsistent(itinerary.transitMode, routerRequest.travelMode));
3274
+ if (!sameModeFound) {
3275
+ throw RemoteRoutingError.notFound(
3276
+ this.rname,
3277
+ "Selected mode of transport was not found for this itinerary."
3278
+ );
3279
+ }
3280
+ return itineraries;
3281
+ }
3282
+ getURL(endpointUrl, routerRequest) {
3283
+ var _a;
3284
+ const { origin, destination, waypoints, travelMode } = routerRequest;
3285
+ if ((waypoints || []).length > 0) {
3286
+ Logger.warn(`${this.rname} router uses only the first 2 waypoints (asked ${waypoints == null ? void 0 : waypoints.length})`);
3287
+ }
3288
+ const url = new URL(endpointUrl);
3289
+ const coreParams = new URLSearchParams();
3290
+ coreParams.set("from", `${origin.longitude};${origin.latitude}`);
3291
+ coreParams.set("to", `${destination.longitude};${destination.latitude}`);
3292
+ coreParams.set("data_freshness", "realtime");
3293
+ if ((_a = routerRequest.itineraryModifiers) == null ? void 0 : _a.avoidStairs) {
3294
+ coreParams.set("wheelchair", "true");
3295
+ }
3296
+ let queryParams = new URLSearchParams();
3297
+ switch (travelMode) {
3298
+ case "WALK":
3299
+ queryParams = this.getWalkingQuery();
3300
+ break;
3301
+ case "BIKE":
3302
+ queryParams = this.getBikeQuery();
3303
+ break;
3304
+ case "CAR":
3305
+ queryParams = this.getCarQuery();
3306
+ break;
3307
+ }
3308
+ [coreParams, queryParams].map((params) => {
3309
+ for (const pair of params.entries()) {
3310
+ url.searchParams.append(pair[0], pair[1]);
3311
+ }
3312
+ });
3313
+ return url;
3314
+ }
3315
+ getCarQuery() {
3316
+ const urlSearchParams = new URLSearchParams();
3317
+ TRANSPORT_IDS$1.forEach((id) => {
3318
+ urlSearchParams.append("forbidden_uris[]", id);
3319
+ });
3320
+ urlSearchParams.append("first_section_mode[]", "walking");
3321
+ urlSearchParams.append("first_section_mode[]", "car");
3322
+ urlSearchParams.append("last_section_mode[]", "walking");
3323
+ urlSearchParams.append("last_section_mode[]", "car");
3324
+ return urlSearchParams;
3325
+ }
3326
+ getWalkingQuery() {
3327
+ const urlSearchParams = new URLSearchParams();
3328
+ TRANSPORT_IDS$1.forEach((id) => {
3329
+ urlSearchParams.append("forbidden_uris[]", id);
3330
+ });
3331
+ urlSearchParams.append("first_section_mode[]", "walking");
3332
+ urlSearchParams.append("last_section_mode[]", "walking");
3333
+ return urlSearchParams;
3334
+ }
3335
+ getBikeQuery() {
3336
+ const urlSearchParams = new URLSearchParams();
3337
+ TRANSPORT_IDS$1.forEach((id) => {
3338
+ urlSearchParams.append("forbidden_uris[]", id);
3339
+ });
3340
+ urlSearchParams.append("first_section_mode[]", "bike");
3341
+ urlSearchParams.append("last_section_mode[]", "bike");
3342
+ return urlSearchParams;
3343
+ }
3344
+ getSectionCoords(section) {
3345
+ let from;
3346
+ let to;
3347
+ if ("stop_point" in section.from) {
3348
+ from = section.from.stop_point.coord;
3349
+ } else if ("address" in section.from) {
3350
+ from = section.from.address.coord;
3351
+ } else {
3352
+ from = section.from.poi.coord;
3353
+ }
3354
+ if ("stop_point" in section.to) {
3355
+ to = section.to.stop_point.coord;
3356
+ } else if ("address" in section.to) {
3357
+ to = section.to.address.coord;
3358
+ } else {
3359
+ to = section.to.poi.coord;
3360
+ }
3361
+ return {
3362
+ from: jsonToCoordinates$2(from),
3363
+ to: jsonToCoordinates$2(to)
3364
+ };
3365
+ }
3366
+ /**
3367
+ * Since the navitia API does not provide coords for each step, we need to compute them
3368
+ * We trim the coordinates of the leg with the distance of each step and keep the last result as the coords of the step
3369
+ * @param {Leg} leg
3370
+ */
3371
+ findStepsCoord(legCoords, steps) {
3372
+ const coords = legCoords;
3373
+ const duplicatedCoords = [...coords];
3374
+ let previousStep = steps[0];
3375
+ let accumulatedIndex = 0;
3376
+ const outputSteps = [];
3377
+ for (const [idx, step] of steps.entries()) {
3378
+ let newCoords;
3379
+ let _idCoordsInLeg;
3380
+ if (idx === 0) {
3381
+ _idCoordsInLeg = 0;
3382
+ newCoords = coords[0];
3383
+ } else if (idx === steps.length - 1) {
3384
+ _idCoordsInLeg = coords.length - 1;
3385
+ newCoords = last$2(coords);
3386
+ } else if (duplicatedCoords.length === 1) {
3387
+ accumulatedIndex++;
3388
+ _idCoordsInLeg = accumulatedIndex;
3389
+ newCoords = duplicatedCoords[0];
3390
+ coords[_idCoordsInLeg] = newCoords;
3391
+ } else {
3392
+ const result = geo.Utils.trimRoute(duplicatedCoords, duplicatedCoords[0], previousStep.distance);
3393
+ accumulatedIndex += result.length - 1;
3394
+ duplicatedCoords.splice(0, result.length - 1);
3395
+ _idCoordsInLeg = accumulatedIndex;
3396
+ newCoords = last$2(result);
3397
+ coords[_idCoordsInLeg] = newCoords;
3398
+ }
3399
+ outputSteps.push({
3400
+ ...step,
3401
+ coords: newCoords
3402
+ });
3403
+ previousStep = step;
3404
+ }
3405
+ return outputSteps;
3406
+ }
3407
+ findStepCoords(step, section) {
3408
+ var _a;
3409
+ if ("instruction_start_coordinate" in step) {
3410
+ return jsonToCoordinates$2(step.instruction_start_coordinate);
3411
+ }
3412
+ const via = (_a = section.vias) == null ? void 0 : _a.find((via2) => via2.id === step.via_uri);
3413
+ if (via) {
3414
+ return jsonToCoordinates$2(via.access_point.coord);
3415
+ }
3416
+ }
3417
+ parseResponse(json) {
3418
+ var _a;
3419
+ if (!json || !json.journeys) {
3420
+ throw RemoteRoutingError.notFound(this.rname, (_a = json.error) == null ? void 0 : _a.message);
3421
+ }
3422
+ const itineraries = [];
3423
+ const timeZone = json.context.timezone;
3424
+ for (const jsonItinerary of json.journeys) {
3425
+ const legs = [];
3426
+ for (const jsonSection of jsonItinerary.sections) {
3427
+ if (jsonSection.type === "waiting" || jsonSection.type === "transfer") {
3428
+ continue;
3429
+ }
3430
+ const { from: startSection, to: endSection } = this.getSectionCoords(jsonSection);
3431
+ let existingCoords = [];
3432
+ const legCoords = jsonSection.geojson.coordinates.reduce((acc, [lon, lat]) => {
3433
+ if (!existingCoords.includes(`${lon}-${lat}`)) {
3434
+ existingCoords = existingCoords.concat(`${lon}-${lat}`);
3435
+ acc.push(new geo.Coordinates(lat, lon));
3436
+ }
3437
+ return acc;
3438
+ }, []);
3439
+ const stepsBuilder = new StepsBuilder().setStart(startSection).setEnd(endSection).setPathCoords(legCoords);
3440
+ let transportInfo;
3441
+ let transitMode = transitModeCorrespondance$2.get(jsonSection.mode);
3442
+ if (jsonSection.path) {
3443
+ const useNavitiaSteps = jsonSection.path.every((step) => "instruction_start_coordinate" in step || step.via_uri);
3444
+ const navitiaIntermediateSteps = [];
3445
+ for (const jsonPathLink of jsonSection.path) {
3446
+ let coords;
3447
+ if (useNavitiaSteps) {
3448
+ coords = this.findStepCoords(jsonPathLink, jsonSection);
3449
+ const intermediateStep = {
3450
+ name: jsonPathLink.name,
3451
+ distance: jsonPathLink.length,
3452
+ coords
3453
+ };
3454
+ stepsBuilder.addStepInfo(intermediateStep);
3455
+ } else {
3456
+ navitiaIntermediateSteps.push({
3457
+ name: jsonPathLink.name,
3458
+ distance: jsonPathLink.length
3459
+ });
3460
+ }
3461
+ }
3462
+ if (!useNavitiaSteps) {
3463
+ stepsBuilder.setStepsInfo(this.findStepsCoord(legCoords, navitiaIntermediateSteps));
3464
+ }
3465
+ }
3466
+ if (jsonSection.type === "public_transport") {
3467
+ transportInfo = {
3468
+ name: jsonSection.display_informations.code,
3469
+ routeColor: jsonSection.display_informations.color,
3470
+ routeTextColor: jsonSection.display_informations.text_color,
3471
+ directionName: jsonSection.display_informations.direction
3472
+ };
3473
+ transitMode = transitModeCorrespondance$2.get(jsonSection.display_informations.physical_mode);
3474
+ const legStep = {
3475
+ coords: legCoords[0],
3476
+ name: transportInfo.directionName,
3477
+ distance: jsonSection.geojson.properties[0].length
3478
+ };
3479
+ stepsBuilder.setStepsInfo([legStep]);
3480
+ }
3481
+ const leg = new Leg({
3482
+ transitMode,
3483
+ duration: jsonSection.duration,
3484
+ startTime: dateStringToTimestamp$1(jsonSection.departure_date_time, timeZone),
3485
+ endTime: dateStringToTimestamp$1(jsonSection.arrival_date_time, timeZone),
3486
+ start: {
3487
+ name: jsonSection.from.name,
3488
+ coords: startSection
3489
+ },
3490
+ end: {
3491
+ name: jsonSection.to.name,
3492
+ coords: endSection
3493
+ },
3494
+ coords: legCoords,
3495
+ transportInfo,
3496
+ steps: stepsBuilder.build()
3497
+ });
3498
+ legs.push(leg);
3499
+ }
3500
+ const itinerary = new Itinerary({
3501
+ duration: jsonItinerary.duration,
3502
+ startTime: dateStringToTimestamp$1(jsonItinerary.departure_date_time, timeZone),
3503
+ endTime: dateStringToTimestamp$1(jsonItinerary.arrival_date_time, timeZone),
3504
+ origin: this.getSectionCoords(jsonItinerary.sections[0]).from,
3505
+ destination: this.getSectionCoords(last$2(jsonItinerary.sections)).to,
3506
+ legs
3507
+ });
3508
+ itineraries.push(itinerary);
3509
+ }
3510
+ return itineraries;
3511
+ }
3512
+ }
3513
+ const NavitiaRemoteRouter$1 = new NavitiaRemoteRouter();
3177
3514
  class DeutscheBahnRemoteRouter extends RemoteRouter {
3178
3515
  /**
3179
3516
  * @override
@@ -4069,6 +4406,7 @@ class WemapMultiRemoteRouter extends RemoteRouter {
4069
4406
  const WemapMultiRemoteRouter$1 = new WemapMultiRemoteRouter();
4070
4407
  const remoteRouters = [
4071
4408
  CitywayRemoteRouter$1,
4409
+ NavitiaRemoteRouter$1,
4072
4410
  DeutscheBahnRemoteRouter$1,
4073
4411
  IdfmRemoteRouter$1,
4074
4412
  OsrmRemoteRouter$1,
@@ -4732,6 +5070,7 @@ exports.InstructionManager = InstructionManager;
4732
5070
  exports.Itinerary = Itinerary;
4733
5071
  exports.ItineraryInfoManager = ItineraryInfoManager;
4734
5072
  exports.Leg = Leg;
5073
+ exports.NavitiaRemoteRouter = NavitiaRemoteRouter$1;
4735
5074
  exports.NoRouteFoundError = NoRouteFoundError;
4736
5075
  exports.OsmGraphUtils = OsmGraphUtils;
4737
5076
  exports.OsrmRemoteRouter = OsrmRemoteRouter$1;