From b1099059f518b263c8abc96e805ea800774f496e Mon Sep 17 00:00:00 2001 From: Alistair Woodcock Date: Tue, 22 Sep 2020 06:52:30 +1000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Merge=20PR=20#47389=20@types/osr?= =?UTF-8?q?m:=20Expose=20annotations=20and=20distances=20matrix=20by=20@al?= =?UTF-8?q?istairwoodcock?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Annotations to specify what matrices are returned is available in OSRM but was not exposed via the types * Updated supported version number * Removed patch version to match CI requirement MAJOR.MINOR --- types/osrm/index.d.ts | 8 +++++++- types/osrm/osrm-tests.ts | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/types/osrm/index.d.ts b/types/osrm/index.d.ts index 2bf324bd96..43c5f6b158 100644 --- a/types/osrm/index.d.ts +++ b/types/osrm/index.d.ts @@ -1,4 +1,4 @@ -// Type definitions for osrm 5.12 +// Type definitions for osrm 5.22 // Project: https://github.com/Project-OSRM/osrm-backend // Definitions by: Denis Carriere // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped @@ -50,6 +50,7 @@ declare namespace OSRM { type Radius = number; type Hint = string; type Duration = number; + type Distance = number; type Tile = [number, number, number]; type StepManeuverTypes = 'turn' | 'new name' | 'depart' | 'arrive' | 'merge' | 'ramp' | 'on ramp' | 'off ramp' | 'fork' | 'end of road' | @@ -466,6 +467,10 @@ declare namespace OSRM { * to use location with given index as destination. Default is to use all. */ destinations?: number[]; + /** + * specify which table results to return. + */ + annotations?: Array<('duration' | 'distance')>; } /** @@ -570,6 +575,7 @@ declare namespace OSRM { interface TableResults { durations: Duration[][]; + distances?: Distance[][]; sources: Waypoint[]; destinations: Waypoint[]; } diff --git a/types/osrm/osrm-tests.ts b/types/osrm/osrm-tests.ts index 513e8c1fd2..e13fd00f34 100644 --- a/types/osrm/osrm-tests.ts +++ b/types/osrm/osrm-tests.ts @@ -35,6 +35,21 @@ osrm.table({coordinates}, (err, response) => { console.log(response.destinations); // array of Waypoint objects }); +// Table Distances +osrm.table({coordinates, annotations: ['distance']}, (err, response) => { + console.log(response.distances); // array of arrays, matrix in row-major order + console.log(response.sources); // array of Waypoint objects + console.log(response.destinations); // array of Waypoint objects +}); + +// Table Durations and Distances +osrm.table({coordinates, annotations: ['distance', 'duration']}, (err, response) => { + console.log(response.durations); // array of arrays, matrix in row-major order + console.log(response.distances); // array of arrays, matrix in row-major order + console.log(response.sources); // array of Waypoint objects + console.log(response.destinations); // array of Waypoint objects +}); + // Tile osrm.tile([0, 0, 0], (err, response) => { if (err) throw err;