mobility-toolbox-js 2.0.0-beta.24 → 2.0.0-beta.27
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/api/{TralisAPI.js → RealtimeAPI.js} +16 -18
- package/api/{TralisAPI.test.js → RealtimeAPI.test.js} +11 -11
- package/api/index.js +1 -1
- package/common/mixins/{TralisLayerMixin.js → RealtimeLayerMixin.js} +9 -9
- package/common/mixins/{SearchMixin.js → StopFinderMixin.js} +3 -3
- package/common/styles/index.js +4 -4
- package/common/styles/{trackerDefaultStyle.js → realtimeDefaultStyle.js} +7 -7
- package/common/styles/realtimeDelayStyle.js +8 -0
- package/common/styles/{trackerSimpleStyle.js → realtimeSimpleStyle.js} +2 -2
- package/common/utils/cleanStopTime.js +19 -0
- package/{api/TralisAPIUtils.js → common/utils/compareDepartures.js} +2 -20
- package/common/utils/getRealtimeModeSuffix.js +2 -0
- package/mapbox/layers/{TralisLayer.js → RealtimeLayer.js} +6 -3
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +1 -1
- package/mbt.js +219 -209
- package/mbt.js.map +3 -3
- package/mbt.min.js +6 -6
- package/mbt.min.js.map +3 -3
- package/ol/controls/RoutingControl.js +2 -2
- package/ol/controls/StopFinderControl.js +1 -1
- package/ol/layers/{TralisLayer.js → RealtimeLayer.js} +4 -4
- package/ol/layers/{TralisLayer.test.js → RealtimeLayer.test.js} +9 -9
- package/ol/layers/index.js +1 -1
- package/package.json +1 -1
- package/common/styles/trackerDelayStyle.js +0 -8
- package/mapbox/layers/TralisLayer.test.js +0 -10
|
@@ -1,15 +1,13 @@
|
|
|
1
1
|
import WebSocketAPI from "../common/api/WebSocketAPI";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from "./TralisAPIUtils";
|
|
7
|
-
export const TralisModes = {
|
|
2
|
+
import cleanStopTime from "../common/utils/cleanStopTime";
|
|
3
|
+
import getModeSuffix from "../common/utils/getRealtimeModeSuffix";
|
|
4
|
+
import compareDepartures from "../common/utils/compareDepartures";
|
|
5
|
+
export const RealtimeModes = {
|
|
8
6
|
RAW: "raw",
|
|
9
7
|
TOPOGRAPHIC: "topographic",
|
|
10
8
|
SCHEMATIC: "schematic"
|
|
11
9
|
};
|
|
12
|
-
class
|
|
10
|
+
class RealtimeAPI {
|
|
13
11
|
constructor(options = {}) {
|
|
14
12
|
this.defineProperties(options);
|
|
15
13
|
this.subscribedStationUic = null;
|
|
@@ -126,8 +124,8 @@ class TralisAPI {
|
|
|
126
124
|
this.wsApi.subscribe({ channel }, onSuccess, onError, quiet);
|
|
127
125
|
}
|
|
128
126
|
unsubscribe(channel, suffix, cb) {
|
|
129
|
-
this.wsApi.unsubscribe(`${channel}${getModeSuffix(
|
|
130
|
-
this.wsApi.unsubscribe(`${channel}${getModeSuffix(
|
|
127
|
+
this.wsApi.unsubscribe(`${channel}${getModeSuffix(RealtimeModes.SCHEMATIC, RealtimeModes)}${suffix}`, cb);
|
|
128
|
+
this.wsApi.unsubscribe(`${channel}${getModeSuffix(RealtimeModes.TOPOGRAPHIC, RealtimeModes)}${suffix || ""}`, cb);
|
|
131
129
|
}
|
|
132
130
|
filterDepartures(depObject, sortByMinArrivalTime = false) {
|
|
133
131
|
const departures = Object.keys(depObject).map((k) => depObject[k]);
|
|
@@ -203,7 +201,7 @@ class TralisAPI {
|
|
|
203
201
|
}
|
|
204
202
|
getStation(uic, mode) {
|
|
205
203
|
const params = {
|
|
206
|
-
channel: `station${getModeSuffix(mode,
|
|
204
|
+
channel: `station${getModeSuffix(mode, RealtimeModes)}`,
|
|
207
205
|
args: uic
|
|
208
206
|
};
|
|
209
207
|
return new Promise((resolve, reject) => {
|
|
@@ -219,7 +217,7 @@ class TralisAPI {
|
|
|
219
217
|
getStations(mode) {
|
|
220
218
|
const stations = [];
|
|
221
219
|
const params = {
|
|
222
|
-
channel: `station${getModeSuffix(mode,
|
|
220
|
+
channel: `station${getModeSuffix(mode, RealtimeModes)}`
|
|
223
221
|
};
|
|
224
222
|
window.clearTimeout(this.stationUpdateTimeout);
|
|
225
223
|
return new Promise((resolve, reject) => {
|
|
@@ -238,7 +236,7 @@ class TralisAPI {
|
|
|
238
236
|
}
|
|
239
237
|
subscribeStations(mode, onMessage) {
|
|
240
238
|
this.unsubscribeStations();
|
|
241
|
-
this.subscribe(`station${getModeSuffix(mode,
|
|
239
|
+
this.subscribe(`station${getModeSuffix(mode, RealtimeModes)}`, (data) => {
|
|
242
240
|
if (data.content) {
|
|
243
241
|
onMessage(data.content);
|
|
244
242
|
}
|
|
@@ -267,24 +265,24 @@ class TralisAPI {
|
|
|
267
265
|
}
|
|
268
266
|
subscribeTrajectory(mode, onMessage, quiet = false) {
|
|
269
267
|
this.unsubscribeTrajectory(onMessage);
|
|
270
|
-
this.subscribe(`trajectory${getModeSuffix(mode,
|
|
268
|
+
this.subscribe(`trajectory${getModeSuffix(mode, RealtimeModes)}`, onMessage, null, quiet);
|
|
271
269
|
}
|
|
272
270
|
unsubscribeTrajectory(cb) {
|
|
273
271
|
this.unsubscribe(`trajectory`, "", cb);
|
|
274
272
|
}
|
|
275
273
|
subscribeDeletedVehicles(mode, onMessage, quiet = false) {
|
|
276
274
|
this.unsubscribeDeletedVehicles(onMessage);
|
|
277
|
-
this.subscribe(`deleted_vehicles${getModeSuffix(mode,
|
|
275
|
+
this.subscribe(`deleted_vehicles${getModeSuffix(mode, RealtimeModes)}`, onMessage, null, quiet);
|
|
278
276
|
}
|
|
279
277
|
unsubscribeDeletedVehicles(cb) {
|
|
280
278
|
this.unsubscribe("deleted_vehicles", "", cb);
|
|
281
279
|
}
|
|
282
280
|
getFullTrajectory(id, mode, generalizationLevel) {
|
|
283
|
-
const channel = [`full_trajectory${getModeSuffix(mode,
|
|
281
|
+
const channel = [`full_trajectory${getModeSuffix(mode, RealtimeModes)}`];
|
|
284
282
|
if (id) {
|
|
285
283
|
channel.push(id);
|
|
286
284
|
}
|
|
287
|
-
if ((!mode || mode ===
|
|
285
|
+
if ((!mode || mode === RealtimeModes.TOPOGRAPHIC) && generalizationLevel) {
|
|
288
286
|
channel.push(`gen${generalizationLevel}`);
|
|
289
287
|
}
|
|
290
288
|
const params = {
|
|
@@ -304,7 +302,7 @@ class TralisAPI {
|
|
|
304
302
|
}
|
|
305
303
|
subscribeFullTrajectory(id, mode) {
|
|
306
304
|
this.unsubscribeFullTrajectory(id);
|
|
307
|
-
this.subscribe(`full_trajectory${getModeSuffix(mode,
|
|
305
|
+
this.subscribe(`full_trajectory${getModeSuffix(mode, RealtimeModes)}_${id}`, (data) => {
|
|
308
306
|
console.log("subscribe full_trajectory", data);
|
|
309
307
|
}, (err) => {
|
|
310
308
|
console.log("subscribe full_trajectory error", err);
|
|
@@ -356,4 +354,4 @@ class TralisAPI {
|
|
|
356
354
|
this.unsubscribe("healthcheck");
|
|
357
355
|
}
|
|
358
356
|
}
|
|
359
|
-
export default
|
|
357
|
+
export default RealtimeAPI;
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
describe("
|
|
3
|
-
let
|
|
1
|
+
import { RealtimeAPI, RealtimeModes } from ".";
|
|
2
|
+
describe("RealtimeAPI", () => {
|
|
3
|
+
let api;
|
|
4
4
|
let get;
|
|
5
5
|
beforeEach(() => {
|
|
6
6
|
get = jest.fn((params, cb) => {
|
|
7
7
|
cb({ content: "content" });
|
|
8
8
|
});
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
api = new RealtimeAPI();
|
|
10
|
+
api.wsApi = {
|
|
11
11
|
get
|
|
12
12
|
};
|
|
13
13
|
});
|
|
14
14
|
describe("#getFullTrajectory() calls fullTrajectory channel", () => {
|
|
15
15
|
test("without parameters", (done) => {
|
|
16
|
-
|
|
16
|
+
api.getFullTrajectory().then(() => {
|
|
17
17
|
expect(get.mock.calls.length).toBe(1);
|
|
18
18
|
expect(get.mock.calls[0][0]).toEqual({
|
|
19
19
|
channel: "full_trajectory"
|
|
@@ -21,10 +21,10 @@ describe("TralisAPI", () => {
|
|
|
21
21
|
done();
|
|
22
22
|
});
|
|
23
23
|
});
|
|
24
|
-
[null,
|
|
24
|
+
[null, RealtimeModes.TOPOGRAPHIC].forEach((mode) => {
|
|
25
25
|
describe(`using mode ${mode}`, () => {
|
|
26
26
|
test("using id", (done) => {
|
|
27
|
-
|
|
27
|
+
api.getFullTrajectory("foo", mode).then(() => {
|
|
28
28
|
expect(get.mock.calls.length).toBe(1);
|
|
29
29
|
expect(get.mock.calls[0][0]).toEqual({
|
|
30
30
|
channel: "full_trajectory_foo"
|
|
@@ -33,7 +33,7 @@ describe("TralisAPI", () => {
|
|
|
33
33
|
});
|
|
34
34
|
});
|
|
35
35
|
test("using id and generalizationLevel param", (done) => {
|
|
36
|
-
|
|
36
|
+
api.getFullTrajectory("foo", mode, 5).then(() => {
|
|
37
37
|
expect(get.mock.calls.length).toBe(1);
|
|
38
38
|
expect(get.mock.calls[0][0]).toEqual({
|
|
39
39
|
channel: "full_trajectory_foo_gen5"
|
|
@@ -45,7 +45,7 @@ describe("TralisAPI", () => {
|
|
|
45
45
|
});
|
|
46
46
|
describe("using schematic mode ", () => {
|
|
47
47
|
test("using id", (done) => {
|
|
48
|
-
|
|
48
|
+
api.getFullTrajectory("foo", RealtimeModes.SCHEMATIC).then(() => {
|
|
49
49
|
expect(get.mock.calls.length).toBe(1);
|
|
50
50
|
expect(get.mock.calls[0][0]).toEqual({
|
|
51
51
|
channel: "full_trajectory_schematic_foo"
|
|
@@ -54,7 +54,7 @@ describe("TralisAPI", () => {
|
|
|
54
54
|
});
|
|
55
55
|
});
|
|
56
56
|
test("doesn't use generalizationLevel param", (done) => {
|
|
57
|
-
|
|
57
|
+
api.getFullTrajectory("foo", RealtimeModes.SCHEMATIC, 10).then(() => {
|
|
58
58
|
expect(get.mock.calls.length).toBe(1);
|
|
59
59
|
expect(get.mock.calls[0][0]).toEqual({
|
|
60
60
|
channel: "full_trajectory_schematic_foo"
|
package/api/index.js
CHANGED
|
@@ -4,11 +4,11 @@ import GeoJSON from "ol/format/GeoJSON";
|
|
|
4
4
|
import debounce from "lodash.debounce";
|
|
5
5
|
import throttle from "lodash.throttle";
|
|
6
6
|
import { fromLonLat } from "ol/proj";
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
7
|
+
import realtimeDefaultStyle from "../styles/realtimeDefaultStyle";
|
|
8
|
+
import { RealtimeAPI, RealtimeModes } from "../../api";
|
|
9
9
|
import renderTrajectories from "../utils/renderTrajectories";
|
|
10
10
|
import * as trackerConfig from "../utils/trackerConfig";
|
|
11
|
-
export class
|
|
11
|
+
export class RealtimeLayerInterface {
|
|
12
12
|
constructor(options = {}) {
|
|
13
13
|
}
|
|
14
14
|
attachToMap(map) {
|
|
@@ -26,15 +26,15 @@ export class TralisLayerInterface {
|
|
|
26
26
|
getTrajectoryInfos(id, mode) {
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const RealtimeLayerMixin = (Base) => class extends Base {
|
|
30
30
|
constructor(options = {}) {
|
|
31
31
|
super({
|
|
32
32
|
hitTolerance: 10,
|
|
33
33
|
...options
|
|
34
34
|
});
|
|
35
35
|
this.debug = options.debug;
|
|
36
|
-
this.mode = options.mode ||
|
|
37
|
-
this.api = options.api || new
|
|
36
|
+
this.mode = options.mode || RealtimeModes.TOPOGRAPHIC;
|
|
37
|
+
this.api = options.api || new RealtimeAPI(options);
|
|
38
38
|
this.tenant = options.tenant || "";
|
|
39
39
|
this.minZoomNonTrain = options.minZoomNonTrain || 9;
|
|
40
40
|
this.minZoomInterpolation = options.minZoomInterpolation || 8;
|
|
@@ -117,7 +117,7 @@ const TralisLayerMixin = (Base) => class extends Base {
|
|
|
117
117
|
value: canvas || document.createElement("canvas")
|
|
118
118
|
},
|
|
119
119
|
style: {
|
|
120
|
-
value: style ||
|
|
120
|
+
value: style || realtimeDefaultStyle
|
|
121
121
|
},
|
|
122
122
|
styleOptions: {
|
|
123
123
|
value: { ...trackerConfig, ...styleOptions || {} }
|
|
@@ -389,7 +389,7 @@ const TralisLayerMixin = (Base) => class extends Base {
|
|
|
389
389
|
if (this.purgeTrajectory(trajectory)) {
|
|
390
390
|
return;
|
|
391
391
|
}
|
|
392
|
-
if (this.debug && this.mode ===
|
|
392
|
+
if (this.debug && this.mode === RealtimeModes.TOPOGRAPHIC && rawCoordinates) {
|
|
393
393
|
trajectory.properties.olGeometry = {
|
|
394
394
|
type: "Point",
|
|
395
395
|
coordinates: fromLonLat(rawCoordinates, this.map.getView().getProjection())
|
|
@@ -430,4 +430,4 @@ const TralisLayerMixin = (Base) => class extends Base {
|
|
|
430
430
|
}
|
|
431
431
|
}
|
|
432
432
|
};
|
|
433
|
-
export default
|
|
433
|
+
export default RealtimeLayerMixin;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { StopsAPI } from "../../api";
|
|
2
|
-
export class
|
|
2
|
+
export class StopFinderInterface {
|
|
3
3
|
constructor(options = {}) {
|
|
4
4
|
}
|
|
5
5
|
search(query, abortController) {
|
|
6
6
|
}
|
|
7
7
|
}
|
|
8
|
-
const
|
|
8
|
+
const StopFinderMixin = (Base) => class extends Base {
|
|
9
9
|
constructor(options = {}) {
|
|
10
10
|
super(options);
|
|
11
11
|
const { apiParams, apiKey, url } = options;
|
|
@@ -107,4 +107,4 @@ const SearchMixin = (Base) => class extends Base {
|
|
|
107
107
|
this.clearElt.style.display = "none";
|
|
108
108
|
}
|
|
109
109
|
};
|
|
110
|
-
export default
|
|
110
|
+
export default StopFinderMixin;
|
package/common/styles/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { default as
|
|
2
|
-
export { default as
|
|
3
|
-
export { default as
|
|
4
|
-
export * from "./
|
|
1
|
+
export { default as realtimeDefaultStyle } from "./realtimeDefaultStyle";
|
|
2
|
+
export { default as realtimeDelayStyle } from "./realtimeDelayStyle";
|
|
3
|
+
export { default as realtimeSimpleStyle } from "./realtimeSimpleStyle";
|
|
4
|
+
export * from "./realtimeDefaultStyle";
|
|
@@ -91,8 +91,8 @@ export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, ha
|
|
|
91
91
|
}
|
|
92
92
|
return cacheText[key];
|
|
93
93
|
};
|
|
94
|
-
const
|
|
95
|
-
const
|
|
94
|
+
const cache = {};
|
|
95
|
+
const realtimeDefaultStyle = (trajectory, viewState, options) => {
|
|
96
96
|
const {
|
|
97
97
|
hoverVehicleId,
|
|
98
98
|
selectedVehicleId,
|
|
@@ -150,9 +150,9 @@ const style = (trajectory, viewState, options) => {
|
|
|
150
150
|
if (mustDrawText) {
|
|
151
151
|
key += `${name}${textColor}`;
|
|
152
152
|
}
|
|
153
|
-
if (!
|
|
153
|
+
if (!cache[key]) {
|
|
154
154
|
if (radius === 0) {
|
|
155
|
-
|
|
155
|
+
cache[key] = null;
|
|
156
156
|
return null;
|
|
157
157
|
}
|
|
158
158
|
const margin = 1 * pixelRatio;
|
|
@@ -194,9 +194,9 @@ const style = (trajectory, viewState, options) => {
|
|
|
194
194
|
const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
|
|
195
195
|
ctx.drawImage(text, 0, 0);
|
|
196
196
|
}
|
|
197
|
-
|
|
197
|
+
cache[key] = canvas;
|
|
198
198
|
}
|
|
199
199
|
}
|
|
200
|
-
return
|
|
200
|
+
return cache[key];
|
|
201
201
|
};
|
|
202
|
-
export default
|
|
202
|
+
export default realtimeDefaultStyle;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
let canvas;
|
|
2
|
-
const
|
|
2
|
+
const realtimeSimpleStyle = () => {
|
|
3
3
|
if (!canvas) {
|
|
4
4
|
document.createElement("canvas");
|
|
5
5
|
canvas.width = 15;
|
|
@@ -15,4 +15,4 @@ const style = () => {
|
|
|
15
15
|
}
|
|
16
16
|
return canvas;
|
|
17
17
|
};
|
|
18
|
-
export default
|
|
18
|
+
export default realtimeSimpleStyle;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const cleanStopTime = (content) => {
|
|
2
|
+
if (!content) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
content.stations.forEach((station) => {
|
|
6
|
+
station.arrivalTimeWithDelay = station.arrivalTime;
|
|
7
|
+
if (station.departureTime) {
|
|
8
|
+
station.departureTimeWithDelay = station.departureTime;
|
|
9
|
+
}
|
|
10
|
+
if (station.arrivalDelay) {
|
|
11
|
+
station.arrivalTime -= station.arrivalDelay;
|
|
12
|
+
if (station.departureTime) {
|
|
13
|
+
station.departureTime -= station.arrivalDelay;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
return content;
|
|
18
|
+
};
|
|
19
|
+
export default cleanStopTime;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
export const compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
1
|
+
const compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
3
2
|
const topStates = ["HIDDEN", "LEAVING", "BOARDING"];
|
|
4
3
|
const aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
|
|
5
4
|
const bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
|
|
@@ -23,21 +22,4 @@ export const compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
|
23
22
|
}
|
|
24
23
|
return aDuration - bDuration;
|
|
25
24
|
};
|
|
26
|
-
export
|
|
27
|
-
if (!content) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
content.stations.forEach((station) => {
|
|
31
|
-
station.arrivalTimeWithDelay = station.arrivalTime;
|
|
32
|
-
if (station.departureTime) {
|
|
33
|
-
station.departureTimeWithDelay = station.departureTime;
|
|
34
|
-
}
|
|
35
|
-
if (station.arrivalDelay) {
|
|
36
|
-
station.arrivalTime -= station.arrivalDelay;
|
|
37
|
-
if (station.departureTime) {
|
|
38
|
-
station.departureTime -= station.arrivalDelay;
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
return content;
|
|
43
|
-
};
|
|
25
|
+
export default compareDepartures;
|
|
@@ -3,10 +3,10 @@ import { unByKey } from "ol/Observable";
|
|
|
3
3
|
import { getWidth, getHeight } from "ol/extent";
|
|
4
4
|
import transformRotate from "@turf/transform-rotate";
|
|
5
5
|
import { point } from "@turf/helpers";
|
|
6
|
-
import mixin from "../../common/mixins/
|
|
6
|
+
import mixin from "../../common/mixins/RealtimeLayerMixin";
|
|
7
7
|
import Layer from "./Layer";
|
|
8
8
|
import { getSourceCoordinates, getMercatorResolution } from "../utils";
|
|
9
|
-
class
|
|
9
|
+
class RealtimeLayer extends mixin(Layer) {
|
|
10
10
|
constructor(options = {}) {
|
|
11
11
|
super({
|
|
12
12
|
...options
|
|
@@ -97,6 +97,9 @@ class TralisLayer extends mixin(Layer) {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
renderTrajectories(noInterpolate) {
|
|
100
|
+
if (!this.map) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
100
103
|
const { width, height } = this.map.getCanvas();
|
|
101
104
|
const center = this.map.getCenter();
|
|
102
105
|
const leftBottom = this.map.unproject({
|
|
@@ -173,4 +176,4 @@ class TralisLayer extends mixin(Layer) {
|
|
|
173
176
|
this.map.getCanvasContainer().style.cursor = features.length ? "pointer" : "auto";
|
|
174
177
|
}
|
|
175
178
|
}
|
|
176
|
-
export default
|
|
179
|
+
export default RealtimeLayer;
|
package/mapbox/layers/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { default as Layer } from "./Layer";
|
|
2
|
-
export { default as
|
|
2
|
+
export { default as RealtimeLayer } from "./RealtimeLayer";
|