@wemap/routers 12.8.5 → 12.8.6
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/assets/geovelo-montpellier.json +1144 -0
- package/dist/index.js +174 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +174 -26
- package/dist/index.mjs.map +1 -1
- package/index.ts +1 -0
- package/package.json +2 -2
- package/src/remote/geovelo/GeoveloRemoteRouter.spec.ts +54 -0
- package/src/remote/geovelo/GeoveloRemoteRouter.ts +290 -0
- package/src/remote/idfm/IdfmRemoteRouter.ts +7 -0
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ const maths = require("@wemap/maths");
|
|
|
11
11
|
const Logger = require("@wemap/logger");
|
|
12
12
|
const salesman = require("@wemap/salesman.js");
|
|
13
13
|
const osm = require("@wemap/osm");
|
|
14
|
-
const
|
|
14
|
+
const polyline = require("@mapbox/polyline");
|
|
15
15
|
const pointInPolygon = require("@turf/boolean-point-in-polygon");
|
|
16
16
|
const convexHullFn = require("@turf/convex");
|
|
17
17
|
function routerRequestToJson(routerRequest) {
|
|
@@ -2947,29 +2947,29 @@ inputModeCorrespondance$1.set("CAR", "Car");
|
|
|
2947
2947
|
inputModeCorrespondance$1.set("WALK", "Walk");
|
|
2948
2948
|
inputModeCorrespondance$1.set("BIKE", "Bike");
|
|
2949
2949
|
inputModeCorrespondance$1.set("TRANSIT", "PT");
|
|
2950
|
-
const transitModeCorrespondance$
|
|
2951
|
-
transitModeCorrespondance$
|
|
2952
|
-
transitModeCorrespondance$
|
|
2953
|
-
transitModeCorrespondance$
|
|
2954
|
-
transitModeCorrespondance$
|
|
2955
|
-
transitModeCorrespondance$
|
|
2956
|
-
transitModeCorrespondance$
|
|
2957
|
-
transitModeCorrespondance$
|
|
2958
|
-
transitModeCorrespondance$
|
|
2959
|
-
transitModeCorrespondance$
|
|
2960
|
-
transitModeCorrespondance$
|
|
2961
|
-
transitModeCorrespondance$
|
|
2962
|
-
transitModeCorrespondance$
|
|
2963
|
-
transitModeCorrespondance$
|
|
2964
|
-
transitModeCorrespondance$
|
|
2965
|
-
transitModeCorrespondance$
|
|
2966
|
-
transitModeCorrespondance$
|
|
2967
|
-
transitModeCorrespondance$
|
|
2968
|
-
transitModeCorrespondance$
|
|
2969
|
-
transitModeCorrespondance$
|
|
2970
|
-
transitModeCorrespondance$
|
|
2971
|
-
transitModeCorrespondance$
|
|
2972
|
-
transitModeCorrespondance$
|
|
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");
|
|
2973
2973
|
const planTripType = /* @__PURE__ */ new Map();
|
|
2974
2974
|
planTripType.set(0, "BUS");
|
|
2975
2975
|
planTripType.set(1, "WALK");
|
|
@@ -3052,7 +3052,7 @@ class CitywayRemoteRouter extends RemoteRouter {
|
|
|
3052
3052
|
const legs = [];
|
|
3053
3053
|
for (const jsonSection of trip.sections.Section) {
|
|
3054
3054
|
const jsonLeg = jsonSection.Leg ? jsonSection.Leg : jsonSection.PTRide;
|
|
3055
|
-
const legMode = transitModeCorrespondance$
|
|
3055
|
+
const legMode = transitModeCorrespondance$2.get(jsonLeg.TransportMode);
|
|
3056
3056
|
const legCoords = [];
|
|
3057
3057
|
let legStart, legEnd;
|
|
3058
3058
|
let transportInfo;
|
|
@@ -3227,6 +3227,149 @@ class DeutscheBahnRemoteRouter extends RemoteRouter {
|
|
|
3227
3227
|
}
|
|
3228
3228
|
}
|
|
3229
3229
|
const DeutscheBahnRemoteRouter$1 = new DeutscheBahnRemoteRouter();
|
|
3230
|
+
function unpackJSON(data) {
|
|
3231
|
+
const headers = data[0];
|
|
3232
|
+
return data.slice(1).map((row) => {
|
|
3233
|
+
const obj = {};
|
|
3234
|
+
headers.forEach((header, index) => {
|
|
3235
|
+
obj[header] = row[index];
|
|
3236
|
+
});
|
|
3237
|
+
return obj;
|
|
3238
|
+
});
|
|
3239
|
+
}
|
|
3240
|
+
const transitModeCorrespondance$1 = /* @__PURE__ */ new Map();
|
|
3241
|
+
transitModeCorrespondance$1.set("BIKE", "BIKE");
|
|
3242
|
+
transitModeCorrespondance$1.set("PEDESTRIAN", "WALK");
|
|
3243
|
+
const apiKey$1 = "qWHj6ax6DMttG8DX6tH9CQARaiTgQ1Di";
|
|
3244
|
+
function waypointToCoordinates(waypoint) {
|
|
3245
|
+
return new geo.Coordinates(waypoint.latitude, waypoint.longitude);
|
|
3246
|
+
}
|
|
3247
|
+
function last$1(array) {
|
|
3248
|
+
return array[array.length - 1];
|
|
3249
|
+
}
|
|
3250
|
+
class GeoveloRemoteRouter extends RemoteRouter {
|
|
3251
|
+
/**
|
|
3252
|
+
* @override
|
|
3253
|
+
*/
|
|
3254
|
+
get rname() {
|
|
3255
|
+
return "geovelo";
|
|
3256
|
+
}
|
|
3257
|
+
async getItineraries(endpointUrl, routerRequest) {
|
|
3258
|
+
const queryParams = this.getQueryParams();
|
|
3259
|
+
const bodyParams = this.getBodyParams(routerRequest);
|
|
3260
|
+
const url = new URL(endpointUrl);
|
|
3261
|
+
for (const [key, value] of Object.entries(queryParams)) {
|
|
3262
|
+
url.searchParams.append(key, value.toString());
|
|
3263
|
+
}
|
|
3264
|
+
const res = await fetch(url, {
|
|
3265
|
+
method: "POST",
|
|
3266
|
+
headers: { apiKey: apiKey$1 },
|
|
3267
|
+
body: JSON.stringify(bodyParams)
|
|
3268
|
+
}).catch(() => {
|
|
3269
|
+
throw RemoteRoutingError.unreachableServer(this.rname, url.toString());
|
|
3270
|
+
});
|
|
3271
|
+
const jsonResponse = await res.json().catch(() => {
|
|
3272
|
+
throw RemoteRoutingError.responseNotParsing(this.rname, url.toString());
|
|
3273
|
+
});
|
|
3274
|
+
if (!jsonResponse || jsonResponse.length === 0) {
|
|
3275
|
+
throw RemoteRoutingError.notFound(this.rname, "No itineraries found.");
|
|
3276
|
+
}
|
|
3277
|
+
const itineraries = this.parseResponse(jsonResponse);
|
|
3278
|
+
return itineraries;
|
|
3279
|
+
}
|
|
3280
|
+
getQueryParams() {
|
|
3281
|
+
return {
|
|
3282
|
+
instructions: true,
|
|
3283
|
+
elevations: false,
|
|
3284
|
+
geometry: true,
|
|
3285
|
+
single_result: false,
|
|
3286
|
+
bike_stations: false,
|
|
3287
|
+
objects_as_ids: false,
|
|
3288
|
+
merge_instructions: true,
|
|
3289
|
+
show_pushing_bike_instructions: false
|
|
3290
|
+
};
|
|
3291
|
+
}
|
|
3292
|
+
getBodyParams(routerRequest) {
|
|
3293
|
+
const { origin, destination, waypoints } = routerRequest;
|
|
3294
|
+
let computedWaypoints = [];
|
|
3295
|
+
if (waypoints && waypoints.length > 1) {
|
|
3296
|
+
computedWaypoints = waypoints.map((waypoint) => ({
|
|
3297
|
+
longitude: waypoint.longitude,
|
|
3298
|
+
latitude: waypoint.latitude
|
|
3299
|
+
}));
|
|
3300
|
+
} else {
|
|
3301
|
+
computedWaypoints = [
|
|
3302
|
+
{ latitude: origin.latitude, longitude: origin.longitude },
|
|
3303
|
+
{ latitude: destination.latitude, longitude: destination.longitude }
|
|
3304
|
+
];
|
|
3305
|
+
}
|
|
3306
|
+
return {
|
|
3307
|
+
transportModes: ["BIKE"],
|
|
3308
|
+
waypoints: computedWaypoints
|
|
3309
|
+
};
|
|
3310
|
+
}
|
|
3311
|
+
parseResponse(json) {
|
|
3312
|
+
if (!json || !json.length) {
|
|
3313
|
+
throw RemoteRoutingError.notFound(this.rname);
|
|
3314
|
+
}
|
|
3315
|
+
const itineraries = [];
|
|
3316
|
+
for (const route of json) {
|
|
3317
|
+
const legs = [];
|
|
3318
|
+
for (const section of route.sections) {
|
|
3319
|
+
const from = waypointToCoordinates(section.waypoints[0]);
|
|
3320
|
+
const to = waypointToCoordinates(last$1(section.waypoints));
|
|
3321
|
+
const geometry = polyline.toGeoJSON(section.geometry, 6);
|
|
3322
|
+
let existingCoords = [];
|
|
3323
|
+
const legCoords = geometry.coordinates.reduce((acc, [lon, lat]) => {
|
|
3324
|
+
if (!existingCoords.includes(`${lon}-${lat}`)) {
|
|
3325
|
+
existingCoords = existingCoords.concat(`${lon}-${lat}`);
|
|
3326
|
+
acc.push(new geo.Coordinates(lat, lon));
|
|
3327
|
+
}
|
|
3328
|
+
return acc;
|
|
3329
|
+
}, []);
|
|
3330
|
+
const stepsBuilder = new StepsBuilder().setStart(from).setEnd(to).setPathCoords(legCoords);
|
|
3331
|
+
const transitMode = transitModeCorrespondance$1.get(section.transportMode);
|
|
3332
|
+
const unpackedIntructions = unpackJSON(section.details.instructions);
|
|
3333
|
+
for (const instruction of unpackedIntructions) {
|
|
3334
|
+
const { geometryIndex, roadLength, roadName } = instruction;
|
|
3335
|
+
const coordinates = geometry.coordinates[geometryIndex];
|
|
3336
|
+
const intermediateStep = {
|
|
3337
|
+
name: roadName,
|
|
3338
|
+
distance: roadLength,
|
|
3339
|
+
coords: new geo.Coordinates(coordinates[1], coordinates[0])
|
|
3340
|
+
};
|
|
3341
|
+
stepsBuilder.addStepInfo(intermediateStep);
|
|
3342
|
+
}
|
|
3343
|
+
const leg = new Leg({
|
|
3344
|
+
transitMode,
|
|
3345
|
+
duration: section.duration,
|
|
3346
|
+
startTime: new Date(section.estimatedDatetimeOfDeparture).getTime(),
|
|
3347
|
+
endTime: new Date(section.estimatedDatetimeOfArrival).getTime(),
|
|
3348
|
+
start: {
|
|
3349
|
+
coords: from
|
|
3350
|
+
},
|
|
3351
|
+
end: {
|
|
3352
|
+
coords: to
|
|
3353
|
+
},
|
|
3354
|
+
coords: legCoords,
|
|
3355
|
+
steps: stepsBuilder.build()
|
|
3356
|
+
});
|
|
3357
|
+
legs.push(leg);
|
|
3358
|
+
}
|
|
3359
|
+
const itinerary = new Itinerary({
|
|
3360
|
+
duration: route.duration,
|
|
3361
|
+
startTime: new Date(route.estimatedDatetimeOfDeparture).getTime(),
|
|
3362
|
+
endTime: new Date(route.estimatedDatetimeOfArrival).getTime(),
|
|
3363
|
+
origin: waypointToCoordinates(route.waypoints[0]),
|
|
3364
|
+
destination: waypointToCoordinates(last$1(route.waypoints)),
|
|
3365
|
+
legs
|
|
3366
|
+
});
|
|
3367
|
+
itineraries.push(itinerary);
|
|
3368
|
+
}
|
|
3369
|
+
return itineraries;
|
|
3370
|
+
}
|
|
3371
|
+
}
|
|
3372
|
+
const GeoveloRemoteRouter$1 = new GeoveloRemoteRouter();
|
|
3230
3373
|
const transitModeCorrespondance = /* @__PURE__ */ new Map();
|
|
3231
3374
|
transitModeCorrespondance.set("Air", "AIRPLANE");
|
|
3232
3375
|
transitModeCorrespondance.set("Boat", "BOAT");
|
|
@@ -3300,6 +3443,10 @@ class IdfmRemoteRouter extends RemoteRouter {
|
|
|
3300
3443
|
return "idfm";
|
|
3301
3444
|
}
|
|
3302
3445
|
async getItineraries(endpointUrl, routerRequest) {
|
|
3446
|
+
const { travelMode } = routerRequest;
|
|
3447
|
+
if (travelMode === "BIKE") {
|
|
3448
|
+
return GeoveloRemoteRouter$1.getItineraries("https://idfm.getwemap.com/marketplace/computedroutes", routerRequest);
|
|
3449
|
+
}
|
|
3303
3450
|
const url = this.getURL(endpointUrl, routerRequest);
|
|
3304
3451
|
const res = await fetch(url, {
|
|
3305
3452
|
method: "GET",
|
|
@@ -3825,7 +3972,7 @@ class OtpRemoteRouter extends RemoteRouter {
|
|
|
3825
3972
|
for (const jsonLeg of jsonItinerary.legs) {
|
|
3826
3973
|
const startCoordinates = jsonToCoordinates(jsonLeg.from);
|
|
3827
3974
|
const endCoordinates = jsonToCoordinates(jsonLeg.to);
|
|
3828
|
-
const legCoords =
|
|
3975
|
+
const legCoords = polyline.decode(jsonLeg.legGeometry.points).map(([lat, lon]) => new geo.Coordinates(lat, lon));
|
|
3829
3976
|
let transportInfo;
|
|
3830
3977
|
const stepsBuilder = new StepsBuilder().setStart(startCoordinates).setEnd(endCoordinates).setPathCoords(legCoords);
|
|
3831
3978
|
if (isLegPT(jsonLeg)) {
|
|
@@ -4571,6 +4718,7 @@ exports.CustomGraphMap = CustomGraphMap;
|
|
|
4571
4718
|
exports.CustomGraphMapTester = CustomGraphMapTester;
|
|
4572
4719
|
exports.DeutscheBahnRemoteRouter = DeutscheBahnRemoteRouter$1;
|
|
4573
4720
|
exports.Edge = Edge;
|
|
4721
|
+
exports.GeoveloRemoteRouter = GeoveloRemoteRouter$1;
|
|
4574
4722
|
exports.Graph = Graph;
|
|
4575
4723
|
exports.GraphProjection = GraphProjection;
|
|
4576
4724
|
exports.GraphRoute = GraphRoute;
|