@iwpnd/valhalla-ts
Version:
A nodejs client and helper utilities for valhalla routing engine
121 lines • 3.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Valhalla = void 0;
const rip_ts_1 = require("@iwpnd/rip-ts");
class Valhalla extends rip_ts_1.RestClient {
constructor(url, options) {
const uri = url ?? process.env.VALHALLA_URL;
if (!uri) {
throw Error('valhalla url is required');
}
super(uri, {
...options,
headers: {
Accept: 'application/json',
...options?.headers,
},
});
}
/**
*
* Get a turn by turn route
*
* @public
* @remarks
* Returns a turn by turn route based on
* the input {@link TurnByTurnRouteRequest}
*
* @param query - {@link TurnByTurnRouteRequest}
*
* @returns {@link Trip}
*/
async route(query) {
const options = {
method: 'POST',
body: query,
};
const { trip } = await this.request('/route', options);
return trip;
}
/**
*
* Get an optimized route
*
* @public
* @remarks
* Get an optimized route, a route between two or more locations,
* based on the input {@link OptimizedRouteRequest}.
*
* @param query - {@link OptimizedRouteRequest}
*
* @returns {@link TripResponse}
*/
async optimizedRoute(query) {
const options = {
method: 'POST',
body: query,
};
return this.request('/optimized_route', options);
}
/**
*
* Get one or more Isochrone(s) around an input location.
*
* @public
* @remarks
* Get one or more Isochrones based on the input {@link IsochroneRouteRequest}.
*
* @param query - {@link IsochroneRouteRequest}
*
* @returns {@link IsochroneResponse}
*/
async isochrone(query) {
const options = {
method: 'POST',
body: query,
};
return this.request('/isochrone', options);
}
/**
*
* Mapmatch an input route to the road network
*
* @public
* @remarks
* Match an input route to the road network,
* based on the input {@link MapMatchingShapeRequest} | {@MapMatchingPolylineRequest}.
*
* @param query - {@link MapMatchingShapeRequest} | {@link MapMatchingPolylineRequest}
*
* @returns {@link MapMatchingTraceRouteResponse}
*/
async traceRoute(query) {
const options = {
method: 'POST',
body: query,
};
return this.request('/trace_route', options);
}
/**
*
* Get the valhalla server status
*
* @public
* @remarks
* Get the valhalla service status,
* If service_limits.status.allow_verbose is set to true, will also
* return addtional information if verbose is set to true.
*
* @param verbose (boolean): default false
*
* @returns {@link StatusResponse} | {@link ExtendedStatusResponse}
*/
async status(verbose = false) {
return this.request('/status', {
method: 'GET',
...(verbose && { query: { verbose: JSON.stringify(verbose) } }),
});
}
}
exports.Valhalla = Valhalla;
//# sourceMappingURL=valhalla.js.map