mirror of
https://gitlab.com/mobicoop/v3/service/matcher.git
synced 2026-01-01 08:12:40 +00:00
create ad, WIP
This commit is contained in:
@@ -75,15 +75,21 @@ export class GraphhopperGeorouter implements IGeorouter {
|
||||
this.getUrl(),
|
||||
'&point=',
|
||||
path.points
|
||||
.map((point) => [point.lat, point.lon].join())
|
||||
.map((point) => [point.lat, point.lon].join('%2C'))
|
||||
.join('&point='),
|
||||
].join('');
|
||||
const route = await lastValueFrom(
|
||||
this.httpService.get(url).pipe(
|
||||
map((res) => (res.data ? this.createRoute(res) : undefined)),
|
||||
catchError((error: AxiosError) => {
|
||||
if (error.code == AxiosError.ERR_BAD_REQUEST) {
|
||||
throw new GeographyException(
|
||||
ExceptionCode.OUT_OF_RANGE,
|
||||
'No route found for given coordinates',
|
||||
);
|
||||
}
|
||||
throw new GeographyException(
|
||||
ExceptionCode.INTERNAL,
|
||||
ExceptionCode.UNAVAILABLE,
|
||||
'Georouter unavailable : ' + error.message,
|
||||
);
|
||||
}),
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
import { Coordinates } from '../../domain/entities/coordinates';
|
||||
import { IEncodeDirection } from '../../domain/interfaces/direction-encoder.interface';
|
||||
|
||||
export class PostgresDirectionEncoder implements IEncodeDirection {
|
||||
encode = (coordinates: Coordinates[]): string =>
|
||||
[
|
||||
"'LINESTRING(",
|
||||
coordinates.map((point) => [point.lon, point.lat].join(' ')).join(),
|
||||
")'",
|
||||
].join('');
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
import { Coordinates } from '../entities/coordinates';
|
||||
|
||||
export interface IEncodeDirection {
|
||||
encode(coordinates: Coordinates[]): string;
|
||||
}
|
||||
@@ -1,13 +1,11 @@
|
||||
export class GeographyException implements Error {
|
||||
name: string;
|
||||
code: number;
|
||||
message: string;
|
||||
|
||||
constructor(private _code: number, private _message: string) {
|
||||
constructor(code: number, message: string) {
|
||||
this.name = 'GeographyException';
|
||||
this.message = _message;
|
||||
}
|
||||
|
||||
get code(): number {
|
||||
return this._code;
|
||||
this.code = code;
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user