mobility-toolbox-js 1.5.0-beta.4 → 1.6.0-beta.3
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/tralis/TralisAPI.js +14 -4
- package/api/tralis/WebSocketConnector.js +25 -23
- package/common/mixins/TrackerLayerMixin.js +19 -3
- package/common/mixins/TralisLayerMixin.js +2 -11
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/mapbox/layers/TrackerLayer.js +8 -4
- package/mapbox/layers/TralisLayer.js +18 -34
- package/ol/layers/TrackerLayer.js +54 -1
- package/ol/layers/TrajservLayer.test.js +2 -3
- package/ol/layers/TralisLayer.js +15 -13
- package/package.json +1 -1
package/api/tralis/TralisAPI.js
CHANGED
|
@@ -75,12 +75,17 @@ class TralisAPI {
|
|
|
75
75
|
/** @ignore */
|
|
76
76
|
this.prefix = options.prefix || '';
|
|
77
77
|
|
|
78
|
+
this.isUpdateBboxOnMoveEnd = options.isUpateBboxOnMoveEnd || false;
|
|
79
|
+
|
|
78
80
|
/** @ignore */
|
|
79
81
|
this.conn = new WebSocketConnector(wsUrl);
|
|
80
|
-
this.conn.setProjection(options.projection || 'epsg:3857');
|
|
81
82
|
|
|
82
|
-
if (
|
|
83
|
-
this.conn.
|
|
83
|
+
if (!this.isUpdateBboxOnMoveEnd) {
|
|
84
|
+
this.conn.setProjection(options.projection || 'epsg:3857');
|
|
85
|
+
|
|
86
|
+
if (options.bbox) {
|
|
87
|
+
this.conn.setBbox(options.bbox);
|
|
88
|
+
}
|
|
84
89
|
}
|
|
85
90
|
}
|
|
86
91
|
|
|
@@ -377,7 +382,12 @@ class TralisAPI {
|
|
|
377
382
|
*/
|
|
378
383
|
subscribeTrajectory(mode, onMessage) {
|
|
379
384
|
this.unsubscribeTrajectory(onMessage);
|
|
380
|
-
this.subscribe(
|
|
385
|
+
this.subscribe(
|
|
386
|
+
`trajectory${getModeSuffix(mode, TralisModes)}`,
|
|
387
|
+
onMessage,
|
|
388
|
+
null,
|
|
389
|
+
this.isUpdateBboxOnMoveEnd,
|
|
390
|
+
);
|
|
381
391
|
}
|
|
382
392
|
|
|
383
393
|
/**
|
|
@@ -48,17 +48,17 @@ class WebSocketConnector {
|
|
|
48
48
|
/** @ignore */
|
|
49
49
|
this.websocket = new WebSocket(url);
|
|
50
50
|
|
|
51
|
-
if (this.currentProj) {
|
|
52
|
-
|
|
53
|
-
}
|
|
51
|
+
// if (this.currentProj) {
|
|
52
|
+
// this.setProjection(this.currentProj);
|
|
53
|
+
// }
|
|
54
54
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
55
|
+
// [...this.subscriptions].forEach((s) => {
|
|
56
|
+
// this.subscribe(s.params, s.cb, s.errorCb, s.quiet);
|
|
57
|
+
// });
|
|
58
58
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
59
|
+
// if (this.currentBbox) {
|
|
60
|
+
// this.setBbox(this.currentBbox);
|
|
61
|
+
// }
|
|
62
62
|
|
|
63
63
|
// reconnect on close
|
|
64
64
|
this.websocket.onclose = () => {
|
|
@@ -123,6 +123,7 @@ class WebSocketConnector {
|
|
|
123
123
|
* @type {Array<Array<number>>}
|
|
124
124
|
*/
|
|
125
125
|
this.currentBbox = coordinates;
|
|
126
|
+
|
|
126
127
|
this.send(`BBOX ${coordinates.join(' ')}`);
|
|
127
128
|
// this.subscriptions.forEach((s) => {
|
|
128
129
|
// this.get(s.params, s.cb, s.errorCb);
|
|
@@ -184,27 +185,28 @@ class WebSocketConnector {
|
|
|
184
185
|
* @param {Object} params Parameters for the websocket get request
|
|
185
186
|
* @param {function} cb callback on listen
|
|
186
187
|
* @param {function} errorCb Callback on error
|
|
187
|
-
* @param {boolean} quiet if
|
|
188
|
+
* @param {boolean} quiet if false, no GET or SUB requests are send, only the callback is registered.
|
|
188
189
|
*/
|
|
189
|
-
subscribe(params, cb, errorCb, quiet) {
|
|
190
|
+
subscribe(params, cb, errorCb, quiet = false) {
|
|
190
191
|
const { onMessageCb, onErrorCb } = this.listen(params, cb, errorCb);
|
|
191
192
|
const reqStr = WebSocketConnector.getRequestString('', params);
|
|
192
193
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
this.subscriptions.push(newSubscr);
|
|
202
|
-
}
|
|
194
|
+
const index = this.subscriptions.findIndex((subcr) => {
|
|
195
|
+
return params.channel === subcr.params.channel && cb === subcr.cb;
|
|
196
|
+
});
|
|
197
|
+
const newSubscr = { params, cb, errorCb, onMessageCb, onErrorCb, quiet };
|
|
198
|
+
if (index > -1) {
|
|
199
|
+
this.subscriptions[index] = newSubscr;
|
|
200
|
+
} else {
|
|
201
|
+
this.subscriptions.push(newSubscr);
|
|
203
202
|
}
|
|
204
203
|
|
|
205
204
|
if (!this.subscribed[reqStr]) {
|
|
205
|
+
// if (!newSubscr.quiet) {
|
|
206
206
|
this.send(`GET ${reqStr}`);
|
|
207
|
-
|
|
207
|
+
|
|
208
|
+
// this.send(`SUB ${reqStr}`);
|
|
209
|
+
// }
|
|
208
210
|
this.subscribed[reqStr] = true;
|
|
209
211
|
}
|
|
210
212
|
}
|
|
@@ -238,7 +240,7 @@ class WebSocketConnector {
|
|
|
238
240
|
this.subscribed[source] &&
|
|
239
241
|
!this.subscriptions.find((s) => s.params.channel === source)
|
|
240
242
|
) {
|
|
241
|
-
this.send(`DEL ${source}`);
|
|
243
|
+
// this.send(`DEL ${source}`);
|
|
242
244
|
this.subscribed[source] = false;
|
|
243
245
|
}
|
|
244
246
|
}
|
|
@@ -44,10 +44,8 @@ export class TrackerLayerInterface {
|
|
|
44
44
|
/**
|
|
45
45
|
* Start the timeout for the next update.
|
|
46
46
|
* @private
|
|
47
|
-
* @param {number} zoom
|
|
48
47
|
*/
|
|
49
|
-
|
|
50
|
-
startUpdateTime(zoom) {}
|
|
48
|
+
startUpdateTime() {}
|
|
51
49
|
|
|
52
50
|
/**
|
|
53
51
|
* Stop the clock.
|
|
@@ -426,6 +424,9 @@ const TrackerLayerMixin = (Base) =>
|
|
|
426
424
|
}
|
|
427
425
|
}
|
|
428
426
|
|
|
427
|
+
/**
|
|
428
|
+
*
|
|
429
|
+
|
|
429
430
|
/**
|
|
430
431
|
* Launch renderTrajectories. it avoids duplicating code in renderTrajectories method.
|
|
431
432
|
*
|
|
@@ -547,9 +548,21 @@ const TrackerLayerMixin = (Base) =>
|
|
|
547
548
|
});
|
|
548
549
|
}
|
|
549
550
|
|
|
551
|
+
/**
|
|
552
|
+
* On zoomend we adjust the time interval of the update of vehicles positions.
|
|
553
|
+
*
|
|
554
|
+
* @param evt Event that triggered the function.
|
|
555
|
+
* @private
|
|
556
|
+
*/
|
|
557
|
+
// eslint-disable-next-line no-unused-vars
|
|
558
|
+
onZoomEnd(evt) {
|
|
559
|
+
this.startUpdateTime();
|
|
560
|
+
}
|
|
561
|
+
|
|
550
562
|
/**
|
|
551
563
|
* Define beahvior when a vehicle is clicked
|
|
552
564
|
* To be defined in child classes.
|
|
565
|
+
*
|
|
553
566
|
* @private
|
|
554
567
|
* @override
|
|
555
568
|
*/
|
|
@@ -558,6 +571,7 @@ const TrackerLayerMixin = (Base) =>
|
|
|
558
571
|
/**
|
|
559
572
|
* Define behavior when a vehicle is hovered
|
|
560
573
|
* To be defined in child classes.
|
|
574
|
+
*
|
|
561
575
|
* @private
|
|
562
576
|
* @override
|
|
563
577
|
*/
|
|
@@ -565,6 +579,7 @@ const TrackerLayerMixin = (Base) =>
|
|
|
565
579
|
|
|
566
580
|
/**
|
|
567
581
|
* Get the duration before the next update depending on zoom level.
|
|
582
|
+
*
|
|
568
583
|
* @private
|
|
569
584
|
* @param {number} zoom
|
|
570
585
|
*/
|
|
@@ -572,6 +587,7 @@ const TrackerLayerMixin = (Base) =>
|
|
|
572
587
|
const roundedZoom = Math.round(zoom);
|
|
573
588
|
const timeStep = timeSteps[roundedZoom] || 25;
|
|
574
589
|
const nextTick = Math.max(25, timeStep / this.speed);
|
|
590
|
+
console.log(`Next render in ${nextTick} ms.`);
|
|
575
591
|
return nextTick;
|
|
576
592
|
}
|
|
577
593
|
|
|
@@ -91,10 +91,10 @@ const TralisLayerMixin = (TrackerLayer) =>
|
|
|
91
91
|
super({ ...options });
|
|
92
92
|
this.debug = options.debug;
|
|
93
93
|
this.mode = options.mode || TralisModes.TOPOGRAPHIC;
|
|
94
|
-
this.refreshTimeInMs = 1000 / 30;
|
|
95
94
|
this.onMessage = this.onMessage.bind(this);
|
|
96
95
|
this.onDeleteMessage = this.onDeleteMessage.bind(this);
|
|
97
96
|
this.api = options.api || new TralisAPI(options);
|
|
97
|
+
|
|
98
98
|
this.format = new GeoJSON();
|
|
99
99
|
|
|
100
100
|
// This property will call api.setBbox on each movend event
|
|
@@ -215,7 +215,7 @@ const TralisLayerMixin = (TrackerLayer) =>
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
this.
|
|
218
|
+
this.tracker.setTrajectories(this.trajectories);
|
|
219
219
|
}
|
|
220
220
|
|
|
221
221
|
removeTrajectory(id) {
|
|
@@ -235,15 +235,6 @@ const TralisLayerMixin = (TrackerLayer) =>
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
}
|
|
238
|
-
|
|
239
|
-
updateTrajectories() {
|
|
240
|
-
this.tracker.setTrajectories(this.trajectories);
|
|
241
|
-
this.renderTrajectories();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
getRefreshTimeInMs() {
|
|
245
|
-
return this.refreshTimeInMs;
|
|
246
|
-
}
|
|
247
238
|
};
|
|
248
239
|
|
|
249
240
|
export default TralisLayerMixin;
|