mobility-toolbox-js 3.0.1-beta.7 → 3.0.1-beta.8
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/mbt.js +62 -49
- package/mbt.js.map +2 -2
- package/mbt.min.js +1 -1
- package/mbt.min.js.map +3 -3
- package/ol/layers/RealtimeLayer.d.ts +21 -6
- package/ol/layers/RealtimeLayer.js +70 -38
- package/package.json +8 -8
|
@@ -7,11 +7,10 @@ import VectorLayer from 'ol/layer/Vector';
|
|
|
7
7
|
import { ObjectEvent } from 'ol/Object';
|
|
8
8
|
import { Vector as VectorSource } from 'ol/source';
|
|
9
9
|
import { State } from 'ol/View';
|
|
10
|
-
import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
|
|
11
10
|
import { FilterFunction, SortFunction } from '../../common/typedefs';
|
|
12
11
|
import RealtimeEngine, { RealtimeEngineOptions } from '../../common/utils/RealtimeEngine';
|
|
13
12
|
import { RealtimeAPI } from '../../maplibre';
|
|
14
|
-
import {
|
|
13
|
+
import { RealtimeMode, RealtimeRenderState, RealtimeStopSequence, RealtimeTrainId, ViewState } from '../../types';
|
|
15
14
|
import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
|
|
16
15
|
export type RealtimeLayerOptions = {
|
|
17
16
|
allowRenderWhenAnimating?: boolean;
|
|
@@ -91,14 +90,30 @@ declare class RealtimeLayer extends Layer {
|
|
|
91
90
|
*/
|
|
92
91
|
detachFromMap(): void;
|
|
93
92
|
/**
|
|
94
|
-
* Get
|
|
93
|
+
* Get the full trajectory of a vehicle as features.
|
|
94
|
+
*
|
|
95
|
+
* @param {string} id A vehicle's id.
|
|
96
|
+
* @returns {Promise<Feature[]>} A list of features representing a full trajectory.
|
|
97
|
+
* @public
|
|
98
|
+
*/
|
|
99
|
+
getFullTrajectory(id: RealtimeTrainId): Promise<Feature[]>;
|
|
100
|
+
/**
|
|
101
|
+
* Get the stop sequences of a vehicle.
|
|
102
|
+
*
|
|
103
|
+
* @param {string} id A vehicle's id.
|
|
104
|
+
* @returns {Promise<RealtimeStopSequence[]>} An array of stop sequences.
|
|
105
|
+
* @public
|
|
106
|
+
*/
|
|
107
|
+
getStopSequences(id: RealtimeTrainId): Promise<RealtimeStopSequence[]>;
|
|
108
|
+
/**
|
|
109
|
+
* Get full trajectory and stop sequences of a vehicle.
|
|
95
110
|
*
|
|
96
111
|
* @param {RealtimeTrainId} id A vehicle's id.
|
|
97
|
-
* @returns
|
|
112
|
+
* @returns {Promise<{fullTrajectory: Feature[], stopSequences: RealtimeStopSequence[]}>} An object containing the full trajectory and the stop sequences.
|
|
98
113
|
*/
|
|
99
114
|
getTrajectoryInfos(id: RealtimeTrainId): Promise<{
|
|
100
|
-
fullTrajectory:
|
|
101
|
-
|
|
115
|
+
fullTrajectory: Feature[];
|
|
116
|
+
stopSequences: RealtimeStopSequence[];
|
|
102
117
|
}>;
|
|
103
118
|
getVehicles(filterFunc: FilterFunction): import("../../types").RealtimeTrajectory[];
|
|
104
119
|
getViewState(): {
|
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
1
10
|
import debounce from 'lodash.debounce';
|
|
2
11
|
import GeoJSON from 'ol/format/GeoJSON';
|
|
3
12
|
import Layer from 'ol/layer/Layer';
|
|
@@ -112,7 +121,6 @@ class RealtimeLayer extends Layer {
|
|
|
112
121
|
this.onMoveEndDebounced = debounce(this.onMoveEnd, 100);
|
|
113
122
|
}
|
|
114
123
|
attachToMap() {
|
|
115
|
-
var _a;
|
|
116
124
|
this.engine.attachToMap();
|
|
117
125
|
const mapInternal = this.getMapInternal();
|
|
118
126
|
if (mapInternal) {
|
|
@@ -120,11 +128,6 @@ class RealtimeLayer extends Layer {
|
|
|
120
128
|
if (this.getVisible()) {
|
|
121
129
|
this.engine.start();
|
|
122
130
|
}
|
|
123
|
-
const index = mapInternal.getLayers().getArray().indexOf(this);
|
|
124
|
-
if (this.vectorLayer.getMapInternal() === mapInternal) {
|
|
125
|
-
(_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
|
|
126
|
-
}
|
|
127
|
-
mapInternal.getLayers().insertAt(index, this.vectorLayer);
|
|
128
131
|
this.olEventsKeys.push(...mapInternal.on(['moveend', 'change:target'],
|
|
129
132
|
// @ts-expect-error - bad ol definitions
|
|
130
133
|
(evt) => {
|
|
@@ -177,25 +180,51 @@ class RealtimeLayer extends Layer {
|
|
|
177
180
|
this.engine.detachFromMap();
|
|
178
181
|
}
|
|
179
182
|
/**
|
|
180
|
-
* Get
|
|
183
|
+
* Get the full trajectory of a vehicle as features.
|
|
184
|
+
*
|
|
185
|
+
* @param {string} id A vehicle's id.
|
|
186
|
+
* @returns {Promise<Feature[]>} A list of features representing a full trajectory.
|
|
187
|
+
* @public
|
|
188
|
+
*/
|
|
189
|
+
getFullTrajectory(id) {
|
|
190
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
191
|
+
var _a, _b, _c, _d;
|
|
192
|
+
const data = yield this.engine.api.getFullTrajectory(id, this.engine.mode, this.engine.getGeneralizationLevelByZoom(Math.floor(((_b = (_a = this.getMapInternal()) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.getZoom()) || 0)));
|
|
193
|
+
if ((_d = (_c = data === null || data === void 0 ? void 0 : data.content) === null || _c === void 0 ? void 0 : _c.features) === null || _d === void 0 ? void 0 : _d.length) {
|
|
194
|
+
return format.readFeatures(data === null || data === void 0 ? void 0 : data.content);
|
|
195
|
+
}
|
|
196
|
+
return [];
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Get the stop sequences of a vehicle.
|
|
201
|
+
*
|
|
202
|
+
* @param {string} id A vehicle's id.
|
|
203
|
+
* @returns {Promise<RealtimeStopSequence[]>} An array of stop sequences.
|
|
204
|
+
* @public
|
|
205
|
+
*/
|
|
206
|
+
getStopSequences(id) {
|
|
207
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
208
|
+
const data = yield this.engine.api.getStopSequence(id);
|
|
209
|
+
return data === null || data === void 0 ? void 0 : data.content;
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
/**
|
|
213
|
+
* Get full trajectory and stop sequences of a vehicle.
|
|
181
214
|
*
|
|
182
215
|
* @param {RealtimeTrainId} id A vehicle's id.
|
|
183
|
-
* @returns
|
|
216
|
+
* @returns {Promise<{fullTrajectory: Feature[], stopSequences: RealtimeStopSequence[]}>} An object containing the full trajectory and the stop sequences.
|
|
184
217
|
*/
|
|
185
218
|
getTrajectoryInfos(id) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const response = {
|
|
195
|
-
fullTrajectory,
|
|
196
|
-
stopSequence,
|
|
219
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
220
|
+
// When a vehicle is selected, we request the complete stop sequence and the complete full trajectory.
|
|
221
|
+
// Then we combine them in one response.
|
|
222
|
+
const promises = [this.getStopSequences(id), this.getFullTrajectory(id)];
|
|
223
|
+
const [stopSequences, fullTrajectory] = yield Promise.all(promises);
|
|
224
|
+
return {
|
|
225
|
+
fullTrajectory: fullTrajectory,
|
|
226
|
+
stopSequences: stopSequences,
|
|
197
227
|
};
|
|
198
|
-
return response;
|
|
199
228
|
});
|
|
200
229
|
}
|
|
201
230
|
getVehicles(filterFunc) {
|
|
@@ -229,30 +258,33 @@ class RealtimeLayer extends Layer {
|
|
|
229
258
|
* Highlight the trajectory of journey.
|
|
230
259
|
*/
|
|
231
260
|
highlightTrajectory(id) {
|
|
232
|
-
|
|
233
|
-
|
|
261
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
262
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
234
263
|
(_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
.
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
243
|
-
return [];
|
|
264
|
+
(_c = this.vectorLayer.getMapInternal()) === null || _c === void 0 ? void 0 : _c.removeLayer(this.vectorLayer);
|
|
265
|
+
if (!id) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const features = yield this.getFullTrajectory(id);
|
|
269
|
+
if (!(features === null || features === void 0 ? void 0 : features.length)) {
|
|
270
|
+
return;
|
|
244
271
|
}
|
|
245
|
-
const features = format.readFeatures(fullTrajectory);
|
|
246
|
-
(_c = (_b = this.vectorLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear(true);
|
|
247
272
|
if (features.length) {
|
|
248
273
|
(_e = (_d = this.vectorLayer) === null || _d === void 0 ? void 0 : _d.getSource()) === null || _e === void 0 ? void 0 : _e.addFeatures(features);
|
|
249
274
|
}
|
|
275
|
+
// Add the vector layer to the map
|
|
276
|
+
const zIndex = this.getZIndex();
|
|
277
|
+
if (zIndex !== undefined) {
|
|
278
|
+
this.vectorLayer.setZIndex(zIndex - 1);
|
|
279
|
+
(_f = this.getMapInternal()) === null || _f === void 0 ? void 0 : _f.addLayer(this.vectorLayer);
|
|
280
|
+
}
|
|
281
|
+
else {
|
|
282
|
+
const index = ((_g = this.getMapInternal()) === null || _g === void 0 ? void 0 : _g.getLayers().getArray().indexOf(this)) || 0;
|
|
283
|
+
if (index) {
|
|
284
|
+
(_h = this.getMapInternal()) === null || _h === void 0 ? void 0 : _h.getLayers().insertAt(index, this.vectorLayer);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
250
287
|
return features;
|
|
251
|
-
})
|
|
252
|
-
.catch(() => {
|
|
253
|
-
var _a, _b;
|
|
254
|
-
(_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
|
|
255
|
-
return [];
|
|
256
288
|
});
|
|
257
289
|
}
|
|
258
290
|
onMoveEnd() {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "mobility-toolbox-js",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"description": "Toolbox for JavaScript applications in the domains of mobility and logistics.",
|
|
5
|
-
"version": "3.0.1-beta.
|
|
5
|
+
"version": "3.0.1-beta.8",
|
|
6
6
|
"homepage": "https://mobility-toolbox-js.geops.io/",
|
|
7
7
|
"exports": {
|
|
8
8
|
".": "./index.js",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@commitlint/cli": "19.6.0",
|
|
30
30
|
"@commitlint/config-conventional": "19.6.0",
|
|
31
31
|
"@geops/eslint-config-react": "^1.3.2",
|
|
32
|
-
"@types/geojson": "7946.0.
|
|
32
|
+
"@types/geojson": "7946.0.15",
|
|
33
33
|
"@types/lodash": "^4.17.13",
|
|
34
34
|
"@types/lodash.debounce": "4.0.9",
|
|
35
35
|
"@types/lodash.throttle": "4.1.9",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"@types/offscreencanvas": "2019.7.3",
|
|
38
38
|
"@types/topojson": "3.2.6",
|
|
39
39
|
"@types/uuid": "10.0.0",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "8.
|
|
41
|
-
"@typescript-eslint/parser": "8.
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "8.18.0",
|
|
41
|
+
"@typescript-eslint/parser": "8.18.0",
|
|
42
42
|
"cypress": "13.16.1",
|
|
43
43
|
"esbuild": "0.24.0",
|
|
44
44
|
"esdoc": "1.1.0",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"eslint-plugin-react": "7.37.2",
|
|
58
58
|
"fixpack": "4.0.0",
|
|
59
59
|
"husky": "9.1.7",
|
|
60
|
-
"is-ci": "
|
|
60
|
+
"is-ci": "4.1.0",
|
|
61
61
|
"jest": "29.7.0",
|
|
62
62
|
"jest-canvas-mock": "2.5.2",
|
|
63
63
|
"jest-environment-jsdom": "29.7.0",
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"jest-serializer-html": "7.1.0",
|
|
66
66
|
"jest-transformer-svg": "2.0.2",
|
|
67
67
|
"jest-websocket-mock": "2.5.0",
|
|
68
|
-
"lint-staged": "15.2.
|
|
68
|
+
"lint-staged": "15.2.11",
|
|
69
69
|
"maplibre-gl": "4.7.1",
|
|
70
70
|
"mock-socket": "9.3.1",
|
|
71
71
|
"next": "15.0.3",
|
|
@@ -76,14 +76,14 @@
|
|
|
76
76
|
"raw-loader": "4.0.2",
|
|
77
77
|
"sort-json": "2.0.1",
|
|
78
78
|
"standard-version": "9.5.0",
|
|
79
|
-
"start-server-and-test": "2.0.
|
|
79
|
+
"start-server-and-test": "2.0.9",
|
|
80
80
|
"stylelint": "16.11.0",
|
|
81
81
|
"stylelint-config-recommended-scss": "14.1.0",
|
|
82
82
|
"stylelint-config-standard": "36.0.1",
|
|
83
83
|
"stylelint-scss": "6.10.0",
|
|
84
84
|
"ts-jest": "^29.2.5",
|
|
85
85
|
"typescript": "5.7.2",
|
|
86
|
-
"vite": "^6.0.
|
|
86
|
+
"vite": "^6.0.3"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"apidoc": "esdoc && cp apidoc/index.json doc/src/components/Esdoc",
|