mobility-toolbox-js 2.0.0-beta.32 → 2.0.0-beta.33
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/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/{index.js → index.d.ts} +1 -0
- package/common/index.d.ts.map +1 -0
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/styles/{index.js → index.d.ts} +1 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.d.ts +11 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/{index.js → index.d.ts} +3 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/{index.js → index.d.ts} +1 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/{index.js → index.d.ts} +1 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/{index.js → index.d.ts} +1 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mbt.js +2049 -2106
- package/mbt.js.map +3 -3
- package/mbt.min.js +18 -18
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/{index.js → index.d.ts} +1 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/{index.js → index.d.ts} +1 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/{index.js → index.d.ts} +1 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/{index.js → index.d.ts} +1 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +14 -36
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/types/index.d.ts +7 -6
- package/types/routing.d.ts +25 -25
- package/types/stops.d.ts +19 -19
- package/api/RealtimeAPI.js +0 -357
- package/api/RealtimeAPI.test.js +0 -67
- package/api/RoutingAPI.js +0 -15
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.js +0 -12
- package/api/StopsAPI.test.js +0 -22
- package/api/index.js +0 -3
- package/api/typedefs.js +0 -0
- package/common/api/HttpAPI.js +0 -32
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.js +0 -175
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -140
- package/common/layers/Layer.test.js +0 -134
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/RealtimeLayerMixin.js +0 -436
- package/common/mixins/StopFinderMixin.js +0 -110
- package/common/mixins/UserInteractionsLayerMixin.js +0 -124
- package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
- package/common/styles/realtimeDefaultStyle.js +0 -202
- package/common/styles/realtimeDelayStyle.js +0 -8
- package/common/styles/realtimeSimpleStyle.js +0 -18
- package/common/typedefs.js +0 -0
- package/common/utils/cleanStopTime.js +0 -19
- package/common/utils/compareDepartures.js +0 -25
- package/common/utils/createCanvas.js +0 -17
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getLayersAsFlatArray.js +0 -14
- package/common/utils/getMapboxMapCopyrights.js +0 -19
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getRealtimeModeSuffix.js +0 -2
- package/common/utils/getUrlWithParams.js +0 -11
- package/common/utils/getVehiclePosition.js +0 -42
- package/common/utils/removeDuplicate.js +0 -8
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/renderTrajectories.js +0 -86
- package/common/utils/sortByDelay.js +0 -18
- package/common/utils/timeUtils.js +0 -20
- package/common/utils/timeUtils.test.js +0 -10
- package/common/utils/trackerConfig.js +0 -129
- package/common/utils/trackerConfig.test.js +0 -23
- package/index.js +0 -8
- package/mapbox/controls/CopyrightControl.js +0 -29
- package/mapbox/layers/Layer.js +0 -56
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/RealtimeLayer.js +0 -185
- package/mapbox/layers/RealtimeLayer.test.js +0 -10
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.js +0 -42
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.js +0 -388
- package/ol/controls/RoutingControl.test.js +0 -146
- package/ol/controls/StopFinderControl.js +0 -10
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.js +0 -83
- package/ol/layers/Layer.test.js +0 -175
- package/ol/layers/MapboxLayer.js +0 -204
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.js +0 -187
- package/ol/layers/MapboxStyleLayer.test.js +0 -226
- package/ol/layers/MaplibreLayer.js +0 -140
- package/ol/layers/RealtimeLayer.js +0 -187
- package/ol/layers/RealtimeLayer.test.js +0 -67
- package/ol/layers/RoutingLayer.js +0 -61
- package/ol/layers/RoutingLayer.test.js +0 -39
- package/ol/layers/VectorLayer.js +0 -22
- package/ol/layers/VectorLayer.test.js +0 -76
- package/ol/layers/WMSLayer.js +0 -38
- package/ol/layers/WMSLayer.test.js +0 -57
- package/ol/styles/fullTrajectoryDelayStyle.js +0 -31
- package/ol/styles/fullTrajectoryStyle.js +0 -42
|
@@ -1,436 +0,0 @@
|
|
|
1
|
-
import { buffer, containsCoordinate, intersects } from "ol/extent";
|
|
2
|
-
import { unByKey } from "ol/Observable";
|
|
3
|
-
import GeoJSON from "ol/format/GeoJSON";
|
|
4
|
-
import debounce from "lodash.debounce";
|
|
5
|
-
import throttle from "lodash.throttle";
|
|
6
|
-
import { fromLonLat } from "ol/proj";
|
|
7
|
-
import realtimeDefaultStyle from "../styles/realtimeDefaultStyle";
|
|
8
|
-
import { RealtimeAPI, RealtimeModes } from "../../api";
|
|
9
|
-
import renderTrajectories from "../utils/renderTrajectories";
|
|
10
|
-
import * as trackerConfig from "../utils/trackerConfig";
|
|
11
|
-
export class RealtimeLayerInterface {
|
|
12
|
-
constructor(options = {}) {
|
|
13
|
-
}
|
|
14
|
-
attachToMap(map) {
|
|
15
|
-
}
|
|
16
|
-
detachFromMap() {
|
|
17
|
-
}
|
|
18
|
-
start() {
|
|
19
|
-
}
|
|
20
|
-
stop() {
|
|
21
|
-
}
|
|
22
|
-
setBbox(extent, zoom) {
|
|
23
|
-
}
|
|
24
|
-
setMode(mode) {
|
|
25
|
-
}
|
|
26
|
-
getTrajectoryInfos(id, mode) {
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
const RealtimeLayerMixin = (Base) => class extends Base {
|
|
30
|
-
constructor(options = {}) {
|
|
31
|
-
super({
|
|
32
|
-
hitTolerance: 10,
|
|
33
|
-
...options
|
|
34
|
-
});
|
|
35
|
-
this.debug = options.debug;
|
|
36
|
-
this.mode = options.mode || RealtimeModes.TOPOGRAPHIC;
|
|
37
|
-
this.api = options.api || new RealtimeAPI(options);
|
|
38
|
-
this.tenant = options.tenant || "";
|
|
39
|
-
this.minZoomNonTrain = options.minZoomNonTrain || 9;
|
|
40
|
-
this.minZoomInterpolation = options.minZoomInterpolation || 8;
|
|
41
|
-
this.format = new GeoJSON();
|
|
42
|
-
this.generalizationLevelByZoom = options.generalizationLevelByZoom || [
|
|
43
|
-
5,
|
|
44
|
-
5,
|
|
45
|
-
5,
|
|
46
|
-
5,
|
|
47
|
-
5,
|
|
48
|
-
5,
|
|
49
|
-
5,
|
|
50
|
-
5,
|
|
51
|
-
10,
|
|
52
|
-
30,
|
|
53
|
-
30,
|
|
54
|
-
100,
|
|
55
|
-
100,
|
|
56
|
-
100
|
|
57
|
-
];
|
|
58
|
-
this.getGeneralizationLevelByZoom = (zoom) => {
|
|
59
|
-
return options.getGeneralizationLevelByZoom && options.getGeneralizationLevelByZoom(zoom, this.generalizationLevelByZoom) || this.generalizationLevelByZoom[zoom];
|
|
60
|
-
};
|
|
61
|
-
this.renderTimeIntervalByZoom = options.renderTimeIntervalByZoom || [
|
|
62
|
-
1e5,
|
|
63
|
-
5e4,
|
|
64
|
-
4e4,
|
|
65
|
-
3e4,
|
|
66
|
-
2e4,
|
|
67
|
-
15e3,
|
|
68
|
-
1e4,
|
|
69
|
-
5e3,
|
|
70
|
-
2e3,
|
|
71
|
-
1e3,
|
|
72
|
-
400,
|
|
73
|
-
300,
|
|
74
|
-
250,
|
|
75
|
-
180,
|
|
76
|
-
90,
|
|
77
|
-
60,
|
|
78
|
-
50,
|
|
79
|
-
50,
|
|
80
|
-
50,
|
|
81
|
-
50,
|
|
82
|
-
50
|
|
83
|
-
];
|
|
84
|
-
this.getRenderTimeIntervalByZoom = (zoom) => {
|
|
85
|
-
return options.getRenderTimeIntervalByZoom && options.getRenderTimeIntervalByZoom(zoom, this.renderTimeIntervalByZoom) || this.renderTimeIntervalByZoom[zoom];
|
|
86
|
-
};
|
|
87
|
-
this.isUpdateBboxOnMoveEnd = options.isUpdateBboxOnMoveEnd !== false;
|
|
88
|
-
this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, 50, { leading: false, trailing: true });
|
|
89
|
-
this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, 50, { leading: true, trailing: true, maxWait: 5e3 });
|
|
90
|
-
this.onFeatureHover = this.onFeatureHover.bind(this);
|
|
91
|
-
this.onFeatureClick = this.onFeatureClick.bind(this);
|
|
92
|
-
this.renderTrajectoriesInternal = this.renderTrajectoriesInternal.bind(this);
|
|
93
|
-
this.onTrajectoryMessage = this.onTrajectoryMessage.bind(this);
|
|
94
|
-
this.onDeleteTrajectoryMessage = this.onDeleteTrajectoryMessage.bind(this);
|
|
95
|
-
this.onDocumentVisibilityChange = this.onDocumentVisibilityChange.bind(this);
|
|
96
|
-
}
|
|
97
|
-
defineProperties(options) {
|
|
98
|
-
const {
|
|
99
|
-
style,
|
|
100
|
-
speed,
|
|
101
|
-
pixelRatio,
|
|
102
|
-
hoverVehicleId,
|
|
103
|
-
selectedVehicleId,
|
|
104
|
-
filter,
|
|
105
|
-
sort,
|
|
106
|
-
time,
|
|
107
|
-
live,
|
|
108
|
-
canvas,
|
|
109
|
-
styleOptions
|
|
110
|
-
} = options;
|
|
111
|
-
let currSpeed = speed || 1;
|
|
112
|
-
let currTime = time || new Date();
|
|
113
|
-
super.defineProperties(options);
|
|
114
|
-
Object.defineProperties(this, {
|
|
115
|
-
isTrackerLayer: { value: true },
|
|
116
|
-
canvas: {
|
|
117
|
-
value: canvas || document.createElement("canvas")
|
|
118
|
-
},
|
|
119
|
-
style: {
|
|
120
|
-
value: style || realtimeDefaultStyle
|
|
121
|
-
},
|
|
122
|
-
styleOptions: {
|
|
123
|
-
value: { ...trackerConfig, ...styleOptions || {} }
|
|
124
|
-
},
|
|
125
|
-
speed: {
|
|
126
|
-
get: () => currSpeed,
|
|
127
|
-
set: (newSpeed) => {
|
|
128
|
-
currSpeed = newSpeed;
|
|
129
|
-
this.start();
|
|
130
|
-
}
|
|
131
|
-
},
|
|
132
|
-
filter: {
|
|
133
|
-
value: filter,
|
|
134
|
-
writable: true
|
|
135
|
-
},
|
|
136
|
-
sort: {
|
|
137
|
-
value: sort,
|
|
138
|
-
writable: true
|
|
139
|
-
},
|
|
140
|
-
live: {
|
|
141
|
-
value: live === false ? live : true,
|
|
142
|
-
writable: true
|
|
143
|
-
},
|
|
144
|
-
time: {
|
|
145
|
-
get: () => currTime,
|
|
146
|
-
set: (newTime) => {
|
|
147
|
-
currTime = newTime && newTime.getTime ? newTime : new Date(newTime);
|
|
148
|
-
this.renderTrajectories();
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
trajectories: {
|
|
152
|
-
value: {},
|
|
153
|
-
writable: true
|
|
154
|
-
},
|
|
155
|
-
hoverVehicleId: {
|
|
156
|
-
value: hoverVehicleId,
|
|
157
|
-
writable: true
|
|
158
|
-
},
|
|
159
|
-
selectedVehicleId: {
|
|
160
|
-
value: selectedVehicleId,
|
|
161
|
-
writable: true
|
|
162
|
-
},
|
|
163
|
-
pixelRatio: {
|
|
164
|
-
value: pixelRatio || (typeof window !== "undefined" ? window.devicePixelRatio : 1),
|
|
165
|
-
writable: true
|
|
166
|
-
},
|
|
167
|
-
useRequestAnimationFrame: {
|
|
168
|
-
value: options.useRequestAnimationFrame || false,
|
|
169
|
-
writable: true
|
|
170
|
-
},
|
|
171
|
-
useThrottle: {
|
|
172
|
-
value: options.useThrottle !== false,
|
|
173
|
-
writable: true
|
|
174
|
-
},
|
|
175
|
-
useDebounce: {
|
|
176
|
-
value: options.useDebounce || false,
|
|
177
|
-
writable: true
|
|
178
|
-
}
|
|
179
|
-
});
|
|
180
|
-
}
|
|
181
|
-
attachToMap(map) {
|
|
182
|
-
super.attachToMap(map);
|
|
183
|
-
if (this.visible) {
|
|
184
|
-
this.start();
|
|
185
|
-
}
|
|
186
|
-
this.visibilityRef = this.on("change:visible", (evt) => {
|
|
187
|
-
if (evt.target.visible) {
|
|
188
|
-
this.start();
|
|
189
|
-
} else {
|
|
190
|
-
this.stop();
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
document.addEventListener("visibilitychange", this.onDocumentVisibilityChange);
|
|
194
|
-
}
|
|
195
|
-
detachFromMap() {
|
|
196
|
-
document.removeEventListener("visibilitychange", this.onDocumentVisibilityChange);
|
|
197
|
-
this.stop();
|
|
198
|
-
unByKey(this.visibilityRef);
|
|
199
|
-
const context = this.canvas.getContext("2d");
|
|
200
|
-
context.clearRect(0, 0, this.canvas.width, this.canvas.height);
|
|
201
|
-
super.detachFromMap();
|
|
202
|
-
}
|
|
203
|
-
start() {
|
|
204
|
-
this.stop();
|
|
205
|
-
this.renderTrajectories();
|
|
206
|
-
this.startUpdateTime();
|
|
207
|
-
this.api.open();
|
|
208
|
-
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
209
|
-
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
210
|
-
if (this.isUpdateBboxOnMoveEnd) {
|
|
211
|
-
this.setBbox();
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
startUpdateTime() {
|
|
215
|
-
this.stopUpdateTime();
|
|
216
|
-
this.updateTimeDelay = this.getRefreshTimeInMs();
|
|
217
|
-
this.updateTimeInterval = setInterval(() => {
|
|
218
|
-
this.time = this.live ? new Date() : this.time.getTime() + this.updateTimeDelay * this.speed;
|
|
219
|
-
}, this.updateTimeDelay);
|
|
220
|
-
}
|
|
221
|
-
stop() {
|
|
222
|
-
this.api.unsubscribeTrajectory(this.onTrajectoryMessage);
|
|
223
|
-
this.api.unsubscribeDeletedVehicles(this.onDeleteTrajectoryMessage);
|
|
224
|
-
this.api.close();
|
|
225
|
-
}
|
|
226
|
-
stopUpdateTime() {
|
|
227
|
-
if (this.updateTimeInterval) {
|
|
228
|
-
clearInterval(this.updateTimeInterval);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
renderTrajectoriesInternal(viewState, noInterpolate) {
|
|
232
|
-
if (!this.map) {
|
|
233
|
-
return false;
|
|
234
|
-
}
|
|
235
|
-
const time = this.live ? Date.now() : this.time;
|
|
236
|
-
const trajectories = Object.values(this.trajectories);
|
|
237
|
-
if (this.sort) {
|
|
238
|
-
trajectories.sort(this.sort);
|
|
239
|
-
}
|
|
240
|
-
this.renderState = renderTrajectories(this.canvas, trajectories, this.style, { ...viewState, pixelRatio: this.pixelRatio, time }, {
|
|
241
|
-
noInterpolate: viewState.zoom < this.minZoomInterpolation ? true : noInterpolate,
|
|
242
|
-
hoverVehicleId: this.hoverVehicleId,
|
|
243
|
-
selectedVehicleId: this.selectedVehicleId,
|
|
244
|
-
...this.styleOptions
|
|
245
|
-
});
|
|
246
|
-
return true;
|
|
247
|
-
}
|
|
248
|
-
renderTrajectories(viewState, noInterpolate) {
|
|
249
|
-
if (this.requestId) {
|
|
250
|
-
cancelAnimationFrame(this.requestId);
|
|
251
|
-
this.requestId = null;
|
|
252
|
-
}
|
|
253
|
-
if (!noInterpolate && this.useRequestAnimationFrame) {
|
|
254
|
-
this.requestId = requestAnimationFrame(() => {
|
|
255
|
-
this.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
256
|
-
});
|
|
257
|
-
} else if (!noInterpolate && this.useDebounce) {
|
|
258
|
-
this.debounceRenderTrajectories(viewState, noInterpolate);
|
|
259
|
-
} else if (!noInterpolate && this.useThrottle) {
|
|
260
|
-
this.throttleRenderTrajectories(viewState, noInterpolate);
|
|
261
|
-
} else {
|
|
262
|
-
this.renderTrajectoriesInternal(viewState, noInterpolate);
|
|
263
|
-
}
|
|
264
|
-
}
|
|
265
|
-
setBbox(extent, zoom) {
|
|
266
|
-
const keys = Object.keys(this.trajectories);
|
|
267
|
-
for (let i = keys.length - 1; i >= 0; i -= 1) {
|
|
268
|
-
this.purgeTrajectory(this.trajectories[keys[i]], extent, zoom);
|
|
269
|
-
}
|
|
270
|
-
const bbox = [...extent];
|
|
271
|
-
if (this.isUpdateBboxOnMoveEnd) {
|
|
272
|
-
bbox.push(zoom);
|
|
273
|
-
if (this.tenant) {
|
|
274
|
-
bbox.push(`tenant=${this.tenant}`);
|
|
275
|
-
}
|
|
276
|
-
this.generalizationLevel = this.getGeneralizationLevelByZoom(zoom);
|
|
277
|
-
if (this.generalizationLevel) {
|
|
278
|
-
bbox.push(`gen=${this.generalizationLevel}`);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
this.api.bbox = bbox;
|
|
282
|
-
}
|
|
283
|
-
setMode(mode) {
|
|
284
|
-
if (this.mode === mode) {
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
this.mode = mode;
|
|
288
|
-
this.api.subscribeTrajectory(this.mode, this.onTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
289
|
-
this.api.subscribeDeletedVehicles(this.mode, this.onDeleteTrajectoryMessage, this.isUpdateBboxOnMoveEnd);
|
|
290
|
-
}
|
|
291
|
-
getRefreshTimeInMs(zoom) {
|
|
292
|
-
const roundedZoom = Math.round(zoom);
|
|
293
|
-
const timeStep = this.getRenderTimeIntervalByZoom(roundedZoom) || 25;
|
|
294
|
-
const nextTick = Math.max(25, timeStep / this.speed);
|
|
295
|
-
const nextThrottleTick = Math.min(nextTick, 500);
|
|
296
|
-
if (this.useThrottle) {
|
|
297
|
-
this.throttleRenderTrajectories = throttle(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true });
|
|
298
|
-
} else if (this.useDebounce) {
|
|
299
|
-
this.debounceRenderTrajectories = debounce(this.renderTrajectoriesInternal, nextThrottleTick, { leading: true, trailing: true, maxWait: 5e3 });
|
|
300
|
-
}
|
|
301
|
-
if (this.api?.buffer) {
|
|
302
|
-
const [, size] = this.api.buffer;
|
|
303
|
-
this.api.buffer = [nextThrottleTick, size];
|
|
304
|
-
}
|
|
305
|
-
return nextTick;
|
|
306
|
-
}
|
|
307
|
-
getVehicle(filterFc) {
|
|
308
|
-
return Object.values(this.trajectories).filter(filterFc);
|
|
309
|
-
}
|
|
310
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
311
|
-
const { resolution, nb } = options;
|
|
312
|
-
const ext = buffer([...coordinate, ...coordinate], this.hitTolerance * resolution);
|
|
313
|
-
let trajectories = Object.values(this.trajectories);
|
|
314
|
-
if (this.sort) {
|
|
315
|
-
trajectories = trajectories.sort(this.sort);
|
|
316
|
-
}
|
|
317
|
-
const vehicles = [];
|
|
318
|
-
for (let i = 0; i < trajectories.length; i += 1) {
|
|
319
|
-
if (trajectories[i].properties.coordinate && containsCoordinate(ext, trajectories[i].properties.coordinate)) {
|
|
320
|
-
vehicles.push(trajectories[i]);
|
|
321
|
-
}
|
|
322
|
-
if (vehicles.length === nb) {
|
|
323
|
-
break;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
return Promise.resolve({
|
|
327
|
-
layer: this,
|
|
328
|
-
features: vehicles.map((vehicle) => this.format.readFeature(vehicle)),
|
|
329
|
-
coordinate
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
getTrajectoryInfos(id) {
|
|
333
|
-
const promises = [
|
|
334
|
-
this.api.getStopSequence(id, this.mode),
|
|
335
|
-
this.api.getFullTrajectory(id, this.mode, this.generalizationLevel)
|
|
336
|
-
];
|
|
337
|
-
return Promise.all(promises).then(([stopSequence, fullTrajectory]) => {
|
|
338
|
-
const response = {
|
|
339
|
-
stopSequence,
|
|
340
|
-
fullTrajectory
|
|
341
|
-
};
|
|
342
|
-
return response;
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
346
|
-
const { type, bounds, train_id: id } = trajectory.properties;
|
|
347
|
-
if (!intersects(extent, bounds) || type !== "rail" && zoom < (this.minZoomNonTrain || 9)) {
|
|
348
|
-
this.removeTrajectory(id);
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
return false;
|
|
352
|
-
}
|
|
353
|
-
addTrajectory(trajectory) {
|
|
354
|
-
if (this.filter && !this.filter(trajectory)) {
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
this.trajectories[trajectory.properties.train_id] = trajectory;
|
|
358
|
-
this.renderTrajectories();
|
|
359
|
-
}
|
|
360
|
-
removeTrajectory(id) {
|
|
361
|
-
delete this.trajectories[id];
|
|
362
|
-
}
|
|
363
|
-
onZoomEnd(evt) {
|
|
364
|
-
this.startUpdateTime();
|
|
365
|
-
}
|
|
366
|
-
onDocumentVisibilityChange() {
|
|
367
|
-
if (!this.visible) {
|
|
368
|
-
return;
|
|
369
|
-
}
|
|
370
|
-
if (document.hidden) {
|
|
371
|
-
this.stop();
|
|
372
|
-
} else {
|
|
373
|
-
this.start();
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
onTrajectoryMessage(data) {
|
|
377
|
-
if (!data.content) {
|
|
378
|
-
return;
|
|
379
|
-
}
|
|
380
|
-
const trajectory = data.content;
|
|
381
|
-
const {
|
|
382
|
-
geometry,
|
|
383
|
-
properties: {
|
|
384
|
-
train_id: id,
|
|
385
|
-
time_since_update: timeSinceUpdate,
|
|
386
|
-
raw_coordinates: rawCoordinates
|
|
387
|
-
}
|
|
388
|
-
} = trajectory;
|
|
389
|
-
if (timeSinceUpdate < 0) {
|
|
390
|
-
return;
|
|
391
|
-
}
|
|
392
|
-
if (this.purgeTrajectory(trajectory)) {
|
|
393
|
-
return;
|
|
394
|
-
}
|
|
395
|
-
if (this.debug && this.mode === RealtimeModes.TOPOGRAPHIC && rawCoordinates) {
|
|
396
|
-
trajectory.properties.olGeometry = {
|
|
397
|
-
type: "Point",
|
|
398
|
-
coordinates: fromLonLat(rawCoordinates, this.map.getView().getProjection())
|
|
399
|
-
};
|
|
400
|
-
} else {
|
|
401
|
-
trajectory.properties.olGeometry = this.format.readGeometry(geometry);
|
|
402
|
-
}
|
|
403
|
-
trajectory.properties.timeOffset = Date.now() - data.timestamp;
|
|
404
|
-
this.addTrajectory(trajectory);
|
|
405
|
-
}
|
|
406
|
-
onDeleteTrajectoryMessage(data) {
|
|
407
|
-
if (!data.content) {
|
|
408
|
-
return;
|
|
409
|
-
}
|
|
410
|
-
this.removeTrajectory(data.content);
|
|
411
|
-
}
|
|
412
|
-
onFeatureHover(features, layer, coordinate) {
|
|
413
|
-
const [feature] = features;
|
|
414
|
-
let id = null;
|
|
415
|
-
if (feature) {
|
|
416
|
-
id = feature.get("train_id");
|
|
417
|
-
}
|
|
418
|
-
if (this.hoverVehicleId !== id) {
|
|
419
|
-
this.hoverVehicleId = id;
|
|
420
|
-
this.renderTrajectories(true);
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
onFeatureClick(features, layer, coordinate) {
|
|
424
|
-
const [feature] = features;
|
|
425
|
-
let id = null;
|
|
426
|
-
if (feature) {
|
|
427
|
-
id = feature.get("train_id");
|
|
428
|
-
}
|
|
429
|
-
if (this.selectedVehicleId !== id) {
|
|
430
|
-
this.selectedVehicleId = id;
|
|
431
|
-
this.selectedVehicle = feature;
|
|
432
|
-
this.renderTrajectories(true);
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
export default RealtimeLayerMixin;
|
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { StopsAPI } from "../../api";
|
|
2
|
-
export class StopFinderInterface {
|
|
3
|
-
constructor(options = {}) {
|
|
4
|
-
}
|
|
5
|
-
search(query, abortController) {
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
const StopFinderMixin = (Base) => class extends Base {
|
|
9
|
-
constructor(options = {}) {
|
|
10
|
-
super(options);
|
|
11
|
-
const { apiParams, apiKey, url } = options;
|
|
12
|
-
this.apiParams = { limit: 20, ...apiParams || {} };
|
|
13
|
-
this.placeholder = options.placeholder || "Search for a stop...";
|
|
14
|
-
const apiOptions = { apiKey };
|
|
15
|
-
if (url) {
|
|
16
|
-
apiOptions.url = url;
|
|
17
|
-
}
|
|
18
|
-
this.api = new StopsAPI(apiOptions);
|
|
19
|
-
this.abortController = new AbortController();
|
|
20
|
-
}
|
|
21
|
-
render(featureCollection) {
|
|
22
|
-
const suggestions = featureCollection?.features || [];
|
|
23
|
-
if (!this.suggestionsElt) {
|
|
24
|
-
return;
|
|
25
|
-
}
|
|
26
|
-
this.suggestionsElt.style.display = suggestions.length ? "block" : "none";
|
|
27
|
-
this.suggestionsElt.innerHTML = "";
|
|
28
|
-
suggestions.forEach((suggestion) => {
|
|
29
|
-
const { properties } = suggestion;
|
|
30
|
-
const suggElt = document.createElement("div");
|
|
31
|
-
suggElt.innerHTML = properties.name;
|
|
32
|
-
suggElt.onclick = () => {
|
|
33
|
-
this.onSuggestionClick(suggestion);
|
|
34
|
-
};
|
|
35
|
-
Object.assign(suggElt.style, {
|
|
36
|
-
padding: "5px 12px"
|
|
37
|
-
});
|
|
38
|
-
this.suggestionsElt.appendChild(suggElt);
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
createDefaultElement() {
|
|
42
|
-
this.element = document.createElement("div");
|
|
43
|
-
this.element.id = "mbt-search";
|
|
44
|
-
Object.assign(this.element.style, {
|
|
45
|
-
position: "absolute",
|
|
46
|
-
top: 0,
|
|
47
|
-
left: "50px",
|
|
48
|
-
margin: "10px",
|
|
49
|
-
display: "flex",
|
|
50
|
-
flexDirection: "column",
|
|
51
|
-
width: "320px"
|
|
52
|
-
});
|
|
53
|
-
this.inputElt = document.createElement("input");
|
|
54
|
-
this.inputElt.type = "text";
|
|
55
|
-
this.inputElt.placeholder = this.placeholder;
|
|
56
|
-
this.inputElt.autoComplete = "off";
|
|
57
|
-
this.inputElt.onkeyup = (evt) => {
|
|
58
|
-
this.abortController.abort();
|
|
59
|
-
this.abortController = new AbortController();
|
|
60
|
-
this.search(evt.target.value, this.abortController);
|
|
61
|
-
};
|
|
62
|
-
Object.assign(this.inputElt.style, {
|
|
63
|
-
padding: "10px 30px 10px 10px"
|
|
64
|
-
});
|
|
65
|
-
this.element.appendChild(this.inputElt);
|
|
66
|
-
this.suggestionsElt = document.createElement("div");
|
|
67
|
-
Object.assign(this.suggestionsElt.style, {
|
|
68
|
-
backgroundColor: "white",
|
|
69
|
-
overflowY: "auto",
|
|
70
|
-
cursor: "pointer"
|
|
71
|
-
});
|
|
72
|
-
this.element.appendChild(this.suggestionsElt);
|
|
73
|
-
this.clearElt = document.createElement("div");
|
|
74
|
-
Object.assign(this.clearElt.style, {
|
|
75
|
-
display: "none",
|
|
76
|
-
position: "absolute",
|
|
77
|
-
right: "0",
|
|
78
|
-
padding: "0 10px",
|
|
79
|
-
fontSize: "200%",
|
|
80
|
-
cursor: "pointer"
|
|
81
|
-
});
|
|
82
|
-
this.clearElt.innerHTML = "\xD7";
|
|
83
|
-
this.clearElt.onclick = () => this.clear();
|
|
84
|
-
this.element.appendChild(this.clearElt);
|
|
85
|
-
}
|
|
86
|
-
search(q, abortController) {
|
|
87
|
-
if (q !== void 0 || q !== null) {
|
|
88
|
-
this.apiParams.q = q;
|
|
89
|
-
}
|
|
90
|
-
if (this.clearElt) {
|
|
91
|
-
this.clearElt.style.display = "block";
|
|
92
|
-
}
|
|
93
|
-
return this.api.search(this.apiParams, abortController).then((data) => {
|
|
94
|
-
this.render(data);
|
|
95
|
-
}).catch(() => {
|
|
96
|
-
this.render();
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
onSuggestionClick(suggestion) {
|
|
100
|
-
}
|
|
101
|
-
clear() {
|
|
102
|
-
if (!this.suggestionsElt) {
|
|
103
|
-
return;
|
|
104
|
-
}
|
|
105
|
-
this.inputElt.value = "";
|
|
106
|
-
this.suggestionsElt.innerHTML = "";
|
|
107
|
-
this.clearElt.style.display = "none";
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
export default StopFinderMixin;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
import { fromLonLat } from "ol/proj";
|
|
2
|
-
import { unByKey } from "ol/Observable";
|
|
3
|
-
export class UserInteractionsLayerInterface {
|
|
4
|
-
constructor(options = {}) {
|
|
5
|
-
}
|
|
6
|
-
attachToMap(map) {
|
|
7
|
-
}
|
|
8
|
-
detachFromMap() {
|
|
9
|
-
}
|
|
10
|
-
activateUserInteractions() {
|
|
11
|
-
}
|
|
12
|
-
deactivateUserInteractions() {
|
|
13
|
-
}
|
|
14
|
-
onClick(callback) {
|
|
15
|
-
}
|
|
16
|
-
onHover(callback) {
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const UserInteractionsLayerMixin = (Base) => class extends Base {
|
|
20
|
-
constructor(options = {}) {
|
|
21
|
-
super(options);
|
|
22
|
-
const {
|
|
23
|
-
userInteractions = true,
|
|
24
|
-
userClickInteractions = true,
|
|
25
|
-
userHoverInteractions = true,
|
|
26
|
-
defaultUserInteractions = true
|
|
27
|
-
} = options;
|
|
28
|
-
this.userInteractions = userInteractions;
|
|
29
|
-
this.userClickInteractions = userClickInteractions;
|
|
30
|
-
this.userHoverInteractions = userHoverInteractions;
|
|
31
|
-
this.defaultUserInteractions = defaultUserInteractions;
|
|
32
|
-
this.userClickCallbacks = [];
|
|
33
|
-
this.userHoverCallbacks = [];
|
|
34
|
-
this.userClickEventsKeys = [];
|
|
35
|
-
this.userHoverEventsKeys = [];
|
|
36
|
-
this.onUserClickCallback = this.onUserClickCallback.bind(this);
|
|
37
|
-
this.onUserMoveCallback = this.onUserMoveCallback.bind(this);
|
|
38
|
-
const { onClick, onHover } = options;
|
|
39
|
-
if (this.userInteractions && this.userClickInteractions && onClick) {
|
|
40
|
-
this.onClick(onClick);
|
|
41
|
-
}
|
|
42
|
-
if (this.userInteractions && this.userHoverInteractions && onHover) {
|
|
43
|
-
this.onHover(onHover);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
attachToMap(map, options) {
|
|
47
|
-
super.attachToMap(map, options);
|
|
48
|
-
if (this.userInteractions && this.defaultUserInteractions && this.userClickInteractions && this.onFeatureClick) {
|
|
49
|
-
this.onClick(this.onFeatureClick);
|
|
50
|
-
}
|
|
51
|
-
if (this.userInteractions && this.defaultUserInteractions && this.userHoverInteractions && this.onFeatureHover) {
|
|
52
|
-
this.onHover(this.onFeatureHover);
|
|
53
|
-
}
|
|
54
|
-
this.listenEvents();
|
|
55
|
-
}
|
|
56
|
-
detachFromMap() {
|
|
57
|
-
this.unlistenEvents();
|
|
58
|
-
super.detachFromMap();
|
|
59
|
-
}
|
|
60
|
-
listenEvents() {
|
|
61
|
-
this.unlistenEvents();
|
|
62
|
-
this.userClickCallbacks.forEach((callback) => {
|
|
63
|
-
this.userClickEventsKeys.push(this.on("user:click", ({ target: { features, layer, coordinate } }) => {
|
|
64
|
-
callback(features, layer, coordinate);
|
|
65
|
-
}));
|
|
66
|
-
});
|
|
67
|
-
this.userHoverCallbacks.forEach((callback) => {
|
|
68
|
-
this.userHoverEventsKeys.push([
|
|
69
|
-
this.on("user:hover", ({ target: { features, layer, coordinate, event } }) => {
|
|
70
|
-
callback(features, layer, coordinate, event);
|
|
71
|
-
})
|
|
72
|
-
]);
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
unlistenEvents() {
|
|
76
|
-
unByKey(this.userClickEventsKeys);
|
|
77
|
-
unByKey(this.userHoverEventsKeys);
|
|
78
|
-
this.userClickEventsKeys = [];
|
|
79
|
-
this.userHoverEventsKeys = [];
|
|
80
|
-
}
|
|
81
|
-
onClick(callback) {
|
|
82
|
-
this.userClickCallbacks.push(callback);
|
|
83
|
-
this.activateUserInteractions();
|
|
84
|
-
}
|
|
85
|
-
onHover(callback) {
|
|
86
|
-
this.userHoverCallbacks.push(callback);
|
|
87
|
-
this.activateUserInteractions();
|
|
88
|
-
}
|
|
89
|
-
onUserClickCallback(evt) {
|
|
90
|
-
const emptyFeatureInfo = {
|
|
91
|
-
features: [],
|
|
92
|
-
layer: this,
|
|
93
|
-
coordinate: evt.coordinate || fromLonLat(evt.lngLat.toArray()),
|
|
94
|
-
event: evt
|
|
95
|
-
};
|
|
96
|
-
return this.getFeatureInfoAtCoordinate(evt.coordinate).then((featureInfo) => {
|
|
97
|
-
this.dispatchEvent({
|
|
98
|
-
type: "user:click",
|
|
99
|
-
target: featureInfo
|
|
100
|
-
});
|
|
101
|
-
return featureInfo;
|
|
102
|
-
}).catch(() => emptyFeatureInfo);
|
|
103
|
-
}
|
|
104
|
-
onUserMoveCallback(evt) {
|
|
105
|
-
const emptyFeatureInfo = {
|
|
106
|
-
features: [],
|
|
107
|
-
layer: this,
|
|
108
|
-
coordinate: evt.coordinate || fromLonLat(evt.lngLat.toArray()),
|
|
109
|
-
event: evt
|
|
110
|
-
};
|
|
111
|
-
return this.getFeatureInfoAtCoordinate(evt.coordinate).then((featureInfo) => {
|
|
112
|
-
this.dispatchEvent({
|
|
113
|
-
type: "user:hover",
|
|
114
|
-
target: featureInfo
|
|
115
|
-
});
|
|
116
|
-
return featureInfo;
|
|
117
|
-
}).catch(() => emptyFeatureInfo);
|
|
118
|
-
}
|
|
119
|
-
activateUserInteractions() {
|
|
120
|
-
}
|
|
121
|
-
deactivateUserInteractions() {
|
|
122
|
-
}
|
|
123
|
-
};
|
|
124
|
-
export default UserInteractionsLayerMixin;
|