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