Skip to content

Commit 23cea73

Browse files
wip
1 parent 955c842 commit 23cea73

9 files changed

+174
-174
lines changed

server/MatchServiceHandler.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
import {ServiceHandler} from "./ServiceHandler";
1+
import { ServiceHandler } from "./ServiceHandler";
22

33
export class MatchServiceHandler extends ServiceHandler {
44
protected buildServiceOptions(options: any, query: any): any {
5-
6-
if (query.timestamps) {
7-
options.timestamps = query.timestamps;
8-
}
9-
10-
if (query.waypoints) {
11-
options.waypoints = query.waypoints;
12-
}
13-
14-
if (query.gaps) {
15-
options.gaps = query.gaps;
16-
}
17-
18-
if (query.tidy) {
19-
options.tidy = query.tidy;
20-
}
21-
return options;
5+
6+
if (query.timestamps) {
7+
options.timestamps = query.timestamps;
8+
}
9+
10+
if (query.waypoints) {
11+
options.waypoints = query.waypoints;
12+
}
13+
14+
if (query.gaps) {
15+
options.gaps = query.gaps;
16+
}
17+
18+
if (query.tidy) {
19+
options.tidy = query.tidy;
20+
}
21+
return options;
2222
}
23-
23+
2424
protected async callOSRM(options: any): Promise<any> {
25-
return this.osrm.match(options);
25+
return this.osrm.match(options);
2626
}
27-
}
27+
}

server/NearestServiceHandler.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import {ServiceHandler} from "./ServiceHandler";
1+
import { ServiceHandler } from "./ServiceHandler";
22

33
export class NearestServiceHandler extends ServiceHandler {
44
protected buildServiceOptions(options: any, query: any): any {
5-
if (query.number !== undefined) {
6-
options.number = query.number;
7-
}
8-
return options;
5+
if (query.number !== undefined) {
6+
options.number = query.number;
7+
}
8+
return options;
99
}
10-
10+
1111
protected async callOSRM(options: any): Promise<any> {
12-
return this.osrm.nearest(options);
12+
return this.osrm.nearest(options);
1313
}
14-
}
14+
}

server/OSRMWrapper.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,28 @@ export class OSRMWrapper {
77
constructor(osrmOptions: any) {
88
this.osrm = new OSRM(osrmOptions);
99
}
10-
10+
1111
async tile(zxy: [number, number, number]): Promise<any> {
12-
return util.promisify(this.osrm.tile.bind(this.osrm))(zxy);
12+
return util.promisify(this.osrm.tile.bind(this.osrm))(zxy);
1313
}
14-
14+
1515
async route(options: any): Promise<any> {
16-
return util.promisify(this.osrm.route.bind(this.osrm))(options);
16+
return util.promisify(this.osrm.route.bind(this.osrm))(options);
1717
}
18-
18+
1919
async nearest(options: any): Promise<any> {
20-
return util.promisify(this.osrm.nearest.bind(this.osrm))(options);
20+
return util.promisify(this.osrm.nearest.bind(this.osrm))(options);
2121
}
22-
22+
2323
async table(options: any): Promise<any> {
24-
return util.promisify(this.osrm.table.bind(this.osrm))(options);
24+
return util.promisify(this.osrm.table.bind(this.osrm))(options);
2525
}
26-
26+
2727
async trip(options: any): Promise<any> {
28-
return util.promisify(this.osrm.trip.bind(this.osrm))(options);
28+
return util.promisify(this.osrm.trip.bind(this.osrm))(options);
2929
}
30-
30+
3131
async match(options: any): Promise<any> {
32-
return util.promisify(this.osrm.match.bind(this.osrm))(options);
32+
return util.promisify(this.osrm.match.bind(this.osrm))(options);
3333
}
34-
}
34+
}

server/RouteServiceHandler.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11

2-
import {ServiceHandler} from "./ServiceHandler";
2+
import { ServiceHandler } from "./ServiceHandler";
33

44
export class RouteServiceHandler extends ServiceHandler {
55
protected buildServiceOptions(options: any, query: any): any {
6-
7-
if (query.alternatives) {
8-
options.alternatives = query.alternatives;
9-
}
10-
if (query.approaches) {
11-
options.approaches = query.approaches;
12-
}
13-
14-
if (query.waypoints) {
15-
options.waypoints = query.waypoints;
16-
}
17-
return options;
6+
7+
if (query.alternatives) {
8+
options.alternatives = query.alternatives;
9+
}
10+
if (query.approaches) {
11+
options.approaches = query.approaches;
12+
}
13+
14+
if (query.waypoints) {
15+
options.waypoints = query.waypoints;
16+
}
17+
return options;
1818
}
19-
20-
19+
20+
2121
protected async callOSRM(options: any): Promise<any> {
22-
return this.osrm.route(options);
22+
return this.osrm.route(options);
2323
}
24-
}
24+
}

server/ServiceHandler.ts

Lines changed: 50 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,89 @@
11

2-
import {Format} from "./Format";
3-
import {OSRMWrapper} from "./OSRMWrapper";
2+
import { Format } from "./Format";
3+
import { OSRMWrapper } from "./OSRMWrapper";
44

55

