@any-routing/core 0.0.0
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 +7 -0
- package/package.json +30 -0
- package/src/index.d.ts +4 -0
- package/src/index.js +5 -0
- package/src/index.js.map +1 -0
- package/src/lib/data-providers/errors/index.d.ts +1 -0
- package/src/lib/data-providers/errors/index.js +2 -0
- package/src/lib/data-providers/errors/index.js.map +1 -0
- package/src/lib/data-providers/errors/unauthorized.d.ts +6 -0
- package/src/lib/data-providers/errors/unauthorized.js +8 -0
- package/src/lib/data-providers/errors/unauthorized.js.map +1 -0
- package/src/lib/data-providers/index.d.ts +44 -0
- package/src/lib/data-providers/index.js +2 -0
- package/src/lib/data-providers/index.js.map +1 -0
- package/src/lib/libre-routing.d.ts +43 -0
- package/src/lib/libre-routing.js +212 -0
- package/src/lib/libre-routing.js.map +1 -0
- package/src/lib/libre-routing.model.d.ts +103 -0
- package/src/lib/libre-routing.model.js +27 -0
- package/src/lib/libre-routing.model.js.map +1 -0
- package/src/lib/utils/dispatcher.d.ts +7 -0
- package/src/lib/utils/dispatcher.js +25 -0
- package/src/lib/utils/dispatcher.js.map +1 -0
- package/src/lib/utils/index.d.ts +3 -0
- package/src/lib/utils/index.js +4 -0
- package/src/lib/utils/index.js.map +1 -0
- package/src/lib/utils/random.d.ts +1 -0
- package/src/lib/utils/random.js +2 -0
- package/src/lib/utils/random.js.map +1 -0
- package/src/lib/utils/requester.d.ts +11 -0
- package/src/lib/utils/requester.js +44 -0
- package/src/lib/utils/requester.js.map +1 -0
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@any-routing/core",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"author": "Marcin Lazar",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"MapLibre GL",
|
|
8
|
+
"Routing",
|
|
9
|
+
"Directions",
|
|
10
|
+
"Route",
|
|
11
|
+
"OSMR",
|
|
12
|
+
"Here",
|
|
13
|
+
"Plugin",
|
|
14
|
+
"Map",
|
|
15
|
+
"js",
|
|
16
|
+
"leaflet"
|
|
17
|
+
],
|
|
18
|
+
"repository": {
|
|
19
|
+
"type": "git",
|
|
20
|
+
"url": "https://github.com/marucjmar/any-routing"
|
|
21
|
+
},
|
|
22
|
+
"dependencies": {
|
|
23
|
+
"@turf/helpers": "6.5.0"
|
|
24
|
+
},
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"tslib": "2.5.0"
|
|
27
|
+
},
|
|
28
|
+
"main": "./src/index.js",
|
|
29
|
+
"types": "./src/index.d.ts"
|
|
30
|
+
}
|
package/src/index.d.ts
ADDED
package/src/index.js
ADDED
package/src/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './unauthorized';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../../packages/core/src/lib/data-providers/errors/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,44 @@
|
|
|
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';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/data-providers/index.ts"],"names":[],"mappings":"AAyCA,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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, MapType extends object = object> {
|
|
4
|
+
private readonly dispatcher;
|
|
5
|
+
private _map;
|
|
6
|
+
private _options;
|
|
7
|
+
private _plugins;
|
|
8
|
+
private _initialState;
|
|
9
|
+
private _state;
|
|
10
|
+
get map(): MapType;
|
|
11
|
+
get options(): AnyRoutingOptions;
|
|
12
|
+
get data(): R;
|
|
13
|
+
get state(): AnyRoutingState<R>;
|
|
14
|
+
get dataProvider(): import("./data-providers").AnyRoutingDataProvider;
|
|
15
|
+
get selectedRouteId(): number | undefined | null;
|
|
16
|
+
private get waypoints();
|
|
17
|
+
constructor(options: AnyRoutingOptions);
|
|
18
|
+
initialize(map: MapType): void;
|
|
19
|
+
onRemove(): void;
|
|
20
|
+
setMode(mode: Mode): void;
|
|
21
|
+
setWaypoints(waypoints: InputWaypoint[]): void;
|
|
22
|
+
getWaypoint(waypointId: number): InternalWaypoint;
|
|
23
|
+
recalculateRoute(opts?: RecalculateOptions & Record<string, any>): Promise<R | undefined>;
|
|
24
|
+
on<E extends keyof AnyRoutingEventsMap>(event: E, callback: (event: AnyRoutingEventsMap[E]) => void): void;
|
|
25
|
+
off<E extends keyof AnyRoutingEventsMap>(event: E, callback: (event: AnyRoutingEventsMap[E]) => void): void;
|
|
26
|
+
selectRoute(routeId: number): void;
|
|
27
|
+
reset(): void;
|
|
28
|
+
getUniqueName(name: string): string;
|
|
29
|
+
syncWaypointsPositions(waypoints: RouteSummary['waypoints']): InternalWaypoint[];
|
|
30
|
+
setState({ waypoints, data, routesShapeGeojson, selectedRouteId, }: {
|
|
31
|
+
waypoints?: InputWaypoint[];
|
|
32
|
+
data?: R;
|
|
33
|
+
routesShapeGeojson?: R['routesShapeGeojson'];
|
|
34
|
+
selectedRouteId?: number | null;
|
|
35
|
+
}): void;
|
|
36
|
+
private initPlugins;
|
|
37
|
+
private detachPlugins;
|
|
38
|
+
private resolvePlugin;
|
|
39
|
+
private _setState;
|
|
40
|
+
private _patchState;
|
|
41
|
+
private transformToInternalWaypoints;
|
|
42
|
+
private fire;
|
|
43
|
+
}
|
|
@@ -0,0 +1,212 @@
|
|
|
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 map() {
|
|
8
|
+
return this._map;
|
|
9
|
+
}
|
|
10
|
+
get options() {
|
|
11
|
+
return this._options;
|
|
12
|
+
}
|
|
13
|
+
get data() {
|
|
14
|
+
return this._state.data;
|
|
15
|
+
}
|
|
16
|
+
get state() {
|
|
17
|
+
return this._state;
|
|
18
|
+
}
|
|
19
|
+
get dataProvider() {
|
|
20
|
+
return this.options.dataProvider;
|
|
21
|
+
}
|
|
22
|
+
get selectedRouteId() {
|
|
23
|
+
return this._state.selectedRouteId;
|
|
24
|
+
}
|
|
25
|
+
get waypoints() {
|
|
26
|
+
return this._state.waypoints;
|
|
27
|
+
}
|
|
28
|
+
constructor(options) {
|
|
29
|
+
var _a;
|
|
30
|
+
this.dispatcher = new Dispatcher();
|
|
31
|
+
this._plugins = [];
|
|
32
|
+
this._initialState = {
|
|
33
|
+
waypoints: [],
|
|
34
|
+
data: undefined,
|
|
35
|
+
loading: false,
|
|
36
|
+
selectedRouteId: undefined,
|
|
37
|
+
mode: 'default',
|
|
38
|
+
routesShapeGeojson: undefined,
|
|
39
|
+
};
|
|
40
|
+
this._state = Object.assign({}, this._initialState);
|
|
41
|
+
this._options = Object.assign({ uniqueKey: randomId() }, options);
|
|
42
|
+
this._plugins = (_a = options.plugins) !== null && _a !== void 0 ? _a : [];
|
|
43
|
+
}
|
|
44
|
+
initialize(map) {
|
|
45
|
+
this._map = map;
|
|
46
|
+
this.initPlugins();
|
|
47
|
+
}
|
|
48
|
+
onRemove() {
|
|
49
|
+
var _a;
|
|
50
|
+
this.detachPlugins();
|
|
51
|
+
(_a = this.options.dataProvider) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
52
|
+
}
|
|
53
|
+
setMode(mode) {
|
|
54
|
+
this._patchState({ mode });
|
|
55
|
+
}
|
|
56
|
+
setWaypoints(waypoints) {
|
|
57
|
+
const internalWaypoints = this.transformToInternalWaypoints(waypoints);
|
|
58
|
+
this._patchState({ waypoints: internalWaypoints });
|
|
59
|
+
this.fire('waypointsChanged', { waypoints: this.state.waypoints });
|
|
60
|
+
}
|
|
61
|
+
getWaypoint(waypointId) {
|
|
62
|
+
return this._state.waypoints[waypointId];
|
|
63
|
+
}
|
|
64
|
+
recalculateRoute(opts = {}) {
|
|
65
|
+
var _a;
|
|
66
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
if (!this.map || this.waypoints.length < 2)
|
|
68
|
+
return;
|
|
69
|
+
if (!this.options.dataProvider) {
|
|
70
|
+
throw new Error('No data provider');
|
|
71
|
+
}
|
|
72
|
+
this.fire('calculationStarted', {
|
|
73
|
+
mode: this.state.mode,
|
|
74
|
+
waypoints: this.waypoints,
|
|
75
|
+
recalculateOptions: opts,
|
|
76
|
+
});
|
|
77
|
+
if (opts.dropPendingRequests) {
|
|
78
|
+
yield this.options.dataProvider.abortAllRequests();
|
|
79
|
+
}
|
|
80
|
+
let patchState = {};
|
|
81
|
+
if (!this._state.loading) {
|
|
82
|
+
patchState = Object.assign(Object.assign({}, patchState), { loading: true });
|
|
83
|
+
}
|
|
84
|
+
this._patchState(patchState);
|
|
85
|
+
if ('loading' in patchState) {
|
|
86
|
+
this.fire('loadingChanged', { loading: true });
|
|
87
|
+
}
|
|
88
|
+
try {
|
|
89
|
+
const data = (yield this.options.dataProvider.request(this._state.waypoints, {
|
|
90
|
+
mode: this.state.mode,
|
|
91
|
+
}));
|
|
92
|
+
let patchState = {
|
|
93
|
+
data,
|
|
94
|
+
selectedRouteId: data.selectedRouteId,
|
|
95
|
+
routesShapeGeojson: data.routesShapeGeojson,
|
|
96
|
+
};
|
|
97
|
+
let waypointsUpdated = false;
|
|
98
|
+
if (opts.syncWaypoints !== false && this.options.waypointsSyncStrategy === 'toPath') {
|
|
99
|
+
const syncedWaypoints = this.syncWaypointsPositions(data.routes[0].waypoints);
|
|
100
|
+
patchState = Object.assign(Object.assign({}, patchState), { waypoints: syncedWaypoints });
|
|
101
|
+
waypointsUpdated = true;
|
|
102
|
+
}
|
|
103
|
+
this._patchState(patchState);
|
|
104
|
+
this.fire('routesFound', {
|
|
105
|
+
mode: this.state.mode,
|
|
106
|
+
waypoints: this._state.waypoints,
|
|
107
|
+
data,
|
|
108
|
+
recalculateOptions: opts,
|
|
109
|
+
});
|
|
110
|
+
if (waypointsUpdated) {
|
|
111
|
+
this.fire('waypointsChanged', { waypoints: this.state.waypoints });
|
|
112
|
+
}
|
|
113
|
+
return this._state.data;
|
|
114
|
+
}
|
|
115
|
+
catch (e) {
|
|
116
|
+
this.fire('calculationError', { error: e, recalculateOptions: opts });
|
|
117
|
+
throw e;
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
if (this._state.loading && (((_a = this.data) === null || _a === void 0 ? void 0 : _a.latest) || !(yield this.dataProvider.hasPendingRequests()))) {
|
|
121
|
+
this._patchState({ loading: false });
|
|
122
|
+
this.fire('loadingChanged', { loading: false });
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
on(event, callback) {
|
|
128
|
+
this.dispatcher.on(event, callback);
|
|
129
|
+
}
|
|
130
|
+
off(event, callback) {
|
|
131
|
+
this.dispatcher.off(event, callback);
|
|
132
|
+
}
|
|
133
|
+
selectRoute(routeId) {
|
|
134
|
+
if (!this.data) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const features = this.data.routesShapeGeojson.features.map((feature) => {
|
|
138
|
+
return Object.assign(Object.assign({}, feature), { properties: Object.assign(Object.assign({}, feature.properties), { selected: feature.properties.routeId === routeId }) });
|
|
139
|
+
});
|
|
140
|
+
this._patchState({
|
|
141
|
+
selectedRouteId: routeId,
|
|
142
|
+
data: Object.assign(Object.assign({}, this._state.data), { routesShapeGeojson: featureCollection(features), selectedRouteId: routeId }),
|
|
143
|
+
routesShapeGeojson: featureCollection(features),
|
|
144
|
+
});
|
|
145
|
+
this.fire('routeSelected', {
|
|
146
|
+
route: this.data.routes[routeId],
|
|
147
|
+
routeId: routeId,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
reset() {
|
|
151
|
+
this._setState(Object.assign({}, this._initialState), 'external');
|
|
152
|
+
}
|
|
153
|
+
getUniqueName(name) {
|
|
154
|
+
return `${name}-${this.options.uniqueKey}`;
|
|
155
|
+
}
|
|
156
|
+
syncWaypointsPositions(waypoints) {
|
|
157
|
+
const newWaypoints = waypoints.map((waypoint, index) => (Object.assign(Object.assign({}, this._state.waypoints[index]), { position: this._state.waypoints[index].position, mappedPosition: waypoint, properties: this._state.waypoints[index].properties })));
|
|
158
|
+
return newWaypoints;
|
|
159
|
+
}
|
|
160
|
+
setState({ waypoints, data, routesShapeGeojson, selectedRouteId, }) {
|
|
161
|
+
let newState = Object.assign({}, this._state);
|
|
162
|
+
if (waypoints) {
|
|
163
|
+
const internalWaypoints = this.transformToInternalWaypoints(waypoints);
|
|
164
|
+
newState = Object.assign(Object.assign({}, newState), { waypoints: internalWaypoints });
|
|
165
|
+
}
|
|
166
|
+
if (routesShapeGeojson) {
|
|
167
|
+
newState = Object.assign(Object.assign({}, newState), { routesShapeGeojson });
|
|
168
|
+
}
|
|
169
|
+
if (data) {
|
|
170
|
+
newState = Object.assign(Object.assign({}, newState), { data, routesShapeGeojson: data.routesShapeGeojson });
|
|
171
|
+
}
|
|
172
|
+
if (selectedRouteId != null) {
|
|
173
|
+
newState = Object.assign(Object.assign({}, newState), { selectedRouteId });
|
|
174
|
+
}
|
|
175
|
+
if (data || waypoints || routesShapeGeojson || selectedRouteId != null) {
|
|
176
|
+
this._setState(newState, 'external');
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
initPlugins() {
|
|
180
|
+
this._plugins.forEach((plugin) => this.resolvePlugin(plugin).onAdd(this));
|
|
181
|
+
}
|
|
182
|
+
detachPlugins() {
|
|
183
|
+
this._plugins.forEach((plugin) => this.resolvePlugin(plugin).onRemove(this));
|
|
184
|
+
}
|
|
185
|
+
resolvePlugin(plugin) {
|
|
186
|
+
if (typeof plugin === 'function') {
|
|
187
|
+
return new plugin({});
|
|
188
|
+
}
|
|
189
|
+
return plugin;
|
|
190
|
+
}
|
|
191
|
+
_setState(newState, source = 'internal', updatedKeys) {
|
|
192
|
+
this._state = newState;
|
|
193
|
+
this.fire('stateUpdated', {
|
|
194
|
+
source,
|
|
195
|
+
updatedProperties: updatedKeys !== null && updatedKeys !== void 0 ? updatedKeys : Object.keys(this.state),
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
_patchState(patchState, source = 'internal') {
|
|
199
|
+
if (Object.keys(patchState).length === 0) {
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
this._setState(Object.assign(Object.assign({}, this._state), patchState), source, Object.keys(patchState));
|
|
203
|
+
}
|
|
204
|
+
transformToInternalWaypoints(waypoints) {
|
|
205
|
+
return waypoints.map((waypoint, index) => InternalWaypointC.fromWaypoint(waypoint, { index, isFirst: index === 0, isLast: index === waypoints.length - 1 }));
|
|
206
|
+
}
|
|
207
|
+
fire(event, data) {
|
|
208
|
+
//@ts-ignore
|
|
209
|
+
this.dispatcher.fire(event, Object.assign(Object.assign({}, data), { state: this.state, eventName: event }));
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
//# sourceMappingURL=libre-routing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,GAGlB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,OAAO,UAAU;IAkBrB,IAAW,GAAG;QACZ,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,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;;QA7CrB,eAAU,GAAG,IAAI,UAAU,EAAuB,CAAC;QAI5D,aAAQ,GAAoB,EAAE,CAAC;QAE/B,kBAAa,GAAuB;YAC1C,SAAS,EAAE,EAAE;YACb,IAAI,EAAE,SAAS;YACf,OAAO,EAAE,KAAK;YACd,eAAe,EAAE,SAAS;YAC1B,IAAI,EAAE,SAAS;YACf,kBAAkB,EAAE,SAAS;SAC9B,CAAC;QAEM,WAAM,qBAA4B,IAAI,CAAC,aAAa,EAAG;QA+B7D,IAAI,CA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S,EAAE,KAAK,GAAE,CAAC,CAAC;IACxG,CAAC;CACF"}
|
|
@@ -0,0 +1,103 @@
|
|
|
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 LoadingChangedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
36
|
+
loading: boolean;
|
|
37
|
+
};
|
|
38
|
+
export type StateUpdateSource = 'internal' | 'external';
|
|
39
|
+
export type StateUpdatedEvent<R extends AnyRoutingDataResponse = AnyRoutingDataResponse> = BaseEvent<R> & {
|
|
40
|
+
state: AnyRoutingState<R>;
|
|
41
|
+
source: StateUpdateSource;
|
|
42
|
+
updatedProperties: Array<keyof AnyRoutingState<R>>;
|
|
43
|
+
};
|
|
44
|
+
export interface AnyRoutingEventsMap {
|
|
45
|
+
calculationStarted: CalculationStartedEvent;
|
|
46
|
+
calculationError: CalculationErrorEvent;
|
|
47
|
+
routesFound: RoutesFoundEvent;
|
|
48
|
+
routeSelected: RouteSelectedEvent;
|
|
49
|
+
waypointsChanged: WaypointsChangedEvent;
|
|
50
|
+
loadingChanged: LoadingChangedEvent;
|
|
51
|
+
stateUpdated: StateUpdatedEvent;
|
|
52
|
+
}
|
|
53
|
+
export type AnyRoutingEvents = keyof AnyRoutingEventsMap;
|
|
54
|
+
export type InternalWaypointProperties = {
|
|
55
|
+
index: number;
|
|
56
|
+
isFirst: boolean;
|
|
57
|
+
isLast: boolean;
|
|
58
|
+
};
|
|
59
|
+
export type AnyRoutingState<DataType = AnyRoutingDataResponse> = {
|
|
60
|
+
data: DataType | undefined;
|
|
61
|
+
waypoints: InternalWaypoint[];
|
|
62
|
+
loading: boolean;
|
|
63
|
+
selectedRouteId: number | undefined | null;
|
|
64
|
+
mode: Mode;
|
|
65
|
+
routesShapeGeojson?: AnyRoutingDataResponse['routesShapeGeojson'];
|
|
66
|
+
};
|
|
67
|
+
export interface InternalWaypoint {
|
|
68
|
+
index: number;
|
|
69
|
+
position: WaypointPosition;
|
|
70
|
+
mappedPosition?: WaypointPosition;
|
|
71
|
+
originalPosition: WaypointPosition;
|
|
72
|
+
originalMappedPosition?: WaypointPosition;
|
|
73
|
+
properties: InternalWaypointProperties & Record<string, any>;
|
|
74
|
+
}
|
|
75
|
+
export declare function isWaypointPositionEqual(posA: WaypointPosition, posB: WaypointPosition): boolean;
|
|
76
|
+
export declare class InternalWaypointC {
|
|
77
|
+
static isChanged(waypoint: InternalWaypoint): boolean;
|
|
78
|
+
static isPositionChanged(waypoint: InternalWaypoint): boolean;
|
|
79
|
+
static isMappedPositionChanged(waypoint: InternalWaypoint): boolean;
|
|
80
|
+
static fromWaypoint(waypoint: Waypoint, props: InternalWaypointProperties): InternalWaypoint;
|
|
81
|
+
}
|
|
82
|
+
export interface Waypoint {
|
|
83
|
+
position: WaypointPosition;
|
|
84
|
+
mappedPosition?: WaypointPosition;
|
|
85
|
+
properties?: Record<string, string | boolean | number>;
|
|
86
|
+
}
|
|
87
|
+
export type PluginFactory = AnyRoutingPlugin | (new (...args: any[]) => AnyRoutingPlugin);
|
|
88
|
+
export type AnyRoutingOptions = {
|
|
89
|
+
dataProvider: AnyRoutingDataProvider;
|
|
90
|
+
plugins?: PluginFactory[];
|
|
91
|
+
uniqueKey?: string;
|
|
92
|
+
waypointsSyncStrategy: 'none' | 'toPath' | 'geocodeFirst';
|
|
93
|
+
};
|
|
94
|
+
export interface AnyRoutingPlugin {
|
|
95
|
+
onAdd(AnyRouting: AnyRouting<any, any>): void;
|
|
96
|
+
onRemove(AnyRouting: AnyRouting<any, any>): void;
|
|
97
|
+
}
|
|
98
|
+
export interface RecalculateOptions {
|
|
99
|
+
fitViewToData?: boolean;
|
|
100
|
+
clearMap?: boolean;
|
|
101
|
+
dropPendingRequests?: boolean;
|
|
102
|
+
syncWaypoints?: boolean;
|
|
103
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export function isWaypointPositionEqual(posA, posB) {
|
|
2
|
+
return posA.lat === posB.lat && posA.lng === posB.lng;
|
|
3
|
+
}
|
|
4
|
+
export class InternalWaypointC {
|
|
5
|
+
static isChanged(waypoint) {
|
|
6
|
+
return !this.isPositionChanged(waypoint) || !this.isMappedPositionChanged(waypoint);
|
|
7
|
+
}
|
|
8
|
+
static isPositionChanged(waypoint) {
|
|
9
|
+
return !isWaypointPositionEqual(waypoint.originalPosition, waypoint.position);
|
|
10
|
+
}
|
|
11
|
+
static isMappedPositionChanged(waypoint) {
|
|
12
|
+
return (!!waypoint.originalMappedPosition &&
|
|
13
|
+
!!waypoint.mappedPosition &&
|
|
14
|
+
!isWaypointPositionEqual(waypoint.originalMappedPosition, waypoint.mappedPosition));
|
|
15
|
+
}
|
|
16
|
+
static fromWaypoint(waypoint, props) {
|
|
17
|
+
return {
|
|
18
|
+
index: props.index,
|
|
19
|
+
originalPosition: waypoint.position,
|
|
20
|
+
position: waypoint.position,
|
|
21
|
+
originalMappedPosition: waypoint.mappedPosition,
|
|
22
|
+
mappedPosition: waypoint.mappedPosition,
|
|
23
|
+
properties: Object.assign(Object.assign({}, props), (waypoint.properties || {})),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=libre-routing.model.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"libre-routing.model.js","sourceRoot":"","sources":["../../../../../packages/core/src/lib/libre-routing.model.ts"],"names":[],"mappings":"AAyFA,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,SAAS,CAAC,QAA0B;QAChD,OAAO,CAAC,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,uBAAuB,CAAC,QAAQ,CAAC,CAAC;IACtF,CAAC;IAEM,MAAM,CAAC,iBAAiB,CAAC,QAA0B;QACxD,OAAO,CAAC,uBAAuB,CAAC,QAAQ,CAAC,gBAAgB,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAChF,CAAC;IAEM,MAAM,CAAC,uBAAuB,CAAC,QAA0B;QAC9D,OAAO,CACL,CAAC,CAAC,QAAQ,CAAC,sBAAsB;YACjC,CAAC,CAAC,QAAQ,CAAC,cAAc;YACzB,CAAC,uBAAuB,CAAC,QAAQ,CAAC,sBAAsB,EAAE,QAAQ,CAAC,cAAc,CAAC,CACnF,CAAC;IACJ,CAAC;IAEM,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,sBAAsB,EAAE,QAAQ,CAAC,cAAc;YAC/C,cAAc,EAAE,QAAQ,CAAC,cAAc;YACvC,UAAU,kCAAO,KAAK,GAAK,CAAC,QAAQ,CAAC,UAAU,IAAI,EAAE,CAAC,CAAE;SACzD,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare class Dispatcher<EventMap extends object> {
|
|
2
|
+
private callbacks;
|
|
3
|
+
fire<E extends keyof EventMap>(event: E, data: EventMap[E]): void;
|
|
4
|
+
on<E extends keyof EventMap>(event: E, callback: (event: EventMap[E]) => void): void;
|
|
5
|
+
off<E extends keyof EventMap>(event: E, callback: (event: EventMap[E]) => void): void;
|
|
6
|
+
private getEventCallbacks;
|
|
7
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export class Dispatcher {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.callbacks = {};
|
|
4
|
+
}
|
|
5
|
+
fire(event, data) {
|
|
6
|
+
this.getEventCallbacks(event).forEach((callback) => {
|
|
7
|
+
try {
|
|
8
|
+
callback(data);
|
|
9
|
+
}
|
|
10
|
+
catch (e) {
|
|
11
|
+
console.error(e);
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
on(event, callback) {
|
|
16
|
+
this.callbacks[event] = [...this.getEventCallbacks(event), callback];
|
|
17
|
+
}
|
|
18
|
+
off(event, callback) {
|
|
19
|
+
this.callbacks[event] = this.getEventCallbacks(event).filter((c) => c !== callback);
|
|
20
|
+
}
|
|
21
|
+
getEventCallbacks(event) {
|
|
22
|
+
return this.callbacks[event] || [];
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=dispatcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dispatcher.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/dispatcher.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,UAAU;IAAvB;QACU,cAAS,GAA2D,EAAE,CAAC;IAuBjF,CAAC;IArBQ,IAAI,CAA2B,KAAQ,EAAE,IAAiB;QAC/D,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YACjD,IAAI;gBACF,QAAQ,CAAC,IAAI,CAAC,CAAC;aAChB;YAAC,OAAO,CAAC,EAAE;gBACV,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;aAClB;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAEM,EAAE,CAA2B,KAAQ,EAAE,QAAsC;QAClF,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ,CAAC,CAAC;IACvE,CAAC;IAEM,GAAG,CAA2B,KAAQ,EAAE,QAAsC;QACnF,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC;IACtF,CAAC;IAEO,iBAAiB,CAA2B,KAAQ;QAC1D,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IACrC,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const randomId: () => string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"random.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/random.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,QAAQ,GAAG,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare class Requester {
|
|
2
|
+
private latestResponseId;
|
|
3
|
+
private lastResponseId;
|
|
4
|
+
private buffer;
|
|
5
|
+
private maxBuffer;
|
|
6
|
+
private pending;
|
|
7
|
+
get hasPendingRequests(): boolean;
|
|
8
|
+
request(url: any, params?: RequestInit): Promise<any>;
|
|
9
|
+
abortAllRequests(): void;
|
|
10
|
+
private cleanBuffer;
|
|
11
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { __awaiter } from "tslib";
|
|
2
|
+
export class Requester {
|
|
3
|
+
constructor() {
|
|
4
|
+
this.latestResponseId = 0;
|
|
5
|
+
this.lastResponseId = 0;
|
|
6
|
+
this.buffer = [];
|
|
7
|
+
this.maxBuffer = 4;
|
|
8
|
+
this.pending = false;
|
|
9
|
+
}
|
|
10
|
+
get hasPendingRequests() {
|
|
11
|
+
return this.pending;
|
|
12
|
+
}
|
|
13
|
+
request(url, params) {
|
|
14
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
+
const controller = new AbortController();
|
|
16
|
+
const executionId = Date.now();
|
|
17
|
+
this.lastResponseId = executionId;
|
|
18
|
+
this.pending = true;
|
|
19
|
+
if (this.buffer.length > this.maxBuffer) {
|
|
20
|
+
this.buffer[0].abort();
|
|
21
|
+
this.buffer.splice(0, 1);
|
|
22
|
+
}
|
|
23
|
+
this.buffer.push(controller);
|
|
24
|
+
const response = yield fetch(url, Object.assign(Object.assign({}, params), { signal: controller.signal }));
|
|
25
|
+
this.cleanBuffer(controller);
|
|
26
|
+
if (response.status !== 200) {
|
|
27
|
+
throw response;
|
|
28
|
+
}
|
|
29
|
+
if (this.latestResponseId > executionId) {
|
|
30
|
+
throw new Error('Prev response');
|
|
31
|
+
}
|
|
32
|
+
this.pending = this.lastResponseId !== executionId;
|
|
33
|
+
this.latestResponseId = executionId;
|
|
34
|
+
return yield response.json();
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
abortAllRequests() {
|
|
38
|
+
this.buffer.forEach((buff) => buff.abort());
|
|
39
|
+
}
|
|
40
|
+
cleanBuffer(controller) {
|
|
41
|
+
this.buffer = this.buffer.filter((ctrl) => ctrl !== controller);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=requester.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"requester.js","sourceRoot":"","sources":["../../../../../../packages/core/src/lib/utils/requester.ts"],"names":[],"mappings":";AAAA,MAAM,OAAO,SAAS;IAAtB;QACU,qBAAgB,GAAG,CAAC,CAAC;QACrB,mBAAc,GAAG,CAAC,CAAC;QACnB,WAAM,GAAsB,EAAE,CAAC;QAC/B,cAAS,GAAG,CAAC,CAAC;QACd,YAAO,GAAG,KAAK,CAAC;IAgD1B,CAAC;IA9CC,IAAW,kBAAkB;QAC3B,OAAO,IAAI,CAAC,OAAO,CAAC;IACtB,CAAC;IAEY,OAAO,CAAC,GAAG,EAAE,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