@any-routing/core 0.1.0 → 1.0.0-rc.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -1
- package/eslint.config.mjs +24 -0
- package/package.json +7 -28
- package/project.json +21 -0
- package/src/index.ts +4 -0
- package/src/lib/core.model.ts +209 -0
- package/src/lib/core.ts +572 -0
- package/src/lib/data-providers/errors/unauthorized.ts +6 -0
- package/src/lib/data-providers/index.ts +39 -0
- package/src/lib/utils/dispatcher.ts +37 -0
- package/src/lib/utils/{random.js → random.ts} +0 -1
- package/src/lib/utils/requester.ts +41 -0
- package/tsconfig.json +23 -0
- package/tsconfig.lib.json +28 -0
- package/tsconfig.spec.json +28 -0
- package/vite.config.mts +59 -0
- package/src/index.d.ts +0 -4
- package/src/index.js +0 -5
- package/src/index.js.map +0 -1
- package/src/lib/data-providers/errors/index.js +0 -2
- package/src/lib/data-providers/errors/index.js.map +0 -1
- package/src/lib/data-providers/errors/unauthorized.d.ts +0 -6
- package/src/lib/data-providers/errors/unauthorized.js +0 -8
- package/src/lib/data-providers/errors/unauthorized.js.map +0 -1
- package/src/lib/data-providers/index.d.ts +0 -44
- package/src/lib/data-providers/index.js +0 -2
- package/src/lib/data-providers/index.js.map +0 -1
- package/src/lib/libre-routing.d.ts +0 -43
- package/src/lib/libre-routing.js +0 -235
- package/src/lib/libre-routing.js.map +0 -1
- package/src/lib/libre-routing.model.d.ts +0 -108
- package/src/lib/libre-routing.model.js +0 -15
- package/src/lib/libre-routing.model.js.map +0 -1
- package/src/lib/utils/dispatcher.d.ts +0 -7
- package/src/lib/utils/dispatcher.js +0 -25
- package/src/lib/utils/dispatcher.js.map +0 -1
- package/src/lib/utils/index.js +0 -4
- package/src/lib/utils/index.js.map +0 -1
- package/src/lib/utils/random.d.ts +0 -1
- package/src/lib/utils/random.js.map +0 -1
- package/src/lib/utils/requester.d.ts +0 -11
- package/src/lib/utils/requester.js +0 -44
- package/src/lib/utils/requester.js.map +0 -1
- /package/src/lib/data-providers/errors/{index.d.ts → index.ts} +0 -0
- /package/src/lib/utils/{index.d.ts → index.ts} +0 -0
package/tsconfig.json
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../tsconfig.base.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"module": "commonjs",
|
|
5
|
+
"forceConsistentCasingInFileNames": true,
|
|
6
|
+
"strict": true,
|
|
7
|
+
"importHelpers": true,
|
|
8
|
+
"noImplicitOverride": true,
|
|
9
|
+
"noImplicitReturns": true,
|
|
10
|
+
"noFallthroughCasesInSwitch": true,
|
|
11
|
+
"noPropertyAccessFromIndexSignature": true
|
|
12
|
+
},
|
|
13
|
+
"files": [],
|
|
14
|
+
"include": [],
|
|
15
|
+
"references": [
|
|
16
|
+
{
|
|
17
|
+
"path": "./tsconfig.lib.json"
|
|
18
|
+
},
|
|
19
|
+
{
|
|
20
|
+
"path": "./tsconfig.spec.json"
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"declaration": true,
|
|
6
|
+
"types": [
|
|
7
|
+
"node",
|
|
8
|
+
"vite/client"
|
|
9
|
+
]
|
|
10
|
+
},
|
|
11
|
+
"include": [
|
|
12
|
+
"src/**/*.ts"
|
|
13
|
+
],
|
|
14
|
+
"exclude": [
|
|
15
|
+
"vite.config.ts",
|
|
16
|
+
"vite.config.mts",
|
|
17
|
+
"vitest.config.ts",
|
|
18
|
+
"vitest.config.mts",
|
|
19
|
+
"src/**/*.test.ts",
|
|
20
|
+
"src/**/*.spec.ts",
|
|
21
|
+
"src/**/*.test.tsx",
|
|
22
|
+
"src/**/*.spec.tsx",
|
|
23
|
+
"src/**/*.test.js",
|
|
24
|
+
"src/**/*.spec.js",
|
|
25
|
+
"src/**/*.test.jsx",
|
|
26
|
+
"src/**/*.spec.jsx"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"outDir": "../../dist/out-tsc",
|
|
5
|
+
"types": [
|
|
6
|
+
"vitest/globals",
|
|
7
|
+
"vitest/importMeta",
|
|
8
|
+
"vite/client",
|
|
9
|
+
"node",
|
|
10
|
+
"vitest"
|
|
11
|
+
]
|
|
12
|
+
},
|
|
13
|
+
"include": [
|
|
14
|
+
"vite.config.ts",
|
|
15
|
+
"vite.config.mts",
|
|
16
|
+
"vitest.config.ts",
|
|
17
|
+
"vitest.config.mts",
|
|
18
|
+
"src/**/*.test.ts",
|
|
19
|
+
"src/**/*.spec.ts",
|
|
20
|
+
"src/**/*.test.tsx",
|
|
21
|
+
"src/**/*.spec.tsx",
|
|
22
|
+
"src/**/*.test.js",
|
|
23
|
+
"src/**/*.spec.js",
|
|
24
|
+
"src/**/*.test.jsx",
|
|
25
|
+
"src/**/*.spec.jsx",
|
|
26
|
+
"src/**/*.d.ts"
|
|
27
|
+
]
|
|
28
|
+
}
|
package/vite.config.mts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/// <reference types='vitest' />
|
|
2
|
+
import { defineConfig } from 'vite';
|
|
3
|
+
import dts from 'vite-plugin-dts';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
|
|
6
|
+
import { nxCopyAssetsPlugin } from '@nx/vite/plugins/nx-copy-assets.plugin';
|
|
7
|
+
|
|
8
|
+
export default defineConfig(() => ({
|
|
9
|
+
root: import.meta.dirname,
|
|
10
|
+
cacheDir: '../../node_modules/.vite/libs/core',
|
|
11
|
+
plugins: [
|
|
12
|
+
nxViteTsPaths(),
|
|
13
|
+
nxCopyAssetsPlugin(['*.md']),
|
|
14
|
+
dts({
|
|
15
|
+
entryRoot: 'src',
|
|
16
|
+
tsconfigPath: path.join(import.meta.dirname, 'tsconfig.lib.json'),
|
|
17
|
+
pathsToAliases: false,
|
|
18
|
+
}),
|
|
19
|
+
],
|
|
20
|
+
// Uncomment this if you are using workers.
|
|
21
|
+
// worker: {
|
|
22
|
+
// plugins: () => [ nxViteTsPaths() ],
|
|
23
|
+
// },
|
|
24
|
+
// Configuration for building your library.
|
|
25
|
+
// See: https://vite.dev/guide/build.html#library-mode
|
|
26
|
+
build: {
|
|
27
|
+
outDir: '../../dist/libs/core',
|
|
28
|
+
emptyOutDir: true,
|
|
29
|
+
reportCompressedSize: true,
|
|
30
|
+
commonjsOptions: {
|
|
31
|
+
transformMixedEsModules: true,
|
|
32
|
+
},
|
|
33
|
+
lib: {
|
|
34
|
+
// Could also be a dictionary or array of multiple entry points.
|
|
35
|
+
entry: 'src/index.ts',
|
|
36
|
+
name: 'here-data-providerx',
|
|
37
|
+
fileName: 'index',
|
|
38
|
+
// Change this to the formats you want to support.
|
|
39
|
+
// Don't forget to update your package.json as well.
|
|
40
|
+
formats: ['es' as const],
|
|
41
|
+
},
|
|
42
|
+
rolldownOptions: {
|
|
43
|
+
// External packages that should not be bundled into your library.
|
|
44
|
+
external: [],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
test: {
|
|
48
|
+
name: 'here-data-providerx',
|
|
49
|
+
watch: false,
|
|
50
|
+
globals: true,
|
|
51
|
+
environment: 'node',
|
|
52
|
+
include: ['{src,tests}/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}'],
|
|
53
|
+
reporters: ['default'],
|
|
54
|
+
coverage: {
|
|
55
|
+
reportsDirectory: '../coverage/apps/playground/libs/core',
|
|
56
|
+
provider: 'v8' as const,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
}));
|
package/src/index.d.ts
DELETED
package/src/index.js
DELETED
package/src/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../packages/core/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,sBAAsB,CAAC;AACrC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,aAAa,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/data-providers/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"unauthorized.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/data-providers/errors/unauthorized.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,iBAAiB;IAI5B,YAA4B,QAAa;QAAb,aAAQ,GAAR,QAAQ,CAAK;QAHzB,SAAI,GAAG,GAAG,CAAC;QACX,YAAO,GAAG,cAAc,CAAC;IAEG,CAAC;CAC9C"}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import type { BBox, FeatureCollection, Geometry, LineString } from '@turf/helpers';
|
|
2
|
-
import { Waypoint, LngLatPosition, Mode } from '../libre-routing.model';
|
|
3
|
-
export interface AnyRoutingDataProvider {
|
|
4
|
-
request: (waypoints: Waypoint[], opts: RequestOptions) => Promise<AnyRoutingDataResponse>;
|
|
5
|
-
destroy(): void;
|
|
6
|
-
hasPendingRequests(): Promise<boolean>;
|
|
7
|
-
abortAllRequests(): void;
|
|
8
|
-
}
|
|
9
|
-
export interface RequestOptions {
|
|
10
|
-
mode: Mode;
|
|
11
|
-
}
|
|
12
|
-
export interface AnyRoutingDataResponse {
|
|
13
|
-
rawResponse: any;
|
|
14
|
-
routesShapeGeojson: FeatureCollection<Geometry, {
|
|
15
|
-
routeId: number;
|
|
16
|
-
waypoint: number;
|
|
17
|
-
}>;
|
|
18
|
-
routes: RouteSummary[];
|
|
19
|
-
selectedRouteId?: number | null;
|
|
20
|
-
routesShapeBounds?: BBox;
|
|
21
|
-
version: number;
|
|
22
|
-
latest: boolean;
|
|
23
|
-
mode: Mode;
|
|
24
|
-
}
|
|
25
|
-
export type RoutePath = LngLatPosition[];
|
|
26
|
-
export interface RouteSummary {
|
|
27
|
-
id: number;
|
|
28
|
-
label?: string;
|
|
29
|
-
path: RoutePath;
|
|
30
|
-
durationTime: number;
|
|
31
|
-
arriveTime: Date;
|
|
32
|
-
departureTime: Date;
|
|
33
|
-
distance: number;
|
|
34
|
-
cost?: number;
|
|
35
|
-
waypoints: {
|
|
36
|
-
lat: number;
|
|
37
|
-
lng: number;
|
|
38
|
-
}[];
|
|
39
|
-
shape: FeatureCollection<LineString, {
|
|
40
|
-
routeId: number;
|
|
41
|
-
waypoint: number;
|
|
42
|
-
}>;
|
|
43
|
-
}
|
|
44
|
-
export * from './errors';
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/data-providers/index.ts"],"names":[],"mappings":"AAyCA,cAAc,UAAU,CAAC"}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { AnyRoutingDataResponse, RouteSummary } from './data-providers';
|
|
2
|
-
import { AnyRoutingEventsMap, AnyRoutingOptions, AnyRoutingState, Waypoint as InputWaypoint, InternalWaypoint, RecalculateOptions, Mode } from './libre-routing.model';
|
|
3
|
-
export declare class AnyRouting<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> {
|
|
4
|
-
private readonly dispatcher;
|
|
5
|
-
private readonly geocoder?;
|
|
6
|
-
private _options;
|
|
7
|
-
private _plugins;
|
|
8
|
-
private _initialState;
|
|
9
|
-
private _state;
|
|
10
|
-
get options(): AnyRoutingOptions;
|
|
11
|
-
get data(): R;
|
|
12
|
-
get state(): AnyRoutingState<R>;
|
|
13
|
-
get dataProvider(): import("./data-providers").AnyRoutingDataProvider;
|
|
14
|
-
get selectedRouteId(): number | undefined | null;
|
|
15
|
-
private get waypoints();
|
|
16
|
-
constructor(options: AnyRoutingOptions);
|
|
17
|
-
initialize(): void;
|
|
18
|
-
onRemove(): void;
|
|
19
|
-
setMode(mode: Mode): void;
|
|
20
|
-
setWaypoints(waypoints: InputWaypoint[]): void;
|
|
21
|
-
getWaypoint(waypointId: number): InternalWaypoint;
|
|
22
|
-
recalculateRoute(opts?: RecalculateOptions & Record<string, any>): Promise<R | undefined>;
|
|
23
|
-
on<E extends keyof AnyRoutingEventsMap>(event: E, callback: (event: AnyRoutingEventsMap[E]) => void): void;
|
|
24
|
-
off<E extends keyof AnyRoutingEventsMap>(event: E, callback: (event: AnyRoutingEventsMap[E]) => void): void;
|
|
25
|
-
selectRoute(routeId: number): void;
|
|
26
|
-
reset(): void;
|
|
27
|
-
getUniqueName(name: string): string;
|
|
28
|
-
syncWaypointsPositions(waypoints: RouteSummary['waypoints']): InternalWaypoint[];
|
|
29
|
-
setState({ waypoints, data, routesShapeGeojson, selectedRouteId, }: {
|
|
30
|
-
waypoints?: InputWaypoint[];
|
|
31
|
-
data?: R;
|
|
32
|
-
routesShapeGeojson?: R['routesShapeGeojson'];
|
|
33
|
-
selectedRouteId?: number | null;
|
|
34
|
-
}): void;
|
|
35
|
-
private initPlugins;
|
|
36
|
-
private detachPlugins;
|
|
37
|
-
private resolvePlugin;
|
|
38
|
-
private _setState;
|
|
39
|
-
private _patchState;
|
|
40
|
-
private transformToInternalWaypoints;
|
|
41
|
-
private fire;
|
|
42
|
-
private geocodeWaypoints;
|
|
43
|
-
}
|
package/src/lib/libre-routing.js
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { __awaiter } from "tslib";
|
|
2
|
-
import { Dispatcher } from './utils/dispatcher';
|
|
3
|
-
import { randomId } from './utils/random';
|
|
4
|
-
import { InternalWaypointC, } from './libre-routing.model';
|
|
5
|
-
import { featureCollection } from '@turf/helpers';
|
|
6
|
-
export class AnyRouting {
|
|
7
|
-
get options() {
|
|
8
|
-
return this._options;
|
|
9
|
-
}
|
|
10
|
-
get data() {
|
|
11
|
-
return this._state.data;
|
|
12
|
-
}
|
|
13
|
-
get state() {
|
|
14
|
-
return this._state;
|
|
15
|
-
}
|
|
16
|
-
get dataProvider() {
|
|
17
|
-
return this.options.dataProvider;
|
|
18
|
-
}
|
|
19
|
-
get selectedRouteId() {
|
|
20
|
-
return this._state.selectedRouteId;
|
|
21
|
-
}
|
|
22
|
-
get waypoints() {
|
|
23
|
-
return this._state.waypoints;
|
|
24
|
-
}
|
|
25
|
-
constructor(options) {
|
|
26
|
-
var _a;
|
|
27
|
-
this.dispatcher = new Dispatcher();
|
|
28
|
-
this._plugins = [];
|
|
29
|
-
this._initialState = {
|
|
30
|
-
waypoints: [],
|
|
31
|
-
data: undefined,
|
|
32
|
-
loading: false,
|
|
33
|
-
selectedRouteId: undefined,
|
|
34
|
-
mode: 'default',
|
|
35
|
-
routesShapeGeojson: undefined,
|
|
36
|
-
};
|
|
37
|
-
this._state = Object.assign({}, this._initialState);
|
|
38
|
-
this._options = Object.assign({ uniqueKey: randomId() }, options);
|
|
39
|
-
this._plugins = (_a = options.plugins) !== null && _a !== void 0 ? _a : [];
|
|
40
|
-
if (this.options.waypointsSyncStrategy === 'geocodeFirst' && !this.options.geocoder) {
|
|
41
|
-
throw new Error('Geocoder is required when waypointsSyncStrategy is `geocodeFirst`');
|
|
42
|
-
}
|
|
43
|
-
this.geocoder =
|
|
44
|
-
this.options.geocoder && typeof this.options.geocoder === 'function'
|
|
45
|
-
? { geocode: this.options.geocoder }
|
|
46
|
-
: this.options.geocoder;
|
|
47
|
-
}
|
|
48
|
-
initialize() {
|
|
49
|
-
this.initPlugins();
|
|
50
|
-
}
|
|
51
|
-
onRemove() {
|
|
52
|
-
var _a;
|
|
53
|
-
this.detachPlugins();
|
|
54
|
-
(_a = this.options.dataProvider) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
55
|
-
}
|
|
56
|
-
setMode(mode) {
|
|
57
|
-
this._patchState({ mode });
|
|
58
|
-
}
|
|
59
|
-
setWaypoints(waypoints) {
|
|
60
|
-
const internalWaypoints = this.transformToInternalWaypoints(waypoints);
|
|
61
|
-
this._patchState({ waypoints: internalWaypoints });
|
|
62
|
-
}
|
|
63
|
-
getWaypoint(waypointId) {
|
|
64
|
-
return this._state.waypoints[waypointId];
|
|
65
|
-
}
|
|
66
|
-
recalculateRoute(opts = {}) {
|
|
67
|
-
var _a;
|
|
68
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
-
if (this.waypoints.length < 2)
|
|
70
|
-
return;
|
|
71
|
-
if (!this.options.dataProvider) {
|
|
72
|
-
throw new Error('No data provider');
|
|
73
|
-
}
|
|
74
|
-
if (opts.dropPendingRequests) {
|
|
75
|
-
yield this.options.dataProvider.abortAllRequests();
|
|
76
|
-
}
|
|
77
|
-
let patchState = {};
|
|
78
|
-
if (!this._state.loading) {
|
|
79
|
-
patchState = Object.assign(Object.assign({}, patchState), { loading: true });
|
|
80
|
-
}
|
|
81
|
-
this.fire('calculationStarted', {
|
|
82
|
-
mode: this.state.mode,
|
|
83
|
-
waypoints: this.waypoints,
|
|
84
|
-
recalculateOptions: opts,
|
|
85
|
-
});
|
|
86
|
-
this._patchState(patchState);
|
|
87
|
-
if ('loading' in patchState) {
|
|
88
|
-
this.fire('loadingChanged', { loading: true });
|
|
89
|
-
}
|
|
90
|
-
try {
|
|
91
|
-
let patchState = {};
|
|
92
|
-
if (opts.syncWaypoints !== false && this.options.waypointsSyncStrategy === 'geocodeFirst') {
|
|
93
|
-
const waypointsToSyncIds = this._state.waypoints.reduce((acc, w, index) => {
|
|
94
|
-
if (!w.geocoded) {
|
|
95
|
-
acc.push(index);
|
|
96
|
-
}
|
|
97
|
-
return acc;
|
|
98
|
-
}, []);
|
|
99
|
-
if (waypointsToSyncIds.length > 0) {
|
|
100
|
-
const waypoints = yield this.geocodeWaypoints(this._state.waypoints);
|
|
101
|
-
this._patchState({ waypoints });
|
|
102
|
-
waypointsToSyncIds.forEach((waypointId) => {
|
|
103
|
-
this.fire('waypointGeocoded', { waypoint: waypoints[waypointId] });
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
const data = (yield this.options.dataProvider.request(this._state.waypoints, {
|
|
108
|
-
mode: this.state.mode,
|
|
109
|
-
}));
|
|
110
|
-
patchState = Object.assign(Object.assign({}, patchState), { data, selectedRouteId: data.selectedRouteId, routesShapeGeojson: data.routesShapeGeojson });
|
|
111
|
-
if (opts.syncWaypoints !== false && this.options.waypointsSyncStrategy === 'toPath') {
|
|
112
|
-
const syncedWaypoints = this.syncWaypointsPositions(data.routes[0].waypoints);
|
|
113
|
-
patchState = Object.assign(Object.assign({}, patchState), { waypoints: syncedWaypoints });
|
|
114
|
-
}
|
|
115
|
-
this._patchState(patchState);
|
|
116
|
-
this.fire('routesFound', {
|
|
117
|
-
mode: this.state.mode,
|
|
118
|
-
waypoints: this._state.waypoints,
|
|
119
|
-
data,
|
|
120
|
-
recalculateOptions: opts,
|
|
121
|
-
});
|
|
122
|
-
return this._state.data;
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
this.fire('calculationError', { error: e, recalculateOptions: opts });
|
|
126
|
-
throw e;
|
|
127
|
-
}
|
|
128
|
-
finally {
|
|
129
|
-
if (this._state.loading && (((_a = this.data) === null || _a === void 0 ? void 0 : _a.latest) || !(yield this.dataProvider.hasPendingRequests()))) {
|
|
130
|
-
this._patchState({ loading: false });
|
|
131
|
-
this.fire('loadingChanged', { loading: false });
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
on(event, callback) {
|
|
137
|
-
this.dispatcher.on(event, callback);
|
|
138
|
-
}
|
|
139
|
-
off(event, callback) {
|
|
140
|
-
this.dispatcher.off(event, callback);
|
|
141
|
-
}
|
|
142
|
-
selectRoute(routeId) {
|
|
143
|
-
if (!this.data) {
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
const features = this.data.routesShapeGeojson.features.map((feature) => {
|
|
147
|
-
return Object.assign(Object.assign({}, feature), { properties: Object.assign(Object.assign({}, feature.properties), { selected: feature.properties.routeId === routeId }) });
|
|
148
|
-
});
|
|
149
|
-
this._patchState({
|
|
150
|
-
selectedRouteId: routeId,
|
|
151
|
-
data: Object.assign(Object.assign({}, this._state.data), { routesShapeGeojson: featureCollection(features), selectedRouteId: routeId }),
|
|
152
|
-
routesShapeGeojson: featureCollection(features),
|
|
153
|
-
});
|
|
154
|
-
this.fire('routeSelected', {
|
|
155
|
-
route: this.data.routes[routeId],
|
|
156
|
-
routeId: routeId,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
reset() {
|
|
160
|
-
this._setState(Object.assign({}, this._initialState), 'external');
|
|
161
|
-
}
|
|
162
|
-
getUniqueName(name) {
|
|
163
|
-
return `${name}-${this.options.uniqueKey}`;
|
|
164
|
-
}
|
|
165
|
-
syncWaypointsPositions(waypoints) {
|
|
166
|
-
const newWaypoints = waypoints.map((waypoint, index) => (Object.assign(Object.assign({}, this._state.waypoints[index]), { position: waypoint, originalPosition: this._state.waypoints[index].originalPosition || this._state.waypoints[index].position, properties: this._state.waypoints[index].properties })));
|
|
167
|
-
return newWaypoints;
|
|
168
|
-
}
|
|
169
|
-
setState({ waypoints, data, routesShapeGeojson, selectedRouteId, }) {
|
|
170
|
-
let newState = Object.assign({}, this._state);
|
|
171
|
-
if (waypoints) {
|
|
172
|
-
const internalWaypoints = this.transformToInternalWaypoints(waypoints);
|
|
173
|
-
newState = Object.assign(Object.assign({}, newState), { waypoints: internalWaypoints });
|
|
174
|
-
}
|
|
175
|
-
if (routesShapeGeojson) {
|
|
176
|
-
newState = Object.assign(Object.assign({}, newState), { routesShapeGeojson });
|
|
177
|
-
}
|
|
178
|
-
if (data) {
|
|
179
|
-
newState = Object.assign(Object.assign({}, newState), { data, routesShapeGeojson: data.routesShapeGeojson });
|
|
180
|
-
}
|
|
181
|
-
if (selectedRouteId != null) {
|
|
182
|
-
newState = Object.assign(Object.assign({}, newState), { selectedRouteId });
|
|
183
|
-
}
|
|
184
|
-
if (data || waypoints || routesShapeGeojson || selectedRouteId != null) {
|
|
185
|
-
this._setState(newState, 'external');
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
initPlugins() {
|
|
189
|
-
this._plugins.forEach((plugin) => this.resolvePlugin(plugin).onAdd(this));
|
|
190
|
-
}
|
|
191
|
-
detachPlugins() {
|
|
192
|
-
this._plugins.forEach((plugin) => this.resolvePlugin(plugin).onRemove(this));
|
|
193
|
-
}
|
|
194
|
-
resolvePlugin(plugin) {
|
|
195
|
-
if (typeof plugin === 'function') {
|
|
196
|
-
return new plugin({});
|
|
197
|
-
}
|
|
198
|
-
return plugin;
|
|
199
|
-
}
|
|
200
|
-
_setState(newState, source = 'internal', updatedKeys) {
|
|
201
|
-
this._state = newState;
|
|
202
|
-
this.fire('stateUpdated', {
|
|
203
|
-
source,
|
|
204
|
-
updatedProperties: updatedKeys !== null && updatedKeys !== void 0 ? updatedKeys : Object.keys(this.state),
|
|
205
|
-
});
|
|
206
|
-
}
|
|
207
|
-
_patchState(patchState, source = 'internal') {
|
|
208
|
-
if (Object.keys(patchState).length === 0) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
this._setState(Object.assign(Object.assign({}, this._state), patchState), source, Object.keys(patchState));
|
|
212
|
-
if ('waypoints' in patchState) {
|
|
213
|
-
this.fire('waypointsChanged', { waypoints: this.state.waypoints });
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
transformToInternalWaypoints(waypoints) {
|
|
217
|
-
return waypoints.map((waypoint, index) => InternalWaypointC.fromWaypoint(waypoint, { index, isFirst: index === 0, isLast: index === waypoints.length - 1 }));
|
|
218
|
-
}
|
|
219
|
-
fire(event, data) {
|
|
220
|
-
//@ts-ignore
|
|
221
|
-
this.dispatcher.fire(event, Object.assign(Object.assign({}, data), { state: this.state, eventName: event }));
|
|
222
|
-
}
|
|
223
|
-
geocodeWaypoints(waypoints) {
|
|
224
|
-
const waypointGeocodes = waypoints.map((waypoint) => __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
if (waypoint.geocoded) {
|
|
226
|
-
return waypoint;
|
|
227
|
-
}
|
|
228
|
-
const geocodedWaypoint = yield this.geocoder.geocode(waypoint);
|
|
229
|
-
geocodedWaypoint.geocoded = true;
|
|
230
|
-
return geocodedWaypoint;
|
|
231
|
-
}));
|
|
232
|
-
return Promise.all(waypointGeocodes);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
//# sourceMappingURL=libre-routing.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libre-routing.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/libre-routing.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EASL,iBAAiB,GAIlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,OAAO,UAAU;IAkBrB,IAAW,OAAO;QAChB,OAAO,IAAI,CAAC,QAAQ,CAAC;IACvB,CAAC;IAED,IAAW,IAAI;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAW,KAAK;QACd,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED,IAAW,YAAY;QACrB,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC;IACnC,CAAC;IAED,IAAW,eAAe;QACxB,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;IACrC,CAAC;IAED,IAAY,SAAS;QACnB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC/B,CAAC;IAED,YAAY,OAA0B;;QAzCrB,eAAU,GAAG,IAAI,UAAU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,CAAC,UAAU,CAAC,IAAI,CAAC,KAAK,EAAE,gCAA6B,IAAI,KAAE,KAAK,EAAE,IAAI,CAAC,KAAK,EAAE,SAAS,EAAE,KAAK,GAAE,CAAC,CAAC;IACxG,CAAC;IAEO,gBAAgB,CAAC,SAA6B;QACpD,MAAM,gBAAgB,GAAG,SAAS,CAAC,GAAG,CAAC,CAAO,QAAQ,EAAE,EAAE;YACxD,IAAI,QAAQ,CAAC,QAAQ,EAAE;gBACrB,OAAO,QAAQ,CAAC;aACjB;YAED,MAAM,gBAAgB,GAAG,MAAM,IAAI,CAAC,QAAS,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;YAChE,gBAAgB,CAAC,QAAQ,GAAG,IAAI,CAAC;YAEjC,OAAO,gBAAgB,CAAC;QAC1B,CAAC,CAAA,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC;IACvC,CAAC;CACF"}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { AnyRoutingDataProvider, AnyRoutingDataResponse, RouteSummary } from './data-providers';
|
|
2
|
-
import type { AnyRouting } from './libre-routing';
|
|
3
|
-
export type LngLatPosition = [number, number];
|
|
4
|
-
export type WaypointPosition = {
|
|
5
|
-
lat: number;
|
|
6
|
-
lng: number;
|
|
7
|
-
};
|
|
8
|
-
export type Mode = 'default' | 'drag';
|
|
9
|
-
export type BaseEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = {
|
|
10
|
-
state: AnyRoutingState<R>;
|
|
11
|
-
eventName: keyof MessagePortEventMap;
|
|
12
|
-
};
|
|
13
|
-
export type CalculationStartedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
14
|
-
waypoints: InternalWaypoint[];
|
|
15
|
-
recalculateOptions: RecalculateOptions;
|
|
16
|
-
mode: Mode;
|
|
17
|
-
};
|
|
18
|
-
export type CalculationErrorEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
19
|
-
error: Error;
|
|
20
|
-
recalculateOptions: RecalculateOptions;
|
|
21
|
-
};
|
|
22
|
-
export type RoutesFoundEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
23
|
-
waypoints: InternalWaypoint[];
|
|
24
|
-
data: R;
|
|
25
|
-
mode: Mode;
|
|
26
|
-
recalculateOptions: RecalculateOptions;
|
|
27
|
-
};
|
|
28
|
-
export type RouteSelectedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
29
|
-
routeId: number;
|
|
30
|
-
route: RouteSummary;
|
|
31
|
-
};
|
|
32
|
-
export type WaypointsChangedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
33
|
-
waypoints: InternalWaypoint[];
|
|
34
|
-
};
|
|
35
|
-
export type WaypointGeocoded<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
36
|
-
waypoint: InternalWaypoint;
|
|
37
|
-
};
|
|
38
|
-
export type LoadingChangedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
39
|
-
loading: boolean;
|
|
40
|
-
};
|
|
41
|
-
export type StateUpdateSource = 'internal' | 'external';
|
|
42
|
-
export type StateUpdatedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
43
|
-
state: AnyRoutingState<R>;
|
|
44
|
-
source: StateUpdateSource;
|
|
45
|
-
updatedProperties: Array<keyof AnyRoutingState<R>>;
|
|
46
|
-
};
|
|
47
|
-
export interface AnyRoutingEventsMap {
|
|
48
|
-
calculationStarted: CalculationStartedEvent;
|
|
49
|
-
calculationError: CalculationErrorEvent;
|
|
50
|
-
routesFound: RoutesFoundEvent;
|
|
51
|
-
routeSelected: RouteSelectedEvent;
|
|
52
|
-
waypointsChanged: WaypointsChangedEvent;
|
|
53
|
-
waypointGeocoded: WaypointGeocoded;
|
|
54
|
-
loadingChanged: LoadingChangedEvent;
|
|
55
|
-
stateUpdated: StateUpdatedEvent;
|
|
56
|
-
}
|
|
57
|
-
export type AnyRoutingEvents = keyof AnyRoutingEventsMap;
|
|
58
|
-
export type InternalWaypointProperties = {
|
|
59
|
-
index: number;
|
|
60
|
-
isFirst: boolean;
|
|
61
|
-
isLast: boolean;
|
|
62
|
-
};
|
|
63
|
-
export type AnyRoutingState<DataType = AnyRoutingDataResponse> = {
|
|
64
|
-
data: DataType | undefined;
|
|
65
|
-
waypoints: InternalWaypoint[];
|
|
66
|
-
loading: boolean;
|
|
67
|
-
selectedRouteId: number | undefined | null;
|
|
68
|
-
mode: Mode;
|
|
69
|
-
routesShapeGeojson?: AnyRoutingDataResponse['routesShapeGeojson'];
|
|
70
|
-
};
|
|
71
|
-
export interface InternalWaypoint {
|
|
72
|
-
index: number;
|
|
73
|
-
position: WaypointPosition;
|
|
74
|
-
originalPosition: WaypointPosition;
|
|
75
|
-
properties: InternalWaypointProperties & Record<string, any>;
|
|
76
|
-
geocoded?: boolean;
|
|
77
|
-
}
|
|
78
|
-
export declare function isWaypointPositionEqual(posA: WaypointPosition, posB: WaypointPosition): boolean;
|
|
79
|
-
export declare class InternalWaypointC {
|
|
80
|
-
static fromWaypoint(waypoint: Waypoint, props: InternalWaypointProperties): InternalWaypoint;
|
|
81
|
-
}
|
|
82
|
-
export interface Waypoint {
|
|
83
|
-
position: WaypointPosition;
|
|
84
|
-
originalPosition?: WaypointPosition;
|
|
85
|
-
properties?: Record<string, string | boolean | number>;
|
|
86
|
-
geocoded?: boolean;
|
|
87
|
-
}
|
|
88
|
-
export type PluginFactory = AnyRoutingPlugin | (new (...args: any[]) => AnyRoutingPlugin);
|
|
89
|
-
export interface AnyRoutingGeocoder {
|
|
90
|
-
geocode(waypoint: InternalWaypoint): Promise<InternalWaypoint>;
|
|
91
|
-
}
|
|
92
|
-
export type AnyRoutingOptions = {
|
|
93
|
-
dataProvider: AnyRoutingDataProvider;
|
|
94
|
-
geocoder?: AnyRoutingGeocoder | ((waypoint: InternalWaypoint) => Promise<InternalWaypoint>);
|
|
95
|
-
plugins?: PluginFactory[];
|
|
96
|
-
uniqueKey?: string;
|
|
97
|
-
waypointsSyncStrategy: 'none' | 'toPath' | 'geocodeFirst';
|
|
98
|
-
};
|
|
99
|
-
export interface AnyRoutingPlugin {
|
|
100
|
-
onAdd(AnyRouting: AnyRouting<any>): void;
|
|
101
|
-
onRemove(AnyRouting: AnyRouting<any>): void;
|
|
102
|
-
}
|
|
103
|
-
export interface RecalculateOptions {
|
|
104
|
-
fitViewToData?: boolean;
|
|
105
|
-
clearMap?: boolean;
|
|
106
|
-
dropPendingRequests?: boolean;
|
|
107
|
-
syncWaypoints?: boolean;
|
|
108
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
export function isWaypointPositionEqual(posA, posB) {
|
|
2
|
-
return posA.lat === posB.lat && posA.lng === posB.lng;
|
|
3
|
-
}
|
|
4
|
-
export class InternalWaypointC {
|
|
5
|
-
static fromWaypoint(waypoint, props) {
|
|
6
|
-
return {
|
|
7
|
-
index: props.index,
|
|
8
|
-
originalPosition: waypoint.position,
|
|
9
|
-
position: waypoint.position,
|
|
10
|
-
geocoded: waypoint.geocoded,
|
|
11
|
-
properties: Object.assign(Object.assign({}, props), (waypoint.properties || {})),
|
|
12
|
-
};
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=libre-routing.model.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"libre-routing.model.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/libre-routing.model.ts"],"names":[],"mappings":"AA6FA,MAAM,UAAU,uBAAuB,CAAC,IAAsB,EAAE,IAAsB;IACpF,OAAO,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,GAAG,KAAK,IAAI,CAAC,GAAG,CAAC;AACxD,CAAC;AAED,MAAM,OAAO,iBAAiB;IACrB,MAAM,CAAC,YAAY,CAAC,QAAkB,EAAE,KAAiC;QAC9E,OAAO;YACL,KAAK,EAAE,KAAK,CAAC,KAAK;YAClB,gBAAgB,EAAE,QAAQ,CAAC,QAAQ;YACnC,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,QAAQ,EAAE,QAAQ,CAAC,QAAQ;YAC3B,UAAU,kCAAO,KAAK,GAAK,CAAC,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC,CAAE;SACzD,CAAC;IACJ,CAAC;CACF"}
|