6-
7-
export abstract class ServiceHandler {
8-
public constructor(protected readonly osrm: OSRMWrapper) {}
6+
7+
export abstract class ServiceHandler {
8+
public constructor(protected readonly osrm: OSRMWrapper) { }
99
public async handle(coordinates: [number, number][], query: any, format: Format): Promise<any> {
10-
const options = this.build(coordinates, query, format);
11-
return this.callOSRM(options);
10+
const options = this.build(coordinates, query, format);
11+
return this.callOSRM(options);
1212
}
13-
14-
15-
13+
14+
15+
1616
private build(coordinates: [number, number][], query: any, format: Format): any {
17-
const options = this.buildBaseOptions(coordinates, query, format);
18-
return this.buildServiceOptions(options, query);
17+
const options = this.buildBaseOptions(coordinates, query, format);
18+
return this.buildServiceOptions(options, query);
1919
}
20-
20+
2121
protected abstract buildServiceOptions(options: any, query: any): any;
2222
protected abstract callOSRM(options: any): Promise<any>;
23-
23+
2424
private buildBaseOptions(coordinates: [number, number][], query: any, format: Format): any {
25-
const options: any = {
26-
coordinates: coordinates
27-
};
28-
this.handleCommonParams(query, options, format);
29-
return options;
25+
const options: any = {
26+
coordinates: coordinates
27+
};
28+
this.handleCommonParams(query, options, format);
29+
return options;
3030
}
3131

3232
private handleCommonParams(query: any, options: any, format: Format) {
3333
options.format = format;
34-
34+
3535
if (query.overview) {
36-
options.overview = query.overview;
36+
options.overview = query.overview;
3737
}
38-
38+
3939
if (query.geometries) {
40-
options.geometries = query.geometries;
40+
options.geometries = query.geometries;
4141
}
42-
42+
4343
if (query.steps) {
44-
options.steps = query.steps;
44+
options.steps = query.steps;
4545
}
46-
46+
4747
// TODO: annotations is per-service option
4848
if (query.annotations) {
49-
options.annotations = query.annotations;
49+
options.annotations = query.annotations;
5050
}
51-
51+
5252
if (query.exclude) {
53-
options.exclude = query.exclude;
53+
options.exclude = query.exclude;
5454
}
55-
55+
5656
if (query.snapping) {
57-
options.snapping = query.snapping;
57+
options.snapping = query.snapping;
5858
}
59-
59+
6060
if (query.radiuses) {
61-
options.radiuses = query.radiuses.map((r: string | 'unlimited') => {
62-
if (r === 'unlimited') {
63-
return null;
64-
}
65-
return r;
66-
});
61+
options.radiuses = query.radiuses.map((r: string | 'unlimited') => {
62+
if (r === 'unlimited') {
63+
return null;
64+
}
65+
return r;
66+
});
6767
}
68-
68+
6969
if (query.bearings) {
70-
options.bearings = query.bearings;
70+
options.bearings = query.bearings;
7171
}
72-
72+
7373
if (query.hints) {
74-
options.hints = query.hints;
74+
options.hints = query.hints;
7575
}
76-
76+
7777
if (query.generate_hints) {
78-
options.generate_hints = query.generate_hints;
78+
options.generate_hints = query.generate_hints;
7979
}
80-
80+
8181
if (query.skip_waypoints) {
82-
options.skip_waypoints = query.skip_waypoints;
82+
options.skip_waypoints = query.skip_waypoints;
8383
}
84-
84+
8585
if (query.continue_straight) {
86-
options.continue_straight = query.continue_straight === 'true';
86+
options.continue_straight = query.continue_straight === 'true';
8787
}
88-
}
89-
}
90-
88+
}
89+
}

server/TableServiceHandler.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
1-
import {ServiceHandler} from "./ServiceHandler";
1+
import { ServiceHandler } from "./ServiceHandler";
22

33
export class TableServiceHandler extends ServiceHandler {
44
protected buildServiceOptions(options: any, query: any): any {
5-
if (query.scale_factor) {
6-
options.scale_factor = query.scale_factor;
7-
}
8-
if (query.fallback_coordinate) {
9-
options.fallback_coordinate = query.fallback_coordinate;
10-
}
11-
if (query.fallback_speed) {
12-
options.fallback_speed = query.fallback_speed;
13-
}
14-
if (query.sources && query.sources !== 'all') {
15-
options.sources = query.sources;
16-
}
17-
if (query.destinations && query.destinations !== 'all') {
18-
options.destinations = query.destinations;
19-
}
20-
return options;
5+
if (query.scale_factor) {
6+
options.scale_factor = query.scale_factor;
7+
}
8+
if (query.fallback_coordinate) {
9+
options.fallback_coordinate = query.fallback_coordinate;
10+
}
11+
if (query.fallback_speed) {
12+
options.fallback_speed = query.fallback_speed;
13+
}
14+
if (query.sources && query.sources !== 'all') {
15+
options.sources = query.sources;
16+
}
17+
if (query.destinations && query.destinations !== 'all') {
18+
options.destinations = query.destinations;
19+
}
20+
return options;
2121
}
22-
22+
2323
protected async callOSRM(options: any): Promise<any> {
24-
return this.osrm.table(options);
24+
return this.osrm.table(options);
2525
}
26-
}
26+
}

server/TripServiceHandler.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
import {ServiceHandler} from "./ServiceHandler";
1+
import { ServiceHandler } from "./ServiceHandler";
22

33
export class TripServiceHandler extends ServiceHandler {
44
protected buildServiceOptions(options: any, query: any): any {
5-
6-
if (query.roundtrip) {
7-
options.roundtrip = query.roundtrip;
8-
}
9-
if (query.source) {
10-
options.source = query.source;
11-
}
12-
if (query.destination) {
13-
options.destination = query.destination;
14-
}
15-
return options;
5+
6+
if (query.roundtrip) {
7+
options.roundtrip = query.roundtrip;
8+
}
9+
if (query.source) {
10+
options.source = query.source;
11+
}
12+
if (query.destination) {
13+
options.destination = query.destination;
14+
}
15+
return options;
1616
}
17-
18-
17+
18+
1919
protected async callOSRM(options: any): Promise<any> {
20-
return this.osrm.trip(options);
20+
return this.osrm.trip(options);
2121
}
22-
}
23-
22+
}

0 commit comments

Comments
 (0)