mobility-toolbox-js 2.0.0 → 2.0.1-beta.13
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/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
- package/api/index.js +3 -3
- package/{ol/README.md → api/typedefs.js} +0 -0
- package/common/Tracker.js +14 -118
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +26 -91
- package/common/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +53 -244
- package/common/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +20 -44
- package/common/mixins/SearchMixin.js +100 -166
- package/common/mixins/TralisLayerMixin.js +443 -894
- package/common/styles/index.js +4 -4
- package/common/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +2 -11
- package/common/styles/trackerSimpleStyle.js +4 -8
- package/common/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +15 -17
- package/common/typedefs.js +0 -23
- package/common/utils/createTrackerFilters.js +10 -41
- package/common/utils/createTrackerFilters.test.js +40 -56
- package/common/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +32 -39
- package/common/utils/getMapboxStyleUrl.js +3 -13
- package/common/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -6
- package/common/utils/removeDuplicate.js +3 -17
- package/common/utils/removeDuplicate.test.js +17 -20
- package/common/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +8 -32
- package/common/utils/timeUtils.test.js +7 -13
- package/index.js +8 -2
- package/mapbox/controls/CopyrightControl.js +9 -38
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -3
- package/mapbox/layers/Layer.js +15 -76
- package/mapbox/layers/Layer.test.js +81 -101
- package/mapbox/layers/TralisLayer.js +46 -193
- package/mapbox/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +8 -46
- package/ol/controls/CopyrightControl.test.js +75 -121
- package/ol/controls/RoutingControl.js +167 -532
- package/ol/controls/RoutingControl.test.js +99 -164
- package/ol/controls/StopFinderControl.js +3 -31
- package/ol/controls/StopFinderControl.test.js +18 -29
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -13
- package/ol/layers/Layer.js +23 -128
- package/ol/layers/Layer.test.js +79 -102
- package/ol/layers/MapboxLayer.js +62 -237
- package/ol/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +38 -268
- package/ol/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +46 -187
- package/ol/layers/RoutingLayer.js +21 -51
- package/ol/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +102 -276
- package/ol/layers/TralisLayer.test.js +32 -50
- package/ol/layers/VectorLayer.js +3 -24
- package/ol/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +15 -57
- package/ol/layers/WMSLayer.test.js +35 -43
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +17 -25
- package/ol/styles/index.js +2 -2
- package/package.json +35 -62
- package/api/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/typedefs.js +0 -81
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/index.js.map +0 -1
- package/module.js +0 -23
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
|
@@ -1,930 +1,479 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import trackerDefaultStyle from '../styles/trackerDefaultStyle';
|
|
18
|
-
import { TralisAPI, TralisModes } from '../../api';
|
|
19
|
-
|
|
20
|
-
/* Permalink parameter used to filters vehicles */
|
|
21
|
-
const LINE_FILTER = 'publishedlinename';
|
|
22
|
-
const ROUTE_FILTER = 'tripnumber';
|
|
23
|
-
const OPERATOR_FILTER = 'operator';
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* TralisLayerInterface.
|
|
27
|
-
*/
|
|
1
|
+
import qs from "query-string";
|
|
2
|
+
import { buffer, containsCoordinate, intersects } from "ol/extent";
|
|
3
|
+
import { unByKey } from "ol/Observable";
|
|
4
|
+
import GeoJSON from "ol/format/GeoJSON";
|
|
5
|
+
import Point from "ol/geom/Point";
|
|
6
|
+
import debounce from "lodash.debounce";
|
|
7
|
+
import throttle from "lodash.throttle";
|
|
8
|
+
import { fromLonLat } from "ol/proj";
|
|
9
|
+
import Tracker from "../Tracker";
|
|
10
|
+
import { timeSteps } from "../trackerConfig";
|
|
11
|
+
import createFilters from "../utils/createTrackerFilters";
|
|
12
|
+
import trackerDefaultStyle from "../styles/trackerDefaultStyle";
|
|
13
|
+
import { TralisAPI, TralisModes } from "../../api";
|
|
14
|
+
const LINE_FILTER = "publishedlinename";
|
|
15
|
+
const ROUTE_FILTER = "tripnumber";
|
|
16
|
+
const OPERATOR_FILTER = "operator";
|
|
28
17
|
export class TralisLayerInterface {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
* @param {ol/Map~Map} map
|
|
46
|
-
*/
|
|
47
|
-
init(map) {}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Terminate the layer unsubscribing to the Tralis api.
|
|
51
|
-
*/
|
|
52
|
-
terminate() {}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Start the clock.
|
|
56
|
-
*/
|
|
57
|
-
start() {}
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Stop the clock.
|
|
61
|
-
*/
|
|
62
|
-
stop() {}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* Set the Tralis api's bbox.
|
|
66
|
-
*
|
|
67
|
-
* @param {Array<number>} extent Extent to request, [minX, minY, maxX, maxY, zoom].
|
|
68
|
-
* @param {number} zoom Zoom level to request. Must be an integer.
|
|
69
|
-
*/
|
|
70
|
-
setBbox(extent, zoom) {}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Set the Tralis api's mode.
|
|
74
|
-
*
|
|
75
|
-
* @param {TralisMode} mode Tralis mode
|
|
76
|
-
*/
|
|
77
|
-
setMode(mode) {}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Request the stopSequence and the fullTrajectory informations for a vehicle.
|
|
81
|
-
*
|
|
82
|
-
* @param {string} id The vehicle identifier (the train_id property).
|
|
83
|
-
* @param {TralisMode} mode The mode to request. If not defined, the layer´s mode propetrty will be used.
|
|
84
|
-
* @return {Promise<{stopSequence: StopSequence, fullTrajectory: FullTrajectory>} A promise that will be resolved with the trajectory informations.
|
|
85
|
-
*/
|
|
86
|
-
getTrajectoryInfos(id, mode) {}
|
|
18
|
+
constructor(options = {}) {
|
|
19
|
+
}
|
|
20
|
+
attachToMap(map) {
|
|
21
|
+
}
|
|
22
|
+
detachFromMap() {
|
|
23
|
+
}
|
|
24
|
+
start() {
|
|
25
|
+
}
|
|
26
|
+
stop() {
|
|
27
|
+
}
|
|
28
|
+
setBbox(extent, zoom) {
|
|
29
|
+
}
|
|
30
|
+
setMode(mode) {
|
|
31
|
+
}
|
|
32
|
+
getTrajectoryInfos(id, mode) {
|
|
33
|
+
}
|
|
87
34
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Define layer's properties.
|
|
155
|
-
*
|
|
156
|
-
* @ignore
|
|
157
|
-
*/
|
|
158
|
-
defineProperties(options) {
|
|
159
|
-
// Tracker options use to build the tracker.
|
|
160
|
-
let { regexPublishedLineName, publishedLineName, tripNumber, operator } =
|
|
161
|
-
options;
|
|
162
|
-
const {
|
|
163
|
-
style,
|
|
164
|
-
speed,
|
|
165
|
-
pixelRatio,
|
|
166
|
-
hoverVehicleId,
|
|
167
|
-
selectedVehicleId,
|
|
168
|
-
filter,
|
|
169
|
-
sort,
|
|
170
|
-
time,
|
|
171
|
-
live,
|
|
172
|
-
} = options;
|
|
173
|
-
|
|
174
|
-
const initTrackerOptions = {
|
|
175
|
-
style,
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
Object.keys(initTrackerOptions).forEach(
|
|
179
|
-
(key) =>
|
|
180
|
-
initTrackerOptions[key] === undefined &&
|
|
181
|
-
delete initTrackerOptions[key],
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
let currSpeed = speed || 1;
|
|
185
|
-
let currTime = time || new Date();
|
|
186
|
-
|
|
187
|
-
super.defineProperties(options);
|
|
188
|
-
|
|
189
|
-
Object.defineProperties(this, {
|
|
190
|
-
isTrackerLayer: { value: true },
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Style function used to render a vehicle.
|
|
194
|
-
*/
|
|
195
|
-
style: {
|
|
196
|
-
value: (trajectory, viewState) =>
|
|
197
|
-
(style || trackerDefaultStyle)(trajectory, viewState, this),
|
|
198
|
-
},
|
|
199
|
-
|
|
200
|
-
/**
|
|
201
|
-
* Speed of the wheel of time.
|
|
202
|
-
* If live property is true. The speed is ignored.
|
|
203
|
-
*/
|
|
204
|
-
speed: {
|
|
205
|
-
get: () => currSpeed,
|
|
206
|
-
set: (newSpeed) => {
|
|
207
|
-
currSpeed = newSpeed;
|
|
208
|
-
this.start();
|
|
209
|
-
},
|
|
210
|
-
},
|
|
211
|
-
|
|
212
|
-
/**
|
|
213
|
-
* Function to filter which vehicles to display.
|
|
214
|
-
*/
|
|
215
|
-
filter: {
|
|
216
|
-
value: filter,
|
|
217
|
-
writable: true,
|
|
218
|
-
},
|
|
219
|
-
|
|
220
|
-
/**
|
|
221
|
-
* Function to sort the vehicles to display.
|
|
222
|
-
*/
|
|
223
|
-
sort: {
|
|
224
|
-
value: sort,
|
|
225
|
-
writable: true,
|
|
226
|
-
},
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* The tracker that renders the trajectories.
|
|
230
|
-
*/
|
|
231
|
-
tracker: { value: null, writable: true },
|
|
232
|
-
|
|
233
|
-
/**
|
|
234
|
-
* Canvas cache object for trajectories drawn.
|
|
235
|
-
*/
|
|
236
|
-
styleCache: { value: {} },
|
|
237
|
-
|
|
238
|
-
/**
|
|
239
|
-
* If true. The layer will always use Date.now() on the next tick to render the trajectories.
|
|
240
|
-
* When true, setting the time property has no effect.
|
|
241
|
-
*/
|
|
242
|
-
live: {
|
|
243
|
-
value: live === false ? live : true,
|
|
244
|
-
writable: true,
|
|
245
|
-
},
|
|
246
|
-
|
|
247
|
-
/**
|
|
248
|
-
* Time used to display the trajectories. Can be a Date or a number in ms representing a Date.
|
|
249
|
-
* If live property is true. The setter does nothing.
|
|
250
|
-
*/
|
|
251
|
-
time: {
|
|
252
|
-
get: () => currTime,
|
|
253
|
-
set: (newTime) => {
|
|
254
|
-
currTime = newTime && newTime.getTime ? newTime : new Date(newTime);
|
|
255
|
-
this.renderTrajectories();
|
|
256
|
-
},
|
|
257
|
-
},
|
|
258
|
-
|
|
259
|
-
/**
|
|
260
|
-
* Keep track of which trajectories are stored.
|
|
261
|
-
*/
|
|
262
|
-
trajectories: {
|
|
263
|
-
value: {},
|
|
264
|
-
writable: true,
|
|
265
|
-
},
|
|
266
|
-
|
|
267
|
-
/**
|
|
268
|
-
* Keep track of which trajectories are currently drawn.
|
|
269
|
-
*/
|
|
270
|
-
renderedTrajectories: {
|
|
271
|
-
get: () => (this.tracker && this.tracker.renderedTrajectories) || [],
|
|
272
|
-
},
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Id of the hovered vehicle.
|
|
276
|
-
*/
|
|
277
|
-
hoverVehicleId: {
|
|
278
|
-
value: hoverVehicleId,
|
|
279
|
-
writable: true,
|
|
280
|
-
},
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Id of the selected vehicle.
|
|
284
|
-
*/
|
|
285
|
-
selectedVehicleId: {
|
|
286
|
-
value: selectedVehicleId,
|
|
287
|
-
writable: true,
|
|
288
|
-
},
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Id of the selected vehicle.
|
|
292
|
-
*/
|
|
293
|
-
pixelRatio: {
|
|
294
|
-
value:
|
|
295
|
-
pixelRatio ||
|
|
296
|
-
(typeof window !== 'undefined' ? window.devicePixelRatio : 1),
|
|
297
|
-
writable: true,
|
|
298
|
-
},
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Options used by the constructor of the Tracker class.
|
|
302
|
-
*/
|
|
303
|
-
initTrackerOptions: {
|
|
304
|
-
value: initTrackerOptions,
|
|
305
|
-
writable: false,
|
|
306
|
-
},
|
|
307
|
-
|
|
308
|
-
/**
|
|
309
|
-
* If true, encapsulates the renderTrajectories calls in a requestAnimationFrame.
|
|
310
|
-
*/
|
|
311
|
-
useRequestAnimationFrame: {
|
|
312
|
-
value: options.useRequestAnimationFrame || false,
|
|
313
|
-
writable: true,
|
|
314
|
-
},
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* If true, encapsulates the renderTrajectories calls in a throttle function. Default to true.
|
|
318
|
-
*/
|
|
319
|
-
useThrottle: {
|
|
320
|
-
value: options.useThrottle || true,
|
|
321
|
-
writable: true,
|
|
322
|
-
},
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* If true, encapsulates the renderTrajectories calls in a debounce function.
|
|
326
|
-
*/
|
|
327
|
-
useDebounce: {
|
|
328
|
-
value: options.useDebounce || false,
|
|
329
|
-
writable: true,
|
|
330
|
-
},
|
|
331
|
-
|
|
332
|
-
/**
|
|
333
|
-
* Filter properties used in combination with permalink parameters.
|
|
334
|
-
*/
|
|
335
|
-
publishedLineName: {
|
|
336
|
-
get: () => publishedLineName,
|
|
337
|
-
set: (newPublishedLineName) => {
|
|
338
|
-
publishedLineName = newPublishedLineName;
|
|
339
|
-
this.updateFilters();
|
|
340
|
-
},
|
|
341
|
-
},
|
|
342
|
-
tripNumber: {
|
|
343
|
-
get: () => tripNumber,
|
|
344
|
-
set: (newTripNumber) => {
|
|
345
|
-
tripNumber = newTripNumber;
|
|
346
|
-
this.updateFilters();
|
|
347
|
-
},
|
|
348
|
-
},
|
|
349
|
-
operator: {
|
|
350
|
-
get: () => operator,
|
|
351
|
-
set: (newOperator) => {
|
|
352
|
-
operator = newOperator;
|
|
353
|
-
this.updateFilters();
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
regexPublishedLineName: {
|
|
357
|
-
get: () => regexPublishedLineName,
|
|
358
|
-
set: (newRegex) => {
|
|
359
|
-
regexPublishedLineName = newRegex;
|
|
360
|
-
this.updateFilters();
|
|
361
|
-
},
|
|
362
|
-
},
|
|
363
|
-
|
|
364
|
-
/**
|
|
365
|
-
* Style properties.
|
|
366
|
-
*/
|
|
367
|
-
delayDisplay: {
|
|
368
|
-
value: options.delayDisplay || 300000,
|
|
369
|
-
writable: true,
|
|
370
|
-
},
|
|
371
|
-
delayOutlineColor: {
|
|
372
|
-
value: options.delayOutlineColor || '#000000',
|
|
373
|
-
writable: true,
|
|
374
|
-
},
|
|
375
|
-
|
|
376
|
-
/**
|
|
377
|
-
* Debug properties.
|
|
378
|
-
*/
|
|
379
|
-
// Not used anymore, but could be useful for debugging.
|
|
380
|
-
// showVehicleTraj: {
|
|
381
|
-
// value:
|
|
382
|
-
// options.showVehicleTraj !== undefined
|
|
383
|
-
// ? options.showVehicleTraj
|
|
384
|
-
// : true,
|
|
385
|
-
// writable: true,
|
|
386
|
-
// },
|
|
387
|
-
});
|
|
388
|
-
|
|
389
|
-
// Update filter function based on convenient properties
|
|
390
|
-
this.updateFilters();
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
init(map) {
|
|
394
|
-
super.init(map);
|
|
395
|
-
|
|
396
|
-
this.tracker = new Tracker({
|
|
397
|
-
style: (...args) => this.style(...args),
|
|
398
|
-
...this.initTrackerOptions,
|
|
399
|
-
});
|
|
400
|
-
|
|
401
|
-
// If the layer is visible we start the rendering clock
|
|
402
|
-
if (this.visible) {
|
|
403
|
-
this.start();
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
// On change of visibility we start/stop the rendering clock
|
|
407
|
-
this.visibilityRef = this.on('change:visible', (evt) => {
|
|
408
|
-
if (evt.target.visible) {
|
|
35
|
+
const TralisLayerMixin = (Base) => class extends Base {
|
|
36
|
+
constructor(options = {}) {
|
|
37
|
+
super({ hitTolerance: 10, ...options });
|
|
38
|
+
this.debug = options.debug;
|
|
39
|
+
this.mode = options.mode || TralisModes.TOPOGRAPHIC;
|
|
40
|
+
this.api = options.api || new TralisAPI(options);
|
|
41
|
+
this.tenant = options.tenant || "";
|
|
42
|
+
this.minZoomNonTrain = options.minZoomNonTrain || 9;
|
|
43
|
+
this.minZoomInterpolation = options.minZoomInterpolation || 8;
|
|
44
|
+
this.format = new GeoJSON();
|
|
45
|
+
this.generalizationLevelByZoom = options.generalizationLevelByZoom || {
|
|
46
|
+
0: 5,
|
|
47
|
+
1: 5,
|
|
48
|
+
2: 5,
|
|
49
|
+
3: 5,
|
|
50
|
+
4: 5,
|
|
51
|
+
5: 5,
|
|
52
|
+
6: 5,
|
|
53
|
+
7: 5,
|
|
54
|
+
8: 10,
|
|
55
|
+
9: 30,
|
|
56
|
+
10: 30,
|
|
57
|
+
11: 100,
|
|
58
|
+
12: 100,
|
|
59
|
+
13: 100
|
|
60
|
+
};
|
|
61
|
+
this.isUpdateBboxOnMoveEnd = options.isUpdateBboxOnMoveEnd !== false;
|
|
62
|
+
this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, 50, { leading: false, trailing: true });
|
|
63
|
+
this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, 50, { leading: true, trailing: true, maxWait: 5e3 });
|
|
64
|
+
this.onFeatureHover = this.onFeatureHover.bind(this);
|
|
65
|
+
this.onFeatureClick = this.onFeatureClick.bind(this);
|
|
66
|
+
this.renderTrajectoriesInternal = this.renderTrajectoriesInternal.bind(this);
|
|
67
|
+
this.onTrajectoryMessage = this.onTrajectoryMessage.bind(this);
|
|
68
|
+
this.onDeleteTrajectoryMessage = this.onDeleteTrajectoryMessage.bind(this);
|
|
69
|
+
this.onDocumentVisibilityChange = this.onDocumentVisibilityChange.bind(this);
|
|
70
|
+
}
|
|
71
|
+
defineProperties(options) {
|
|
72
|
+
let { regexPublishedLineName, publishedLineName, tripNumber, operator } = options;
|
|
73
|
+
const {
|
|
74
|
+
style,
|
|
75
|
+
speed,
|
|
76
|
+
pixelRatio,
|
|
77
|
+
hoverVehicleId,
|
|
78
|
+
selectedVehicleId,
|
|
79
|
+
filter,
|
|
80
|
+
sort,
|
|
81
|
+
time,
|
|
82
|
+
live
|
|
83
|
+
} = options;
|
|
84
|
+
const initTrackerOptions = {
|
|
85
|
+
style
|
|
86
|
+
};
|
|
87
|
+
Object.keys(initTrackerOptions).forEach((key) => initTrackerOptions[key] === void 0 && delete initTrackerOptions[key]);
|
|
88
|
+
let currSpeed = speed || 1;
|
|
89
|
+
let currTime = time || new Date();
|
|
90
|
+
super.defineProperties(options);
|
|
91
|
+
Object.defineProperties(this, {
|
|
92
|
+
isTrackerLayer: { value: true },
|
|
93
|
+
style: {
|
|
94
|
+
value: (trajectory, viewState) => (style || trackerDefaultStyle)(trajectory, viewState, this)
|
|
95
|
+
},
|
|
96
|
+
speed: {
|
|
97
|
+
get: () => currSpeed,
|
|
98
|
+
set: (newSpeed) => {
|
|
99
|
+
currSpeed = newSpeed;
|
|
409
100
|
this.start();
|
|
410
|
-
} else {
|
|
411
|
-
this.stop();
|
|
412
101
|
}
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
102
|
+
},
|
|
103
|
+
filter: {
|
|
104
|
+
value: filter,
|
|
105
|
+
writable: true
|
|
106
|
+
},
|
|
107
|
+
sort: {
|
|
108
|
+
value: sort,
|
|
109
|
+
writable: true
|
|
110
|
+
},
|
|
111
|
+
tracker: { value: null, writable: true },
|
|
112
|
+
styleCache: { value: {} },
|
|
113
|
+
live: {
|
|
114
|
+
value: live === false ? live : true,
|
|
115
|
+
writable: true
|
|
116
|
+
},
|
|
117
|
+
time: {
|
|
118
|
+
get: () => currTime,
|
|
119
|
+
set: (newTime) => {
|
|
120
|
+
currTime = newTime && newTime.getTime ? newTime : new Date(newTime);
|
|
121
|
+
this.renderTrajectories();
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
trajectories: {
|
|
125
|
+
value: {},
|
|
126
|
+
writable: true
|
|
127
|
+
},
|
|
128
|
+
renderedTrajectories: {
|
|
129
|
+
get: () => this.tracker && this.tracker.renderedTrajectories || []
|
|
130
|
+
},
|
|
131
|
+
hoverVehicleId: {
|
|
132
|
+
value: hoverVehicleId,
|
|
133
|
+
writable: true
|
|
134
|
+
},
|
|
135
|
+
selectedVehicleId: {
|
|
136
|
+
value: selectedVehicleId,
|
|
137
|
+
writable: true
|
|
138
|
+
},
|
|
139
|
+
pixelRatio: {
|
|
140
|
+
value: pixelRatio || (typeof window !== "undefined" ? window.devicePixelRatio : 1),
|
|
141
|
+
writable: true
|
|
142
|
+
},
|
|
143
|
+
initTrackerOptions: {
|
|
144
|
+
value: initTrackerOptions,
|
|
145
|
+
writable: false
|
|
146
|
+
},
|
|
147
|
+
useRequestAnimationFrame: {
|
|
148
|
+
value: options.useRequestAnimationFrame || false,
|
|
149
|
+
writable: true
|
|
150
|
+
},
|
|
151
|
+
useThrottle: {
|
|
152
|
+
value: options.useThrottle || true,
|
|
153
|
+
writable: true
|
|
154
|
+
},
|
|
155
|
+
useDebounce: {
|
|
156
|
+
value: options.useDebounce || false,
|
|
157
|
+
writable: true
|
|
158
|
+
},
|
|
159
|
+
publishedLineName: {
|
|
160
|
+
get: () => publishedLineName,
|
|
161
|
+
set: (newPublishedLineName) => {
|
|
162
|
+
publishedLineName = newPublishedLineName;
|
|
163
|
+
this.updateFilters();
|
|
164
|
+
}
|
|
165
|
+
},
|
|
166
|
+
tripNumber: {
|
|
167
|
+
get: () => tripNumber,
|
|
168
|
+
set: (newTripNumber) => {
|
|
169
|
+
tripNumber = newTripNumber;
|
|
170
|
+
this.updateFilters();
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
operator: {
|
|
174
|
+
get: () => operator,
|
|
175
|
+
set: (newOperator) => {
|
|
176
|
+
operator = newOperator;
|
|
177
|
+
this.updateFilters();
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
regexPublishedLineName: {
|
|
181
|
+
get: () => regexPublishedLineName,
|
|
182
|
+
set: (newRegex) => {
|
|
183
|
+
regexPublishedLineName = newRegex;
|
|
184
|
+
this.updateFilters();
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
delayDisplay: {
|
|
188
|
+
value: options.delayDisplay || 3e5,
|
|
189
|
+
writable: true
|
|
190
|
+
},
|
|
191
|
+
delayOutlineColor: {
|
|
192
|
+
value: options.delayOutlineColor || "#000000",
|
|
193
|
+
writable: true
|
|
436
194
|
}
|
|
437
|
-
|
|
195
|
+
});
|
|
196
|
+
this.updateFilters();
|
|
197
|
+
}
|
|
198
|
+
attachToMap(map) {
|
|
199
|
+
super.attachToMap(map);
|
|
200
|
+
this.tracker = new Tracker({
|
|
201
|
+
style: (...args) => this.style(...args),
|
|
202
|
+
...this.initTrackerOptions
|
|
203
|
+
});
|
|
204
|
+
if (this.visible) {
|
|
205
|
+
this.start();
|
|
438
206
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
if (this.isClickActive) {
|
|
446
|
-
this.onClick(this.onFeatureClick);
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
if (this.isHoverActive) {
|
|
450
|
-
this.onHover(this.onFeatureHover);
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
this.api.open();
|
|
454
|
-
this.api.subscribeTrajectory(
|
|
455
|
-
this.mode,
|
|
456
|
-
this.onTrajectoryMessage,
|
|
457
|
-
this.isUpdateBboxOnMoveEnd,
|
|
458
|
-
);
|
|
459
|
-
this.api.subscribeDeletedVehicles(
|
|
460
|
-
this.mode,
|
|
461
|
-
this.onDeleteTrajectoryMessage,
|
|
462
|
-
this.isUpdateBboxOnMoveEnd,
|
|
463
|
-
);
|
|
464
|
-
|
|
465
|
-
if (this.isUpdateBboxOnMoveEnd) {
|
|
466
|
-
// Update the bbox on each move end
|
|
467
|
-
this.setBbox();
|
|
207
|
+
this.visibilityRef = this.on("change:visible", (evt) => {
|
|
208
|
+
if (evt.target.visible) {
|
|
209
|
+
this.start();
|
|
210
|
+
} else {
|
|
211
|
+
this.stop();
|
|
468
212
|
}
|
|
213
|
+
});
|
|
214
|
+
document.addEventListener("visibilitychange", this.onDocumentVisibilityChange);
|
|
215
|
+
}
|
|
216
|
+
detachFromMap() {
|
|
217
|
+
document.removeEventListener("visibilitychange", this.onDocumentVisibilityChange);
|
|
218
|
+
this.stop();
|
|
219
|
+
unByKey(this.visibilityRef);
|
|
220
|
+
if (this.tracker) {
|
|
221
|
+
const { canvas } = this.tracker;
|
|
222
|
+
const context = canvas.getContext("2d");
|
|
223
|
+
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
224
|
+
this.tracker = null;
|
|
469
225
|
}
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
startUpdateTime()
|
|
476
|
-
|
|
477
|
-
this.
|
|
478
|
-
this.updateTimeInterval = setInterval(() => {
|
|
479
|
-
// When live=true, we update the time with new Date();
|
|
480
|
-
this.time = this.live
|
|
481
|
-
? new Date()
|
|
482
|
-
: this.time.getTime() + this.updateTimeDelay * this.speed;
|
|
483
|
-
}, this.updateTimeDelay);
|
|
226
|
+
super.detachFromMap();
|
|
227
|
+
}
|
|
228
|
+
start() {
|
|
229
|
+
this.stop();
|
|
230
|
+
this.renderTrajectories();
|
|
231
|
+
this.startUpdateTime();
|
|
232
|
+
if (this.isClickActive) {
|
|
233
|
+
this.onClick(this.onFeatureClick);
|
|
484
234
|
}
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
this.api.unsubscribeTrajectory(this.onTrajectoryMessage);
|
|
488
|
-
this.api.unsubscribeDeletedVehicles(this.onDeleteTrajectoryMessage);
|
|
489
|
-
this.api.close();
|
|
235
|
+
if (this.isHoverActive) {
|
|
236
|
+
this.onHover(this.onFeatureHover);
|
|
490
237
|
}
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
stopUpdateTime() {
|
|
497
|
-
if (this.updateTimeInterval) {
|
|
498
|
-
clearInterval(this.updateTimeInterval);
|
|
499
|
-
}
|
|
238
|
+
this.api.open();
|
|
239
|
+
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
240
|
+
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
241
|
+
if (this.isUpdateBboxOnMoveEnd) {
|
|
242
|
+
this.setBbox();
|
|
500
243
|
}
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
if (!this.tracker) {
|
|
518
|
-
return false;
|
|
519
|
-
}
|
|
520
|
-
|
|
521
|
-
const time = this.live ? Date.now() : this.time;
|
|
522
|
-
|
|
523
|
-
const trajectories = Object.values(this.trajectories);
|
|
524
|
-
|
|
525
|
-
// console.time('sort');
|
|
526
|
-
if (this.sort) {
|
|
527
|
-
trajectories.sort(this.sort);
|
|
528
|
-
}
|
|
529
|
-
// console.timeEnd('sort');
|
|
530
|
-
|
|
531
|
-
// console.time('render');
|
|
532
|
-
this.renderState = this.tracker.renderTrajectories(
|
|
533
|
-
trajectories,
|
|
534
|
-
{ ...viewState, pixelRatio: this.pixelRatio, time },
|
|
535
|
-
{
|
|
536
|
-
noInterpolate:
|
|
537
|
-
viewState.zoom < this.minZoomInterpolation ? true : noInterpolate,
|
|
538
|
-
hoverVehicleId: this.hoverVehicleId,
|
|
539
|
-
selectedVehicleId: this.selectedVehicleId,
|
|
540
|
-
iconScale: this.iconScale,
|
|
541
|
-
delayDisplay: this.delayDisplay,
|
|
542
|
-
delayOutlineColor: this.delayOutlineColor,
|
|
543
|
-
},
|
|
544
|
-
);
|
|
545
|
-
|
|
546
|
-
// console.timeEnd('render');
|
|
547
|
-
return true;
|
|
244
|
+
}
|
|
245
|
+
startUpdateTime() {
|
|
246
|
+
this.stopUpdateTime();
|
|
247
|
+
this.updateTimeDelay = this.getRefreshTimeInMs();
|
|
248
|
+
this.updateTimeInterval = setInterval(() => {
|
|
249
|
+
this.time = this.live ? new Date() : this.time.getTime() + this.updateTimeDelay * this.speed;
|
|
250
|
+
}, this.updateTimeDelay);
|
|
251
|
+
}
|
|
252
|
+
stop() {
|
|
253
|
+
this.api.unsubscribeTrajectory(this.onTrajectoryMessage);
|
|
254
|
+
this.api.unsubscribeDeletedVehicles(this.onDeleteTrajectoryMessage);
|
|
255
|
+
this.api.close();
|
|
256
|
+
}
|
|
257
|
+
stopUpdateTime() {
|
|
258
|
+
if (this.updateTimeInterval) {
|
|
259
|
+
clearInterval(this.updateTimeInterval);
|
|
548
260
|
}
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
this.debounceRenderTrajectories(viewState, noInterpolate);
|
|
577
|
-
} else if (!noInterpolate && this.useThrottle) {
|
|
578
|
-
this.throttleRenderTrajectories(viewState, noInterpolate);
|
|
579
|
-
} else {
|
|
261
|
+
}
|
|
262
|
+
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
263
|
+
if (!this.tracker) {
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
const time = this.live ? Date.now() : this.time;
|
|
267
|
+
const trajectories = Object.values(this.trajectories);
|
|
268
|
+
if (this.sort) {
|
|
269
|
+
trajectories.sort(this.sort);
|
|
270
|
+
}
|
|
271
|
+
this.renderState = this.tracker.renderTrajectories(trajectories, { ...viewState, pixelRatio: this.pixelRatio, time }, {
|
|
272
|
+
noInterpolate: viewState.zoom < this.minZoomInterpolation ? true : noInterpolate,
|
|
273
|
+
hoverVehicleId: this.hoverVehicleId,
|
|
274
|
+
selectedVehicleId: this.selectedVehicleId,
|
|
275
|
+
iconScale: this.iconScale,
|
|
276
|
+
delayDisplay: this.delayDisplay,
|
|
277
|
+
delayOutlineColor: this.delayOutlineColor
|
|
278
|
+
});
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
renderTrajectories(viewState, noInterpolate) {
|
|
282
|
+
if (this.requestId) {
|
|
283
|
+
cancelAnimationFrame(this.requestId);
|
|
284
|
+
this.requestId = null;
|
|
285
|
+
}
|
|
286
|
+
if (!noInterpolate && this.useRequestAnimationFrame) {
|
|
287
|
+
this.requestId = requestAnimationFrame(() => {
|
|
580
288
|
this.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
581
|
-
}
|
|
289
|
+
});
|
|
290
|
+
} else if (!noInterpolate && this.useDebounce) {
|
|
291
|
+
this.debounceRenderTrajectories(viewState, noInterpolate);
|
|
292
|
+
} else if (!noInterpolate && this.useThrottle) {
|
|
293
|
+
this.throttleRenderTrajectories(viewState, noInterpolate);
|
|
294
|
+
} else {
|
|
295
|
+
this.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
setBbox(extent, zoom) {
|
|
299
|
+
const keys = Object.keys(this.trajectories);
|
|
300
|
+
for (let i = keys.length - 1; i >= 0; i -= 1) {
|
|
301
|
+
this.purgeTrajectory(this.trajectories[keys[i]], extent, zoom);
|
|
582
302
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
// - when it's bus and zoom level is too low for them
|
|
589
|
-
const keys = Object.keys(this.trajectories);
|
|
590
|
-
for (let i = keys.length - 1; i >= 0; i -= 1) {
|
|
591
|
-
this.purgeTrajectory(this.trajectories[keys[i]], extent, zoom);
|
|
303
|
+
const bbox = [...extent];
|
|
304
|
+
if (this.isUpdateBboxOnMoveEnd) {
|
|
305
|
+
bbox.push(zoom);
|
|
306
|
+
if (this.tenant) {
|
|
307
|
+
bbox.push(`tenant=${this.tenant}`);
|
|
592
308
|
}
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
if (this.isUpdateBboxOnMoveEnd) {
|
|
597
|
-
bbox.push(zoom);
|
|
598
|
-
|
|
599
|
-
if (this.tenant) {
|
|
600
|
-
bbox.push(`tenant=${this.tenant}`);
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
/* @ignore */
|
|
604
|
-
this.generalizationLevel = this.generalizationLevelByZoom[zoom];
|
|
605
|
-
if (this.generalizationLevel) {
|
|
606
|
-
bbox.push(`gen=${this.generalizationLevel}`);
|
|
607
|
-
}
|
|
309
|
+
this.generalizationLevel = this.generalizationLevelByZoom[zoom];
|
|
310
|
+
if (this.generalizationLevel) {
|
|
311
|
+
bbox.push(`gen=${this.generalizationLevel}`);
|
|
608
312
|
}
|
|
609
|
-
|
|
610
|
-
this.api.bbox = bbox;
|
|
611
313
|
}
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
this.mode = mode;
|
|
618
|
-
this.api.subscribeTrajectory(
|
|
619
|
-
this.mode,
|
|
620
|
-
this.onTrajectoryMessage,
|
|
621
|
-
this.isUpdateBboxOnMoveEnd,
|
|
622
|
-
);
|
|
623
|
-
this.api.subscribeDeletedVehicles(
|
|
624
|
-
this.mode,
|
|
625
|
-
this.onDeleteTrajectoryMessage,
|
|
626
|
-
this.isUpdateBboxOnMoveEnd,
|
|
627
|
-
);
|
|
314
|
+
this.api.bbox = bbox;
|
|
315
|
+
}
|
|
316
|
+
setMode(mode) {
|
|
317
|
+
if (this.mode === mode) {
|
|
318
|
+
return;
|
|
628
319
|
}
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
if (this.useThrottle) {
|
|
643
|
-
this.throttleRenderTrajectories = throttle(
|
|
644
|
-
this.renderTrajectoriesInternal,
|
|
645
|
-
nextThrottleTick,
|
|
646
|
-
{ leading: true, trailing: true },
|
|
647
|
-
);
|
|
648
|
-
} else if (this.useDebounce) {
|
|
649
|
-
this.debounceRenderTrajectories = debounce(
|
|
650
|
-
this.renderTrajectoriesInternal,
|
|
651
|
-
nextThrottleTick,
|
|
652
|
-
{ leading: true, trailing: true, maxWait: 5000 },
|
|
653
|
-
);
|
|
654
|
-
}
|
|
655
|
-
if (this.api?.buffer) {
|
|
656
|
-
const [, size] = this.api.buffer;
|
|
657
|
-
this.api.buffer = [nextThrottleTick, size];
|
|
658
|
-
}
|
|
659
|
-
return nextTick;
|
|
320
|
+
this.mode = mode;
|
|
321
|
+
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
322
|
+
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
323
|
+
}
|
|
324
|
+
getRefreshTimeInMs(zoom) {
|
|
325
|
+
const roundedZoom = Math.round(zoom);
|
|
326
|
+
const timeStep = timeSteps[roundedZoom] || 25;
|
|
327
|
+
const nextTick = Math.max(25, timeStep / this.speed);
|
|
328
|
+
const nextThrottleTick = Math.min(nextTick, 500);
|
|
329
|
+
if (this.useThrottle) {
|
|
330
|
+
this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true });
|
|
331
|
+
} else if (this.useDebounce) {
|
|
332
|
+
this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true, maxWait: 5e3 });
|
|
660
333
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
* @param {function} filterFc A function use to filter results.
|
|
665
|
-
* @return {Array<Object>} Array of vehicle.
|
|
666
|
-
*/
|
|
667
|
-
getVehicle(filterFc) {
|
|
668
|
-
return Object.values(this.trajectories).filter(filterFc);
|
|
334
|
+
if (this.api?.buffer) {
|
|
335
|
+
const [, size] = this.api.buffer;
|
|
336
|
+
this.api.buffer = [nextThrottleTick, size];
|
|
669
337
|
}
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
let trajectories = Object.values(this.trajectories);
|
|
687
|
-
|
|
688
|
-
if (this.sort) {
|
|
689
|
-
trajectories = trajectories.sort(this.sort);
|
|
338
|
+
return nextTick;
|
|
339
|
+
}
|
|
340
|
+
getVehicle(filterFc) {
|
|
341
|
+
return Object.values(this.trajectories).filter(filterFc);
|
|
342
|
+
}
|
|
343
|
+
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
344
|
+
const { resolution, nb } = options;
|
|
345
|
+
const ext = buffer([...coordinate, ...coordinate], this.hitTolerance * resolution);
|
|
346
|
+
let trajectories = Object.values(this.trajectories);
|
|
347
|
+
if (this.sort) {
|
|
348
|
+
trajectories = trajectories.sort(this.sort);
|
|
349
|
+
}
|
|
350
|
+
const vehicles = [];
|
|
351
|
+
for (let i = 0; i < trajectories.length; i += 1) {
|
|
352
|
+
if (trajectories[i].properties.coordinate && containsCoordinate(ext, trajectories[i].properties.coordinate)) {
|
|
353
|
+
vehicles.push(trajectories[i]);
|
|
690
354
|
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
for (let i = 0; i < trajectories.length; i += 1) {
|
|
694
|
-
if (
|
|
695
|
-
trajectories[i].properties.coordinate &&
|
|
696
|
-
containsCoordinate(ext, trajectories[i].properties.coordinate)
|
|
697
|
-
) {
|
|
698
|
-
vehicles.push(trajectories[i]);
|
|
699
|
-
}
|
|
700
|
-
if (vehicles.length === nb) {
|
|
701
|
-
break;
|
|
702
|
-
}
|
|
355
|
+
if (vehicles.length === nb) {
|
|
356
|
+
break;
|
|
703
357
|
}
|
|
704
|
-
|
|
705
|
-
return Promise.resolve({
|
|
706
|
-
layer: this,
|
|
707
|
-
features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
|
|
708
|
-
coordinate,
|
|
709
|
-
});
|
|
710
358
|
}
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
359
|
+
return Promise.resolve({
|
|
360
|
+
layer: this,
|
|
361
|
+
features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
|
|
362
|
+
coordinate
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
getTrajectoryInfos(id) {
|
|
366
|
+
const promises = [
|
|
367
|
+
this.api.getStopSequence(id, this.mode),
|
|
368
|
+
this.api.getFullTrajectory(id, this.mode, this.generalizationLevel)
|
|
369
|
+
];
|
|
370
|
+
return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
|
|
371
|
+
const response = {
|
|
372
|
+
stopSequence,
|
|
373
|
+
fullTrajectory
|
|
374
|
+
};
|
|
375
|
+
return response;
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
purgeTrajectory(trajectory, extent, zoom) {
|
|
379
|
+
const { type, bounds, train_id: id } = trajectory.properties;
|
|
380
|
+
if (!intersects(extent, bounds) || type !== "rail" && zoom < (this.minZoomNonTrain || 9)) {
|
|
381
|
+
this.removeTrajectory(id);
|
|
382
|
+
return true;
|
|
733
383
|
}
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
* - that are not a train and zoom level is lower than layer's minZoomNonTrain property.
|
|
740
|
-
*
|
|
741
|
-
* @param {TralisTrajectory} trajectory
|
|
742
|
-
* @param {Array<number>} extent
|
|
743
|
-
* @param {number} zoom
|
|
744
|
-
* @return {boolean} if the trajectory must be displayed or not.
|
|
745
|
-
* @ignore
|
|
746
|
-
*/
|
|
747
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
748
|
-
const { type, bounds, train_id: id } = trajectory.properties;
|
|
749
|
-
if (
|
|
750
|
-
!intersects(extent, bounds) ||
|
|
751
|
-
(type !== 'rail' && zoom < (this.minZoomNonTrain || 9))
|
|
752
|
-
) {
|
|
753
|
-
this.removeTrajectory(id);
|
|
754
|
-
return true;
|
|
755
|
-
}
|
|
756
|
-
return false;
|
|
384
|
+
return false;
|
|
385
|
+
}
|
|
386
|
+
addTrajectory(trajectory) {
|
|
387
|
+
if (this.filter && !this.filter(trajectory)) {
|
|
388
|
+
return;
|
|
757
389
|
}
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
390
|
+
this.trajectories[trajectory.properties.train_id] = trajectory;
|
|
391
|
+
this.renderTrajectories();
|
|
392
|
+
}
|
|
393
|
+
removeTrajectory(id) {
|
|
394
|
+
delete this.trajectories[id];
|
|
395
|
+
}
|
|
396
|
+
onZoomEnd(evt) {
|
|
397
|
+
this.startUpdateTime();
|
|
398
|
+
}
|
|
399
|
+
onDocumentVisibilityChange() {
|
|
400
|
+
if (!this.visible) {
|
|
401
|
+
return;
|
|
770
402
|
}
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
403
|
+
if (document.hidden) {
|
|
404
|
+
this.stop();
|
|
405
|
+
} else {
|
|
406
|
+
this.start();
|
|
774
407
|
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
* @param evt Event that triggered the function.
|
|
780
|
-
* @private
|
|
781
|
-
*/
|
|
782
|
-
// eslint-disable-next-line no-unused-vars
|
|
783
|
-
onZoomEnd(evt) {
|
|
784
|
-
this.startUpdateTime();
|
|
408
|
+
}
|
|
409
|
+
onTrajectoryMessage(data) {
|
|
410
|
+
if (!data.content) {
|
|
411
|
+
return;
|
|
785
412
|
}
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
} else {
|
|
794
|
-
this.start();
|
|
413
|
+
const trajectory = data.content;
|
|
414
|
+
const {
|
|
415
|
+
geometry,
|
|
416
|
+
properties: {
|
|
417
|
+
train_id: id,
|
|
418
|
+
time_since_update: timeSinceUpdate,
|
|
419
|
+
raw_coordinates: rawCoordinates
|
|
795
420
|
}
|
|
421
|
+
} = trajectory;
|
|
422
|
+
if (timeSinceUpdate < 0) {
|
|
423
|
+
return;
|
|
796
424
|
}
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
* Callback on websocket's trajectory channel events.
|
|
800
|
-
* It adds a trajectory to the list.
|
|
801
|
-
*
|
|
802
|
-
* @private
|
|
803
|
-
*/
|
|
804
|
-
onTrajectoryMessage(data) {
|
|
805
|
-
if (!data.content) {
|
|
806
|
-
return;
|
|
807
|
-
}
|
|
808
|
-
const trajectory = data.content;
|
|
809
|
-
|
|
810
|
-
const {
|
|
811
|
-
geometry,
|
|
812
|
-
properties: {
|
|
813
|
-
train_id: id,
|
|
814
|
-
time_since_update: timeSinceUpdate,
|
|
815
|
-
raw_coordinates: rawCoordinates,
|
|
816
|
-
},
|
|
817
|
-
} = trajectory;
|
|
818
|
-
|
|
819
|
-
// ignore old events [SBAHNM-97]
|
|
820
|
-
if (timeSinceUpdate < 0) {
|
|
821
|
-
return;
|
|
822
|
-
}
|
|
823
|
-
|
|
824
|
-
// console.time(`onTrajectoryMessage${data.content.properties.train_id}`);
|
|
825
|
-
if (this.purgeTrajectory(trajectory)) {
|
|
826
|
-
return;
|
|
827
|
-
}
|
|
828
|
-
|
|
829
|
-
if (
|
|
830
|
-
this.debug &&
|
|
831
|
-
this.mode === TralisModes.TOPOGRAPHIC &&
|
|
832
|
-
rawCoordinates
|
|
833
|
-
) {
|
|
834
|
-
trajectory.properties.olGeometry = {
|
|
835
|
-
type: 'Point',
|
|
836
|
-
coordinates: fromLonLat(
|
|
837
|
-
rawCoordinates,
|
|
838
|
-
this.map.getView().getProjection(),
|
|
839
|
-
),
|
|
840
|
-
};
|
|
841
|
-
} else {
|
|
842
|
-
trajectory.properties.olGeometry = this.format.readGeometry(geometry);
|
|
843
|
-
}
|
|
844
|
-
|
|
845
|
-
// TODO Make sure the timeOffset is useful. May be we can remove it.
|
|
846
|
-
trajectory.properties.timeOffset = Date.now() - data.timestamp;
|
|
847
|
-
this.addTrajectory(trajectory);
|
|
425
|
+
if (this.purgeTrajectory(trajectory)) {
|
|
426
|
+
return;
|
|
848
427
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
*/
|
|
857
|
-
onDeleteTrajectoryMessage(data) {
|
|
858
|
-
if (!data.content) {
|
|
859
|
-
return;
|
|
860
|
-
}
|
|
861
|
-
|
|
862
|
-
this.removeTrajectory(data.content);
|
|
428
|
+
if (this.debug && this.mode === TralisModes.TOPOGRAPHIC && rawCoordinates) {
|
|
429
|
+
trajectory.properties.olGeometry = {
|
|
430
|
+
type: "Point",
|
|
431
|
+
coordinates: fromLonLat(rawCoordinates, this.map.getView().getProjection())
|
|
432
|
+
};
|
|
433
|
+
} else {
|
|
434
|
+
trajectory.properties.olGeometry = this.format.readGeometry(geometry);
|
|
863
435
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
* @override
|
|
871
|
-
*/
|
|
872
|
-
onFeatureHover(features, layer, coordinate) {
|
|
873
|
-
const [feature] = features;
|
|
874
|
-
let id = null;
|
|
875
|
-
if (feature) {
|
|
876
|
-
id = feature.get('train_id');
|
|
877
|
-
}
|
|
878
|
-
if (this.hoverVehicleId !== id) {
|
|
879
|
-
/** @ignore */
|
|
880
|
-
this.hoverVehicleId = id;
|
|
881
|
-
this.renderTrajectories(true);
|
|
882
|
-
}
|
|
436
|
+
trajectory.properties.timeOffset = Date.now() - data.timestamp;
|
|
437
|
+
this.addTrajectory(trajectory);
|
|
438
|
+
}
|
|
439
|
+
onDeleteTrajectoryMessage(data) {
|
|
440
|
+
if (!data.content) {
|
|
441
|
+
return;
|
|
883
442
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
*/
|
|
892
|
-
onFeatureClick(features, layer, coordinate) {
|
|
893
|
-
const [feature] = features;
|
|
894
|
-
let id = null;
|
|
895
|
-
if (feature) {
|
|
896
|
-
id = feature.get('train_id');
|
|
897
|
-
}
|
|
898
|
-
if (this.selectedVehicleId !== id) {
|
|
899
|
-
/** @ignore */
|
|
900
|
-
this.selectedVehicleId = id;
|
|
901
|
-
this.selectedVehicle = feature;
|
|
902
|
-
this.renderTrajectories(true);
|
|
903
|
-
}
|
|
443
|
+
this.removeTrajectory(data.content);
|
|
444
|
+
}
|
|
445
|
+
onFeatureHover(features, layer, coordinate) {
|
|
446
|
+
const [feature] = features;
|
|
447
|
+
let id = null;
|
|
448
|
+
if (feature) {
|
|
449
|
+
id = feature.get("train_id");
|
|
904
450
|
}
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
451
|
+
if (this.hoverVehicleId !== id) {
|
|
452
|
+
this.hoverVehicleId = id;
|
|
453
|
+
this.renderTrajectories(true);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
onFeatureClick(features, layer, coordinate) {
|
|
457
|
+
const [feature] = features;
|
|
458
|
+
let id = null;
|
|
459
|
+
if (feature) {
|
|
460
|
+
id = feature.get("train_id");
|
|
461
|
+
}
|
|
462
|
+
if (this.selectedVehicleId !== id) {
|
|
463
|
+
this.selectedVehicleId = id;
|
|
464
|
+
this.selectedVehicle = feature;
|
|
465
|
+
this.renderTrajectories(true);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
updateFilters() {
|
|
469
|
+
const parameters = qs.parse(window.location.search.toLowerCase());
|
|
470
|
+
const publishedName = this.publishedLineName || parameters[LINE_FILTER];
|
|
471
|
+
const tripNumber = this.tripNumber || parameters[ROUTE_FILTER];
|
|
472
|
+
const operator = this.operator || parameters[OPERATOR_FILTER];
|
|
473
|
+
const { regexPublishedLineName } = this;
|
|
474
|
+
if (publishedName || tripNumber || operator || regexPublishedLineName) {
|
|
475
|
+
this.filter = createFilters(publishedName, tripNumber, operator, regexPublishedLineName);
|
|
927
476
|
}
|
|
928
|
-
}
|
|
929
|
-
|
|
477
|
+
}
|
|
478
|
+
};
|
|
930
479
|
export default TralisLayerMixin;
|