Skip to content

Commit

Permalink
🤖 Merge PR DefinitelyTyped#47389 @types/osrm: Expose annotations and …
Browse files Browse the repository at this point in the history
…distances matrix by @alistairwoodcock

* 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
  • Loading branch information
alistairwoodcock committed Sep 21, 2020
1 parent fc8039e commit b109905
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion 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 <https://github.com/DenisCarriere>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
Expand Down Expand Up @@ -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' |
Expand Down Expand Up @@ -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')>;
}

/**
Expand Down Expand Up @@ -570,6 +575,7 @@ declare namespace OSRM {

interface TableResults {
durations: Duration[][];
distances?: Distance[][];
sources: Waypoint[];
destinations: Waypoint[];
}
Expand Down
15 changes: 15 additions & 0 deletions types/osrm/osrm-tests.ts
Expand Up @@ -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;
Expand Down

0 comments on commit b109905

Please sign in to comment.