Skip to content

Commit 7f5acf6

Browse files
wip
1 parent 8395629 commit 7f5acf6

File tree

5 files changed

+184
-47
lines changed

5 files changed

+184
-47
lines changed

features/step_definitions/distance_matrix.js

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ function tableParse(table, noRoute, annotation, format, callback) {
9898
}
9999
} else { //flatbuffers
100100
var body = response.body;
101+
console.log(body)
101102
var bytes = new Uint8Array(body.length);
102103
for (var indx = 0; indx < body.length; ++indx) {
103104
bytes[indx] = body.charCodeAt(indx);

features/support/shared_steps.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ module.exports = function () {
178178
if (whitelist.indexOf(a_type) == -1)
179179
return cb(new Error('Unrecognized annotation field', a_type));
180180
if (annotation && !annotation[a_type])
181-
return cb(new Error('Annotation not found in response', a_type));
181+
return cb(new Error('Annotation not found in response ' + a_type));
182182
got[k] = annotation && annotation[a_type] || '';
183183
} else if (k.match(/^am:/)) {
184184
let a_type = k.slice(3);

include/nodejs/node_osrm_support.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ inline bool parseCommonParameters(const v8::Local<v8::Object> &obj, ParamType &p
799799
if (annotations->IsBoolean())
800800
{
801801
params->annotations = Nan::To<bool>(annotations).FromJust();
802+
params->annotations_type = params->annotations ? osrm::RouteParameters::AnnotationsType::All : osrm::RouteParameters::AnnotationsType::None;
802803
}
803804
else if (annotations->IsArray())
804805
{

server/server.js

+79-18
Original file line numberDiff line numberDiff line change
@@ -84,13 +84,26 @@ async function handleTable(osrm, coordinates, query) {
8484
const options = {
8585
coordinates: coordinates
8686
};
87+
handleCommonParams(query, options);
88+
if (query.scale_factor) {
89+
options.scale_factor = parseFloat(query.scale_factor);
90+
}
91+
if (query.fallback_coordinate) {
92+
options.fallback_coordinate = query.fallback_coordinate;
93+
}
94+
if (query.fallback_speed) {
95+
options.fallback_speed = parseFloat(query.fallback_speed);
96+
}
97+
if (query.sources) {
98+
options.sources = query.sources.split(';').map((t) => parseInt(t));
99+
}
100+
if (query.destinations) {
101+
options.destinations = query.destinations.split(';').map((t) => parseInt(t));
102+
}
87103
const res = await table(osrm, options);
88104
return res;
89105
}
90-
async function handleMatch(osrm, coordinates, query) {
91-
const options = {
92-
coordinates: coordinates,
93-
};
106+
function handleCommonParams(query, options) {
94107
if (query.overview) {
95108
options.overview = query.overview;
96109
}
@@ -103,18 +116,9 @@ async function handleMatch(osrm, coordinates, query) {
103116
if (query.waypoints) {
104117
options.waypoints = query.waypoints.split(';').map((t) => parseInt(t));
105118
}
106-
if (query.tidy) {
107-
options.tidy = query.tidy == 'true' ? true : false;
108-
}
109-
if (query.gaps) {
110-
options.gaps = query.gaps;
111-
}
112119
if (query.steps) {
113120
options.steps = query.steps === 'true' ? true : false;
114121
}
115-
if (query.generate_hints) {
116-
options.generate_hints = query.generate_hints == 'true' ? true : false;
117-
}
118122
if (query.annotations) {
119123
let annotations;
120124
if (query.annotations === 'true') {
@@ -125,24 +129,81 @@ async function handleMatch(osrm, coordinates, query) {
125129
}
126130
options.annotations = annotations;
127131
}
132+
if (query.exclude) {
133+
options.exclude = query.exclude.split(',');
134+
}
135+
if (query.snapping) {
136+
options.snapping = query.snapping;
137+
}
138+
if (query.radiuses) {
139+
options.radiuses = query.radiuses.split(';').map((t) => {
140+
if (t === 'unlimited') {
141+
return null;
142+
}
143+
return parseFloat(t);
144+
});
145+
}
146+
if (query.bearings) {
147+
options.bearings = query.bearings.split(';').map((bearingWithRange) => {
148+
if (bearingWithRange === '') {
149+
return null;
150+
}
151+
return bearingWithRange.split(',').map((t) => parseFloat(t));
152+
});
153+
}
154+
if (query.hints) {
155+
options.hints = query.hints.split(';');
156+
}
157+
if (query.generate_hints) {
158+
options.generate_hints = query.generate_hints == 'true' ? true : false;
159+
}
160+
if (query.skip_waypoints) {
161+
options.skip_waypoints = query.skip_waypoints === 'true' ? true : false;
162+
}
163+
}
164+
async function handleMatch(osrm, coordinates, query) {
165+
const options = {
166+
coordinates: coordinates,
167+
};
168+
handleCommonParams(query, options);
169+
if (query.gaps) {
170+
options.gaps = query.gaps;
171+
}
172+
if (query.tidy) {
173+
options.tidy = query.tidy === 'true' ? true : false;
174+
}
128175
//throw new Error(`not implemented ${JSON.stringify(options)}`);
129176
const res = await match(osrm, options);
130177
return res;
131178
}
132179
async function handleTrip(osrm, coordinates, query) {
133180
const options = {
134-
coordinates: coordinates,
135-
steps: query.steps === 'true' ? true : false,
181+
coordinates: coordinates
136182
};
183+
handleCommonParams(query, options);
184+
if (query.roundtrip) {
185+
options.roundtrip = query.roundtrip === 'true' ? true : false;
186+
}
187+
if (query.source) {
188+
options.source = query.source;
189+
}
190+
if (query.destination) {
191+
options.destination = query.destination;
192+
}
137193
const res = await trip(osrm, options);
138194
return res;
139195
}
140196
async function handleRoute(osrm, coordinates, query) {
141197
const options = {
142-
coordinates: coordinates,
143-
steps: query.steps === 'true' ? true : false,
144-
alternatives: query.alternatives === 'true' ? true : false,
198+
coordinates: coordinates
145199
};
200+
handleCommonParams(query, options);
201+
if (query.alternatives) {
202+
options.alternatives = query.alternatives === 'true' ? true : false;
203+
}
204+
if (query.approaches) {
205+
options.approaches = query.approaches.split(';');
206+
}
146207
const res = await route(osrm, options);
147208
return res;
148209
}

server/server.ts

+102-28
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#!/usr/bin/env node
22
import Fastify from 'fastify'
3+
import { option } from 'yargs';
34
import yargs from 'yargs/yargs';
45

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

8182

8283
async function handleTable(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
83-
const options = {
84+
const options: any = {
8485
coordinates: coordinates
8586
};
87+
handleCommonParams(query, options);
88+
if (query.scale_factor) {
89+
options.scale_factor = parseFloat(query.scale_factor);
90+
}
91+
if (query.fallback_coordinate) {
92+
options.fallback_coordinate = query.fallback_coordinate;
93+
}
94+
if (query.fallback_speed) {
95+
options.fallback_speed = parseFloat(query.fallback_speed);
96+
}
97+
if (query.sources) {
98+
options.sources = query.sources.split(';').map((t: string) => parseInt(t));
99+
}
100+
if (query.destinations) {
101+
options.destinations = query.destinations.split(';').map((t: string) => parseInt(t));
102+
}
86103
const res = await table(osrm, options);
87104
return res;
88105
}
89106

90-
async function handleMatch(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
91-
92-
93-
const options: any = {
94-
coordinates: coordinates,
95-
96-
};
97-
107+
function handleCommonParams(query: any, options: any) {
98108
if (query.overview) {
99109
options.overview = query.overview;
100110
}
@@ -111,22 +121,11 @@ async function handleMatch(osrm: any, coordinates: [number, number][], query: an
111121
options.waypoints = query.waypoints.split(';').map((t: string) => parseInt(t));
112122
}
113123

114-
if (query.tidy) {
115-
options.tidy = query.tidy == 'true' ? true : false;
116-
}
117-
118-
if (query.gaps) {
119-
options.gaps = query.gaps;
120-
}
121-
122124
if (query.steps) {
123125
options.steps = query.steps === 'true' ? true : false;
124126
}
125127

126-
if (query.generate_hints) {
127-
options.generate_hints = query.generate_hints == 'true' ? true : false;
128-
}
129-
128+
130129
if (query.annotations) {
131130
let annotations;
132131
if (query.annotations === 'true') {
@@ -136,26 +135,100 @@ async function handleMatch(osrm: any, coordinates: [number, number][], query: an
136135
}
137136
options.annotations = annotations;
138137
}
138+
139+
if (query.exclude) {
140+
options.exclude = query.exclude.split(',');
141+
}
142+
143+
if (query.snapping) {
144+
options.snapping = query.snapping;
145+
}
146+
147+
if (query.radiuses) {
148+
options.radiuses = query.radiuses.split(';').map((t: string) => {
149+
if (t === 'unlimited') {
150+
return null;
151+
}
152+
return parseFloat(t);
153+
});
154+
}
155+
156+
if (query.bearings) {
157+
options.bearings = query.bearings.split(';').map((bearingWithRange: string) => {
158+
if (bearingWithRange === '') {
159+
return null;
160+
}
161+
return bearingWithRange.split(',').map((t: string) => parseFloat(t));
162+
});
163+
}
164+
165+
if (query.hints) {
166+
options.hints = query.hints.split(';');
167+
}
168+
169+
if (query.generate_hints) {
170+
options.generate_hints = query.generate_hints == 'true' ? true : false;
171+
}
172+
173+
if (query.skip_waypoints) {
174+
options.skip_waypoints = query.skip_waypoints === 'true' ? true : false;
175+
}
176+
}
177+
178+
async function handleMatch(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
179+
180+
181+
const options: any = {
182+
coordinates: coordinates,
183+
184+
};
185+
186+
handleCommonParams(query, options);
187+
if (query.gaps) {
188+
options.gaps = query.gaps;
189+
}
190+
191+
if (query.tidy) {
192+
options.tidy = query.tidy === 'true' ? true : false;
193+
}
194+
195+
196+
197+
139198
//throw new Error(`not implemented ${JSON.stringify(options)}`);
140199
const res = await match(osrm, options);
141200
return res;
142201
}
143202

144203
async function handleTrip(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
145-
const options = {
146-
coordinates: coordinates,
147-
steps: query.steps === 'true' ? true : false,
204+
const options: any = {
205+
coordinates: coordinates
148206
};
207+
handleCommonParams(query, options);
208+
if (query.roundtrip) {
209+
options.roundtrip = query.roundtrip === 'true' ? true : false;
210+
}
211+
if (query.source) {
212+
options.source = query.source;
213+
}
214+
if (query.destination) {
215+
options.destination = query.destination;
216+
}
149217
const res = await trip(osrm, options);
150218
return res;
151219
}
152220

153221
async function handleRoute(osrm: any, coordinates: [number, number][], query: any): Promise<any> {
154-
const options = {
155-
coordinates: coordinates,
156-
steps: query.steps === 'true' ? true : false,
157-
alternatives: query.alternatives === 'true' ? true : false,
222+
const options: any = {
223+
coordinates: coordinates
158224
};
225+
handleCommonParams(query, options);
226+
if (query.alternatives) {
227+
options.alternatives = query.alternatives === 'true' ? true : false;
228+
}
229+
if (query.approaches) {
230+
options.approaches = query.approaches.split(';');
231+
}
159232
const res = await route(osrm, options);
160233
return res;
161234
}
@@ -196,6 +269,7 @@ async function main() {
196269
// TODO: validation
197270
fastify.get('/:service(route|nearest|table|match|trip|tile)/v1/:profile/:coordinates', async (request, reply) => {
198271
const { service, profile, coordinates } = request.params as any;
272+
199273
const query = request.query as any;
200274
const parsedCoordinates = coordinates.split(';').map((c: string) => c.split(',').map((n: string) => parseFloat(n)));
201275
const handlers: Map<string, Function> = new Map();

0 commit comments

Comments
 (0)