mobility-toolbox-js 3.0.1-beta.7 → 3.0.1-beta.9
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 +70 -48
- 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 +22 -6
- package/ol/layers/RealtimeLayer.js +83 -40
- 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;
|
|
@@ -77,6 +76,7 @@ declare class RealtimeLayer extends Layer {
|
|
|
77
76
|
*/
|
|
78
77
|
constructor(options: RealtimeLayerOptions);
|
|
79
78
|
attachToMap(): void;
|
|
79
|
+
cleanVectorLayer(): void;
|
|
80
80
|
/**
|
|
81
81
|
* Create a copy of the RealtimeLayer.
|
|
82
82
|
*
|
|
@@ -91,14 +91,30 @@ declare class RealtimeLayer extends Layer {
|
|
|
91
91
|
*/
|
|
92
92
|
detachFromMap(): void;
|
|
93
93
|
/**
|
|
94
|
-
* Get
|
|
94
|
+
* Get the full trajectory of a vehicle as features.
|
|
95
|
+
*
|
|
96
|
+
* @param {string} id A vehicle's id.
|
|
97
|
+
* @returns {Promise<Feature[]>} A list of features representing a full trajectory.
|
|
98
|
+
* @public
|
|
99
|
+
*/
|
|
100
|
+
getFullTrajectory(id: RealtimeTrainId): Promise<Feature[]>;
|
|
101
|
+
/**
|
|
102
|
+
* Get the stop sequences of a vehicle.
|
|
103
|
+
*
|
|
104
|
+
* @param {string} id A vehicle's id.
|
|
105
|
+
* @returns {Promise<RealtimeStopSequence[]>} An array of stop sequences.
|
|
106
|
+
* @public
|
|
107
|
+
*/
|
|
108
|
+
getStopSequences(id: RealtimeTrainId): Promise<RealtimeStopSequence[]>;
|
|
109
|
+
/**
|
|
110
|
+
* Get full trajectory and stop sequences of a vehicle.
|
|
95
111
|
*
|
|
96
112
|
* @param {RealtimeTrainId} id A vehicle's id.
|
|
97
|
-
* @returns
|
|
113
|
+
* @returns {Promise<{fullTrajectory: Feature[], stopSequences: RealtimeStopSequence[]}>} An object containing the full trajectory and the stop sequences.
|
|
98
114
|
*/
|
|
99
115
|
getTrajectoryInfos(id: RealtimeTrainId): Promise<{
|
|
100
|
-
fullTrajectory:
|
|
101
|
-
|
|
116
|
+
fullTrajectory: Feature[];
|
|
117
|
+
stopSequences: RealtimeStopSequence[];
|
|
102
118
|
}>;
|
|
103
119
|
getVehicles(filterFunc: FilterFunction): import("../../types").RealtimeTrajectory[];
|
|
104
120
|
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) => {
|
|
@@ -154,6 +157,11 @@ class RealtimeLayer extends Layer {
|
|
|
154
157
|
}));
|
|
155
158
|
}
|
|
156
159
|
}
|
|
160
|
+
cleanVectorLayer() {
|
|
161
|
+
var _a, _b, _c;
|
|
162
|
+
(_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
|
|
163
|
+
(_c = this.vectorLayer.getMapInternal()) === null || _c === void 0 ? void 0 : _c.removeLayer(this.vectorLayer);
|
|
164
|
+
}
|
|
157
165
|
/**
|
|
158
166
|
* Create a copy of the RealtimeLayer.
|
|
159
167
|
*
|
|
@@ -177,25 +185,51 @@ class RealtimeLayer extends Layer {
|
|
|
177
185
|
this.engine.detachFromMap();
|
|
178
186
|
}
|
|
179
187
|
/**
|
|
180
|
-
* Get
|
|
188
|
+
* Get the full trajectory of a vehicle as features.
|
|
189
|
+
*
|
|
190
|
+
* @param {string} id A vehicle's id.
|
|
191
|
+
* @returns {Promise<Feature[]>} A list of features representing a full trajectory.
|
|
192
|
+
* @public
|
|
193
|
+
*/
|
|
194
|
+
getFullTrajectory(id) {
|
|
195
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
196
|
+
var _a, _b, _c, _d;
|
|
197
|
+
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)));
|
|
198
|
+
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) {
|
|
199
|
+
return format.readFeatures(data === null || data === void 0 ? void 0 : data.content);
|
|
200
|
+
}
|
|
201
|
+
return [];
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Get the stop sequences of a vehicle.
|
|
206
|
+
*
|
|
207
|
+
* @param {string} id A vehicle's id.
|
|
208
|
+
* @returns {Promise<RealtimeStopSequence[]>} An array of stop sequences.
|
|
209
|
+
* @public
|
|
210
|
+
*/
|
|
211
|
+
getStopSequences(id) {
|
|
212
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
213
|
+
const data = yield this.engine.api.getStopSequence(id);
|
|
214
|
+
return data === null || data === void 0 ? void 0 : data.content;
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Get full trajectory and stop sequences of a vehicle.
|
|
181
219
|
*
|
|
182
220
|
* @param {RealtimeTrainId} id A vehicle's id.
|
|
183
|
-
* @returns
|
|
221
|
+
* @returns {Promise<{fullTrajectory: Feature[], stopSequences: RealtimeStopSequence[]}>} An object containing the full trajectory and the stop sequences.
|
|
184
222
|
*/
|
|
185
223
|
getTrajectoryInfos(id) {
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const response = {
|
|
195
|
-
fullTrajectory,
|
|
196
|
-
stopSequence,
|
|
224
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
+
// When a vehicle is selected, we request the complete stop sequence and the complete full trajectory.
|
|
226
|
+
// Then we combine them in one response.
|
|
227
|
+
const promises = [this.getStopSequences(id), this.getFullTrajectory(id)];
|
|
228
|
+
const [stopSequences, fullTrajectory] = yield Promise.all(promises);
|
|
229
|
+
return {
|
|
230
|
+
fullTrajectory: fullTrajectory,
|
|
231
|
+
stopSequences: stopSequences,
|
|
197
232
|
};
|
|
198
|
-
return response;
|
|
199
233
|
});
|
|
200
234
|
}
|
|
201
235
|
getVehicles(filterFunc) {
|
|
@@ -229,30 +263,39 @@ class RealtimeLayer extends Layer {
|
|
|
229
263
|
* Highlight the trajectory of journey.
|
|
230
264
|
*/
|
|
231
265
|
highlightTrajectory(id) {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
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 [];
|
|
266
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
267
|
+
var _a, _b, _c, _d, _e, _f;
|
|
268
|
+
if (!id) {
|
|
269
|
+
this.cleanVectorLayer();
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const features = yield this.getFullTrajectory(id);
|
|
273
|
+
if (!(features === null || features === void 0 ? void 0 : features.length)) {
|
|
274
|
+
this.cleanVectorLayer();
|
|
275
|
+
return;
|
|
244
276
|
}
|
|
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
277
|
if (features.length) {
|
|
248
|
-
(
|
|
278
|
+
(_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.addFeatures(features);
|
|
279
|
+
}
|
|
280
|
+
if (this.vectorLayer.getMapInternal() &&
|
|
281
|
+
this.vectorLayer.getMapInternal() !== this.getMapInternal()) {
|
|
282
|
+
(_c = this.vectorLayer.getMapInternal()) === null || _c === void 0 ? void 0 : _c.removeLayer(this.vectorLayer);
|
|
283
|
+
}
|
|
284
|
+
// Add the vector layer to the map
|
|
285
|
+
const zIndex = this.getZIndex();
|
|
286
|
+
if (zIndex !== undefined) {
|
|
287
|
+
this.vectorLayer.setZIndex(zIndex - 1);
|
|
288
|
+
if (!this.vectorLayer.getMapInternal()) {
|
|
289
|
+
(_d = this.getMapInternal()) === null || _d === void 0 ? void 0 : _d.addLayer(this.vectorLayer);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
else if (!this.vectorLayer.getMapInternal()) {
|
|
293
|
+
const index = ((_e = this.getMapInternal()) === null || _e === void 0 ? void 0 : _e.getLayers().getArray().indexOf(this)) || 0;
|
|
294
|
+
if (index) {
|
|
295
|
+
(_f = this.getMapInternal()) === null || _f === void 0 ? void 0 : _f.getLayers().insertAt(index, this.vectorLayer);
|
|
296
|
+
}
|
|
249
297
|
}
|
|
250
298
|
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
299
|
});
|
|
257
300
|
}
|
|
258
301
|
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.9",
|
|
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",
|