Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
SiarheiFedartsou committed Oct 17, 2022
1 parent 8395629 commit 7f5acf6
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 47 deletions.
1 change: 1 addition & 0 deletions features/step_definitions/distance_matrix.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ function tableParse(table, noRoute, annotation, format, callback) {
}
} else { //flatbuffers
var body = response.body;
console.log(body)
var bytes = new Uint8Array(body.length);
for (var indx = 0; indx < body.length; ++indx) {
bytes[indx] = body.charCodeAt(indx);
Expand Down
2 changes: 1 addition & 1 deletion features/support/shared_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ module.exports = function () {
if (whitelist.indexOf(a_type) == -1)
return cb(new Error('Unrecognized annotation field', a_type));
if (annotation && !annotation[a_type])
return cb(new Error('Annotation not found in response', a_type));
return cb(new Error('Annotation not found in response ' + a_type));
got[k] = annotation && annotation[a_type] || '';
} else if (k.match(/^am:/)) {
let a_type = k.slice(3);
Expand Down
1 change: 1 addition & 0 deletions include/nodejs/node_osrm_support.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
if (annotations->IsBoolean())
{
params->annotations = Nan::To<bool>(annotations).FromJust();
params->annotations_type = params->annotations ? osrm::RouteParameters::AnnotationsType::All : osrm::RouteParameters::AnnotationsType::None;
}
else if (annotations->IsArray())
{
Expand Down
97 changes: 79 additions & 18 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,26 @@ async function handleTable(osrm, coordinates, query) {
const options = {
coordinates: coordinates
};
handleCommonParams(query, options);
if (query.scale_factor) {
options.scale_factor = parseFloat(query.scale_factor);
}
if (query.fallback_coordinate) {
options.fallback_coordinate = query.fallback_coordinate;
}
if (query.fallback_speed) {
options.fallback_speed = parseFloat(query.fallback_speed);
}
if (query.sources) {
options.sources = query.sources.split(';').map((t) => parseInt(t));
}
if (query.destinations) {
options.destinations = query.destinations.split(';').map((t) => parseInt(t));
}
const res = await table(osrm, options);
return res;
}
async function handleMatch(osrm, coordinates, query) {
const options = {
coordinates: coordinates,
};
function handleCommonParams(query, options) {
if (query.overview) {
options.overview = query.overview;
}
Expand All @@ -103,18 +116,9 @@ async function handleMatch(osrm, coordinates, query) {
if (query.waypoints) {
options.waypoints = query.waypoints.split(';').map((t) => parseInt(t));
}
if (query.tidy) {
options.tidy = query.tidy == 'true' ? true : false;
}
if (query.gaps) {
options.gaps = query.gaps;
}
if (query.steps) {
options.steps = query.steps === 'true' ? true : false;
}
if (query.generate_hints) {
options.generate_hints = query.generate_hints == 'true' ? true : false;
}
if (query.annotations) {
let annotations;
if (query.annotations === 'true') {
Expand All @@ -125,24 +129,81 @@ async function handleMatch(osrm, coordinates, query) {
}
options.annotations = annotations;
}
if (query.exclude) {
options.exclude = query.exclude.split(',');
}
if (query.snapping) {
options.snapping = query.snapping;
}
if (query.radiuses) {
options.radiuses = query.radiuses.split(';').map((t) => {
if (t === 'unlimited') {
return null;
}
return parseFloat(t);
});
}
if (query.bearings) {
options.bearings = query.bearings.split(';').map((bearingWithRange) => {
if (bearingWithRange === '') {
return null;
}
return bearingWithRange.split(',').map((t) => parseFloat(t));
});
}
if (query.hints) {
options.hints = query.hints.split(';');
}
if (query.generate_hints) {
options.generate_hints = query.generate_hints == 'true' ? true : false;
}
if (query.skip_waypoints) {
options.skip_waypoints = query.skip_waypoints === 'true' ? true : false;
}
}
async function handleMatch(osrm, coordinates, query) {
const options = {
coordinates: coordinates,
};
handleCommonParams(query, options);
if (query.gaps) {
options.gaps = query.gaps;
}
if (query.tidy) {
options.tidy = query.tidy === 'true' ? true : false;
}
//throw new Error(`not implemented ${JSON.stringify(options)}`);
const res = await match(osrm, options);
return res;
}
async function handleTrip(osrm, coordinates, query) {
const options = {
coordinates: coordinates,
steps: query.steps === 'true' ? true : false,
coordinates: coordinates
};
handleCommonParams(query, options);
if (query.roundtrip) {
options.roundtrip = query.roundtrip === 'true' ? true : false;
}
if (query.source) {
options.source = query.source;
}
if (query.destination) {
options.destination = query.destination;
}
const res = await trip(osrm, options);
return res;
}
async function handleRoute(osrm, coordinates, query) {
const options = {
coordinates: coordinates,
steps: query.steps === 'true' ? true : false,
alternatives: query.alternatives === 'true' ? true : false,
coordinates: coordinates
};
handleCommonParams(query, options);
if (query.alternatives) {
options.alternatives = query.alternatives === 'true' ? true : false;
}
if (query.approaches) {
options.approaches = query.approaches.split(';');
}
const res = await route(osrm, options);
return res;
}
Expand Down
130 changes: 102 additions & 28 deletions server/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env node
import Fastify from 'fastify'
import { option } from 'yargs';
import yargs from 'yargs/yargs';

const OSRM = require('../lib/index.js')
Expand Down Expand Up @@ -80,21 +81,30 @@ async function handleNearest(osrm: any, coordinates: [number, number][], query:


async function handleTable(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
const options = {
const options: any = {
coordinates: coordinates
};
handleCommonParams(query, options);
if (query.scale_factor) {
options.scale_factor = parseFloat(query.scale_factor);
}
if (query.fallback_coordinate) {
options.fallback_coordinate = query.fallback_coordinate;
}
if (query.fallback_speed) {
options.fallback_speed = parseFloat(query.fallback_speed);
}
if (query.sources) {
options.sources = query.sources.split(';').map((t: string) => parseInt(t));
}
if (query.destinations) {
options.destinations = query.destinations.split(';').map((t: string) => parseInt(t));
}
const res = await table(osrm, options);
return res;
}

async function handleMatch(osrm: any, coordinates: [number, number][], query: any): Promise<any> {


const options: any = {
coordinates: coordinates,

};

function handleCommonParams(query: any, options: any) {
if (query.overview) {
options.overview = query.overview;
}
Expand All @@ -111,22 +121,11 @@ async function handleMatch(osrm: any, coordinates: [number, number][], query: an
options.waypoints = query.waypoints.split(';').map((t: string) => parseInt(t));
}

if (query.tidy) {
options.tidy = query.tidy == 'true' ? true : false;
}

if (query.gaps) {
options.gaps = query.gaps;
}

if (query.steps) {
options.steps = query.steps === 'true' ? true : false;
}

if (query.generate_hints) {
options.generate_hints = query.generate_hints == 'true' ? true : false;
}


if (query.annotations) {
let annotations;
if (query.annotations === 'true') {
Expand All @@ -136,26 +135,100 @@ async function handleMatch(osrm: any, coordinates: [number, number][], query: an
}
options.annotations = annotations;
}

if (query.exclude) {
options.exclude = query.exclude.split(',');
}

if (query.snapping) {
options.snapping = query.snapping;
}

if (query.radiuses) {
options.radiuses = query.radiuses.split(';').map((t: string) => {
if (t === 'unlimited') {
return null;
}
return parseFloat(t);
});
}

if (query.bearings) {
options.bearings = query.bearings.split(';').map((bearingWithRange: string) => {
if (bearingWithRange === '') {
return null;
}
return bearingWithRange.split(',').map((t: string) => parseFloat(t));
});
}

if (query.hints) {
options.hints = query.hints.split(';');
}

if (query.generate_hints) {
options.generate_hints = query.generate_hints == 'true' ? true : false;
}

if (query.skip_waypoints) {
options.skip_waypoints = query.skip_waypoints === 'true' ? true : false;
}
}

async function handleMatch(osrm: any, coordinates: [number, number][], query: any): Promise<any> {


const options: any = {
coordinates: coordinates,

};

handleCommonParams(query, options);
if (query.gaps) {
options.gaps = query.gaps;
}

if (query.tidy) {
options.tidy = query.tidy === 'true' ? true : false;
}




//throw new Error(`not implemented ${JSON.stringify(options)}`);
const res = await match(osrm, options);
return res;
}

async function handleTrip(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
const options = {
coordinates: coordinates,
steps: query.steps === 'true' ? true : false,
const options: any = {
coordinates: coordinates
};
handleCommonParams(query, options);
if (query.roundtrip) {
options.roundtrip = query.roundtrip === 'true' ? true : false;
}
if (query.source) {
options.source = query.source;
}
if (query.destination) {
options.destination = query.destination;
}
const res = await trip(osrm, options);
return res;
}

async function handleRoute(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
const options = {
coordinates: coordinates,
steps: query.steps === 'true' ? true : false,
alternatives: query.alternatives === 'true' ? true : false,
const options: any = {
coordinates: coordinates
};
handleCommonParams(query, options);
if (query.alternatives) {
options.alternatives = query.alternatives === 'true' ? true : false;
}
if (query.approaches) {
options.approaches = query.approaches.split(';');
}
const res = await route(osrm, options);
return res;
}
Expand Down Expand Up @@ -196,6 +269,7 @@ async function main() {
// TODO: validation
fastify.get('/:service(route|nearest|table|match|trip|tile)/v1/:profile/:coordinates', async (request, reply) => {
const { service, profile, coordinates } = request.params as any;

const query = request.query as any;
const parsedCoordinates = coordinates.split(';').map((c: string) => c.split(',').map((n: string) => parseFloat(n)));
const handlers: Map<string, Function> = new Map();
Expand Down

0 comments on commit 7f5acf6

Please sign in to comment.