mobility-toolbox-js 3.0.0-beta.3 → 3.0.0-beta.32

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.
Files changed (125) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +404 -0
  4. package/api/RealtimeAPI.js +342 -276
  5. package/api/RoutingAPI.d.ts +47 -0
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +17 -11
  9. package/api/WebSocketAPI.d.ts +147 -0
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.d.ts +3 -0
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +76 -0
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  16. package/common/controls/StopFinderControlCommon.js +31 -31
  17. package/common/index.d.ts +2 -0
  18. package/common/index.js +1 -1
  19. package/common/mixins/RealtimeLayerMixin.d.ts +267 -0
  20. package/common/mixins/RealtimeLayerMixin.js +401 -393
  21. package/common/styles/index.d.ts +4 -0
  22. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  23. package/common/styles/realtimeDefaultStyle.js +6 -6
  24. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  26. package/common/styles/realtimeHeadingStyle.js +5 -5
  27. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  28. package/common/typedefs.d.ts +219 -0
  29. package/common/typedefs.js +7 -1
  30. package/common/utils/compareDepartures.d.ts +10 -0
  31. package/common/utils/compareDepartures.js +2 -2
  32. package/common/utils/constants.d.ts +5 -0
  33. package/common/utils/createCanvas.d.ts +10 -0
  34. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  35. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  36. package/common/utils/createRealtimeFilters.d.ts +12 -0
  37. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  38. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  39. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  40. package/common/utils/getLayersAsFlatArray.js +5 -1
  41. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  42. package/common/utils/getMapGlCopyrights.js +3 -3
  43. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  44. package/common/utils/getRealtimeModeSuffix.js +1 -0
  45. package/common/utils/getUrlWithParams.d.ts +8 -0
  46. package/common/utils/getVehiclePosition.d.ts +17 -0
  47. package/common/utils/getVehiclePosition.js +9 -3
  48. package/common/utils/index.d.ts +16 -0
  49. package/common/utils/realtimeConfig.d.ts +64 -0
  50. package/common/utils/removeDuplicate.d.ts +9 -0
  51. package/common/utils/renderTrajectories.d.ts +16 -0
  52. package/common/utils/renderTrajectories.js +6 -6
  53. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  54. package/common/utils/sortAndFilterDepartures.js +1 -1
  55. package/common/utils/sortByDelay.d.ts +3 -0
  56. package/common/utils/sortByDelay.js +5 -1
  57. package/common/utils/timeUtils.d.ts +23 -0
  58. package/common/utils/toMercatorExtent.d.ts +5 -0
  59. package/iife.d.ts +2 -0
  60. package/index.d.ts +9 -0
  61. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  62. package/maplibre/controls/index.d.ts +1 -0
  63. package/maplibre/index.d.ts +5 -0
  64. package/maplibre/layers/Layer.d.ts +28 -0
  65. package/maplibre/layers/Layer.js +1 -1
  66. package/maplibre/layers/RealtimeLayer.d.ts +181 -0
  67. package/maplibre/layers/RealtimeLayer.js +29 -5
  68. package/maplibre/layers/index.d.ts +2 -0
  69. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  70. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  71. package/maplibre/utils/getSourceCoordinates.js +5 -5
  72. package/maplibre/utils/index.d.ts +2 -0
  73. package/mbt.js +39819 -32088
  74. package/mbt.js.map +4 -4
  75. package/mbt.min.js +61 -58
  76. package/mbt.min.js.map +4 -4
  77. package/ol/controls/CopyrightControl.d.ts +31 -0
  78. package/ol/controls/CopyrightControl.js +18 -8
  79. package/ol/controls/RoutingControl.d.ts +202 -0
  80. package/ol/controls/RoutingControl.js +220 -219
  81. package/ol/controls/StopFinderControl.d.ts +37 -0
  82. package/ol/controls/StopFinderControl.js +5 -2
  83. package/ol/controls/index.d.ts +3 -0
  84. package/ol/index.d.ts +7 -0
  85. package/ol/index.js +1 -0
  86. package/ol/layers/Layer.d.ts +103 -0
  87. package/ol/layers/Layer.js +38 -0
  88. package/ol/layers/MaplibreLayer.d.ts +167 -0
  89. package/ol/layers/MaplibreLayer.js +115 -27
  90. package/ol/layers/MaplibreStyleLayer.d.ts +237 -0
  91. package/ol/layers/MaplibreStyleLayer.js +315 -265
  92. package/ol/layers/RealtimeLayer.d.ts +283 -0
  93. package/ol/layers/RealtimeLayer.js +143 -128
  94. package/ol/layers/VectorLayer.d.ts +18 -0
  95. package/ol/layers/VectorLayer.js +32 -0
  96. package/ol/layers/index.d.ts +5 -0
  97. package/ol/layers/index.js +3 -0
  98. package/ol/mixins/MobilityLayerMixin.d.ts +96 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +136 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +122 -140
  102. package/ol/mixins/index.d.ts +1 -0
  103. package/ol/mixins/index.js +2 -0
  104. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  105. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  106. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  107. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  108. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  109. package/ol/renderers/RealtimeLayerRenderer.js +58 -53
  110. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  111. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  112. package/ol/styles/index.d.ts +3 -0
  113. package/ol/styles/routingStyle.d.ts +4 -0
  114. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  115. package/ol/utils/getFeatureInfoAtCoordinate.js +12 -18
  116. package/ol/utils/index.d.ts +1 -0
  117. package/package.json +31 -31
  118. package/setupTests.d.ts +1 -0
  119. package/setupTests.js +3 -4
  120. package/types/common.d.ts +55 -48
  121. package/types/index.d.ts +1 -1
  122. package/types/realtime.d.ts +91 -93
  123. package/types/routing.d.ts +60 -60
  124. package/types/stops.d.ts +62 -62
  125. package/ol/layers/MapGlLayer.js +0 -142
@@ -0,0 +1,283 @@
1
+ import { Map, MapEvent } from 'ol';
2
+ import Feature, { FeatureLike } from 'ol/Feature';
3
+ import GeoJSON from 'ol/format/GeoJSON';
4
+ import { Vector as VectorLayer } from 'ol/layer';
5
+ import Layer from 'ol/layer/Layer';
6
+ import { ObjectEvent } from 'ol/Object';
7
+ import Source from 'ol/source/Source';
8
+ import { WebSocketAPIMessageEventData } from '../../api/WebSocketAPI';
9
+ import { RealtimeLayerMixinOptions } from '../../common/mixins/RealtimeLayerMixin';
10
+ import { RealtimeFullTrajectory, RealtimeTrainId, RealtimeTrajectory, ViewState } from '../../types';
11
+ import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
12
+ export type RealtimeLayerOptions = RealtimeLayerMixinOptions & {
13
+ allowRenderWhenAnimating?: boolean;
14
+ fullTrajectoryStyle?: (feature: FeatureLike, resolution: number, options: any) => void;
15
+ };
16
+ declare const RealtimeLayer_base: {
17
+ new (options: RealtimeLayerMixinOptions): {
18
+ [x: string]: any;
19
+ [x: symbol]: any;
20
+ api: import("..").RealtimeAPI;
21
+ bboxParameters?: Record<string, boolean | boolean[] | number | number[] | string | string[]>;
22
+ canvas?: import("../../types").AnyCanvas;
23
+ debounceRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
24
+ debug: boolean;
25
+ filter?: import("../../common/typedefs").FilterFunction;
26
+ format: GeoJSON;
27
+ generalizationLevel?: import("../../types").RealtimeGeneralizationLevel;
28
+ generalizationLevelByZoom: import("../../types").RealtimeGeneralizationLevel[];
29
+ getGeneralizationLevelByZoom: (zoom: number) => import("../../types").RealtimeGeneralizationLevel;
30
+ getMotsByZoom: (zoom: number) => import("../../types").RealtimeMot[];
31
+ getRenderTimeIntervalByZoom: (zoom: number) => number;
32
+ hoverVehicleId?: RealtimeTrainId;
33
+ isUpdateBboxOnMoveEnd: boolean;
34
+ live?: boolean;
35
+ minZoomInterpolation: number;
36
+ mode: import("../../types").RealtimeMode;
37
+ mots?: import("../../types").RealtimeMot[];
38
+ motsByZoom: import("../../types").RealtimeMot[][];
39
+ onStart?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
40
+ onStop?: ((realtimeLayer: import("../../types").AnyLayer) => void) | undefined;
41
+ pixelRatio?: number;
42
+ renderState?: import("../../types").RealtimeRenderState;
43
+ renderTimeIntervalByZoom: number[];
44
+ requestId?: number;
45
+ selectedVehicle: RealtimeTrajectory;
46
+ selectedVehicleId?: RealtimeTrainId;
47
+ sort?: import("../../common/typedefs").SortFunction;
48
+ speed?: number;
49
+ style?: import("../../types").RealtimeStyleFunction;
50
+ styleOptions?: import("../../types").RealtimeStyleOptions;
51
+ tenant: import("../../types").RealtimeTenant;
52
+ throttleRenderTrajectories: (viewState: ViewState, noInterpolate?: boolean) => void;
53
+ time?: Date;
54
+ trajectories?: Record<RealtimeTrainId, RealtimeTrajectory>;
55
+ updateTimeDelay?: number;
56
+ updateTimeInterval?: number;
57
+ useDebounce?: boolean;
58
+ useRequestAnimationFrame?: boolean;
59
+ useThrottle?: boolean;
60
+ visibilityRef: import("ol/events").EventsKey;
61
+ addTrajectory(trajectory: RealtimeTrajectory): void;
62
+ attachToMap(map: import("../../types").AnyMap): void;
63
+ defineProperties(options: RealtimeLayerMixinOptions): void;
64
+ detachFromMap(): void;
65
+ getFeatureInfoAtCoordinate(coordinate: import("ol/coordinate").Coordinate, options: import("../../types").LayerGetFeatureInfoOptions): Promise<import("../../types").LayerGetFeatureInfoResponse>;
66
+ getRefreshTimeInMs(zoom?: number | undefined): number;
67
+ getTrajectoryInfos(id: RealtimeTrainId): Promise<{
68
+ fullTrajectory: WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]> | WebSocketAPIMessageEventData<RealtimeFullTrajectory>;
69
+ stopSequence: WebSocketAPIMessageEventData<import("../../types").RealtimeStopSequence[]> | WebSocketAPIMessageEventData<RealtimeFullTrajectory>;
70
+ }>;
71
+ getVehicle(filterFc: import("../../common/typedefs").FilterFunction): RealtimeTrajectory[];
72
+ highlightVehicle(id: RealtimeTrainId): void;
73
+ onDeleteTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrainId>): void;
74
+ onDocumentVisibilityChange(): void;
75
+ onTrajectoryMessage(data: WebSocketAPIMessageEventData<RealtimeTrajectory>): void;
76
+ onZoomEnd(): void;
77
+ purgeOutOfDateTrajectories(): void;
78
+ purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
79
+ removeTrajectory(trajectoryOrId: RealtimeTrainId | RealtimeTrajectory): void;
80
+ renderTrajectories(viewState: undefined | ViewState, noInterpolate: boolean | undefined): void;
81
+ renderTrajectoriesInternal(viewState: ViewState, noInterpolate?: boolean): boolean;
82
+ selectVehicle(id: RealtimeTrainId): void;
83
+ setBbox(extent: [number, number, number, number], zoom: number): void;
84
+ start(): void;
85
+ startUpdateTime(): void;
86
+ stop(): void;
87
+ stopUpdateTime(): void;
88
+ };
89
+ } & {
90
+ new (...args: any[]): {
91
+ olEventsKeys: import("ol/events").EventsKey[];
92
+ options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions;
93
+ attachToMap(map: Map): void;
94
+ detachFromMap(): void;
95
+ flat(): any[];
96
+ onChildrenChange(oldValue: Layer[]): void;
97
+ setMapInternal: ((map: Map) => void) & ((map: import("ol/Map").default | null) => void);
98
+ children: Layer<Source, import("ol/renderer/Layer").default<any>>[];
99
+ get copyrights(): string;
100
+ set copyrights(newCopyrights: string | string[]);
101
+ disabled: boolean;
102
+ readonly group: string;
103
+ hitTolerance: number;
104
+ readonly key: string;
105
+ readonly map: Map;
106
+ readonly name: string;
107
+ olLayer: Layer;
108
+ parent: Layer<Source, import("ol/renderer/Layer").default<any>>;
109
+ visible: boolean;
110
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
111
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
112
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
113
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
114
+ getSource: () => Source | null;
115
+ getRenderSource: () => Source | null;
116
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<Array<import("ol/Feature").FeatureLike>>;
117
+ getData: (pixel: import("ol/pixel").Pixel) => Uint8ClampedArray | Uint8Array | Float32Array | DataView | null;
118
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
119
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => Array<string>;
120
+ unrender: () => void;
121
+ getDeclutter: () => string;
122
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
123
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
124
+ getMapInternal: () => import("ol/Map").default | null;
125
+ setMap: (map: import("ol/Map").default | null) => void;
126
+ setSource: (source: Source | null) => void;
127
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
128
+ hasRenderer: () => boolean;
129
+ getBackground: () => import("ol/layer/Base").BackgroundColor | false;
130
+ getClassName: () => string;
131
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
132
+ getLayersArray: (array?: import("ol/layer/Layer").default<import("ol/source/Source").default, import("ol/renderer/Layer").default<any>>[] | undefined) => Array<import("ol/layer/Layer").default>;
133
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => Array<import("ol/layer/Layer").State>;
134
+ getExtent: () => import("ol/extent").Extent | undefined;
135
+ getMaxResolution: () => number;
136
+ getMinResolution: () => number;
137
+ getMinZoom: () => number;
138
+ getMaxZoom: () => number;
139
+ getOpacity: () => number;
140
+ getSourceState: () => import("ol/source/Source").State;
141
+ getVisible: () => boolean;
142
+ getZIndex: () => number | undefined;
143
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
144
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
145
+ setMaxResolution: (maxResolution: number) => void;
146
+ setMinResolution: (minResolution: number) => void;
147
+ setMaxZoom: (maxZoom: number) => void;
148
+ setMinZoom: (minZoom: number) => void;
149
+ setOpacity: (opacity: number) => void;
150
+ setVisible: (visible: boolean) => void;
151
+ setZIndex: (zindex: number) => void;
152
+ get: (key: string) => any;
153
+ getKeys: () => Array<string>;
154
+ getProperties: () => {
155
+ [x: string]: any;
156
+ };
157
+ getPropertiesInternal: () => {
158
+ [x: string]: any;
159
+ } | null;
160
+ hasProperties: () => boolean;
161
+ notify: (key: string, oldValue: any) => void;
162
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
163
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
164
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
165
+ setProperties: (values: {
166
+ [x: string]: any;
167
+ }, silent?: boolean | undefined) => void;
168
+ unset: (key: string, silent?: boolean | undefined) => void;
169
+ changed: () => void;
170
+ getRevision: () => number;
171
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
172
+ dispatchEvent: (event: import("ol/events/Event").default | string) => boolean | undefined;
173
+ getListeners: (type: string) => Array<import("ol/events").Listener> | undefined;
174
+ hasListener: (type?: string | undefined) => boolean;
175
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
176
+ dispose: () => void;
177
+ };
178
+ } & typeof Layer;
179
+ /**
180
+ * An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
181
+ *
182
+ * @example
183
+ * import { RealtimeLayer } from 'mobility-toolbox-js/ol';
184
+ *
185
+ * const layer = new RealtimeLayer({
186
+ * apiKey: "yourApiKey"
187
+ * // allowRenderWhenAnimating: false,
188
+ * // url: "wss://api.geops.io/tracker-ws/v1/",
189
+ * });
190
+ *
191
+ *
192
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
193
+ *
194
+ * @extends {ol/layer/Layer~Layer}
195
+ *
196
+ * @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating.
197
+ * @public
198
+ */
199
+ declare class RealtimeLayer extends RealtimeLayer_base {
200
+ /** @private */
201
+ allowRenderWhenAnimating?: boolean;
202
+ vectorLayer: VectorLayer<Feature>;
203
+ /**
204
+ * Constructor.
205
+ *
206
+ * @param {RealtimeLayerOptions} options
207
+ * @param {boolean} [options.allowRenderWhenAnimating=false] Allow rendering of the layer when the map is animating.
208
+ * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
209
+ * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
210
+ *
211
+ */
212
+ constructor(options: RealtimeLayerOptions);
213
+ /** @private */
214
+ attachToMap(map: Map): void;
215
+ /**
216
+ * Create a copy of the RealtimeLayer.
217
+ * @param {Object} newOptions Options to override
218
+ * @return {RealtimeLayer} A RealtimeLayer
219
+ */
220
+ clone(newOptions: RealtimeLayerOptions): RealtimeLayer;
221
+ /**
222
+ * @private
223
+ */
224
+ createRenderer(): RealtimeLayerRenderer;
225
+ /**
226
+ * Render the trajectories using current map's size, resolution and rotation.
227
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
228
+ * @overrides
229
+ * @private
230
+ */
231
+ /**
232
+ * Destroy the container of the tracker.
233
+ * @private
234
+ */
235
+ detachFromMap(): void;
236
+ /**
237
+ * Return the delay in ms before the next rendering.
238
+ * @private
239
+ */
240
+ getRefreshTimeInMs(): number;
241
+ highlight(feature: Feature): void;
242
+ /**
243
+ * On move end we update the websocket with the new bbox.
244
+ *
245
+ * @private
246
+ * @override
247
+ */
248
+ /**
249
+ * Highlight the trajectory of journey.
250
+ * @private
251
+ */
252
+ highlightTrajectory(id: RealtimeTrainId): Promise<Feature[] | undefined>;
253
+ /**
254
+ * Function called on moveend event only when the zoom has changed.
255
+ *
256
+ * @param {ol/MapEvent~MapEvent} evt Moveend event.
257
+ * @private
258
+ * @override
259
+ */
260
+ onMoveEnd(evt: MapEvent | ObjectEvent): void;
261
+ onZoomEnd(): void;
262
+ /**
263
+ * Remove the trajectory form the list if necessary.
264
+ *
265
+ * @private
266
+ */
267
+ purgeTrajectory(trajectory: RealtimeTrajectory, extent: [number, number, number, number], zoom: number): boolean;
268
+ renderTrajectories(noInterpolate: boolean): void;
269
+ /**
270
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
271
+ * @private
272
+ * @override
273
+ */
274
+ renderTrajectoriesInternal(viewState: ViewState, noInterpolate: boolean): boolean;
275
+ select(feature: Feature): void;
276
+ /**
277
+ * Send the current bbox to the websocket
278
+ *
279
+ * @private
280
+ */
281
+ setBbox(extent?: [number, number, number, number], zoom?: number): void;
282
+ }
283
+ export default RealtimeLayer;
@@ -1,17 +1,17 @@
1
+ import debounce from 'lodash.debounce';
1
2
  import GeoJSON from 'ol/format/GeoJSON';
2
3
  import { Vector as VectorLayer } from 'ol/layer';
3
- import Source from 'ol/source/Source';
4
- import { Vector as VectorSource } from 'ol/source';
5
- import debounce from 'lodash.debounce';
6
4
  import Layer from 'ol/layer/Layer';
5
+ import { Vector as VectorSource } from 'ol/source';
6
+ import Source from 'ol/source/Source';
7
7
  import RealtimeLayerMixin from '../../common/mixins/RealtimeLayerMixin';
8
- import { fullTrajectoryStyle } from '../styles';
9
8
  import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
10
9
  import RealtimeLayerRenderer from '../renderers/RealtimeLayerRenderer';
10
+ import { fullTrajectoryStyle } from '../styles';
11
11
  /** @private */
12
12
  const format = new GeoJSON();
13
13
  /**
14
- * Responsible for loading and display data from the geOps Realtime API.
14
+ * An OpenLayers layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
15
15
  *
16
16
  * @example
17
17
  * import { RealtimeLayer } from 'mobility-toolbox-js/ol';
@@ -30,7 +30,7 @@ const format = new GeoJSON();
30
30
  * @classproperty {boolean} allowRenderWhenAnimating - Allow rendering of the layer when the map is animating.
31
31
  * @public
32
32
  */
33
- // @ts-ignore
33
+ // @ts-expect-error
34
34
  class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
35
35
  /**
36
36
  * Constructor.
@@ -52,45 +52,42 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
52
52
  // We store the layer used to highlight the full Trajectory
53
53
  /** @private */
54
54
  this.vectorLayer = new VectorLayer({
55
- updateWhileAnimating: this.allowRenderWhenAnimating,
56
- updateWhileInteracting: true,
57
55
  source: new VectorSource({ features: [] }),
58
56
  style: (feature, resolution) => {
59
57
  return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
60
58
  },
59
+ updateWhileAnimating: this.allowRenderWhenAnimating,
60
+ updateWhileInteracting: true,
61
61
  });
62
62
  // Options the last render run did happen. If something changes
63
63
  // we have to render again
64
64
  /** @private */
65
65
  this.renderState = {
66
66
  center: [0, 0],
67
- zoom: undefined,
68
67
  rotation: 0,
68
+ zoom: undefined,
69
69
  };
70
70
  /** @private */
71
71
  this.onZoomEndDebounced = debounce(this.onZoomEnd, 100);
72
72
  /** @private */
73
73
  this.onMoveEndDebounced = debounce(this.onMoveEnd, 100);
74
74
  }
75
- /**
76
- * @private
77
- */
78
- createRenderer() {
79
- return new RealtimeLayerRenderer(this);
80
- }
81
75
  /** @private */
82
76
  attachToMap(map) {
83
77
  super.attachToMap(map);
84
78
  if (this.map) {
85
79
  // If the layer is visible we start the rendering clock
86
- if (this.visible) {
80
+ if (this.getVisible()) {
87
81
  this.start();
88
82
  }
83
+ // @ts-expect-error - bad ts check RealtimeLayer is a BaseLayer
89
84
  const index = this.map.getLayers().getArray().indexOf(this);
90
85
  this.map.getLayers().insertAt(index, this.vectorLayer);
91
- this.olListenersKeys.push(...this.map.on(['moveend', 'change:target'], (evt) => {
86
+ this.olEventsKeys.push(...this.map.on(['moveend', 'change:target'],
87
+ // @ts-expect-error - bad ol definitions
88
+ (evt) => {
92
89
  const view = (evt.map || evt.target).getView();
93
- if (view.getAnimating() || view.getInteracting()) {
90
+ if (!view || (view === null || view === void 0 ? void 0 : view.getAnimating()) || (view === null || view === void 0 ? void 0 : view.getInteracting())) {
94
91
  return;
95
92
  }
96
93
  const zoom = view.getZoom();
@@ -102,7 +99,7 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
102
99
  this.currentZoom = zoom;
103
100
  this.onMoveEndDebounced(evt);
104
101
  }), this.on('change:visible', (evt) => {
105
- if (evt.target.visible) {
102
+ if (evt.target.getVisible()) {
106
103
  this.start();
107
104
  }
108
105
  else {
@@ -117,13 +114,18 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
117
114
  }
118
115
  }
119
116
  /**
120
- * Destroy the container of the tracker.
117
+ * Create a copy of the RealtimeLayer.
118
+ * @param {Object} newOptions Options to override
119
+ * @return {RealtimeLayer} A RealtimeLayer
120
+ */
121
+ clone(newOptions) {
122
+ return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
123
+ }
124
+ /**
121
125
  * @private
122
126
  */
123
- detachFromMap() {
124
- var _a;
125
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
126
- super.detachFromMap();
127
+ createRenderer() {
128
+ return new RealtimeLayerRenderer(this);
127
129
  }
128
130
  /**
129
131
  * Render the trajectories using current map's size, resolution and rotation.
@@ -131,61 +133,25 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
131
133
  * @overrides
132
134
  * @private
133
135
  */
134
- // @ts-ignore
135
- renderTrajectories(noInterpolate) {
136
- if (!this.map) {
137
- return;
138
- }
139
- const view = this.map.getView();
140
- // it could happen that the view is set but without center yet,
141
- // so the calcualteExtent will trigger an error.
142
- if (!view.getCenter()) {
143
- return;
144
- }
145
- super.renderTrajectories({
146
- size: this.map.getSize(),
147
- center: view.getCenter(),
148
- extent: view.calculateExtent(),
149
- resolution: view.getResolution(),
150
- rotation: view.getRotation(),
151
- zoom: view.getZoom(),
152
- pixelRatio: this.pixelRatio,
153
- }, noInterpolate);
154
- }
155
136
  /**
156
- * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
137
+ * Destroy the container of the tracker.
157
138
  * @private
158
- * @override
159
139
  */
160
- renderTrajectoriesInternal(viewState, noInterpolate) {
161
- if (!this.map) {
162
- return false;
163
- }
164
- let isRendered = false;
165
- const blockRendering = this.allowRenderWhenAnimating
166
- ? false
167
- : this.map.getView().getAnimating() ||
168
- this.map.getView().getInteracting();
169
- // Don't render the map when the map is animating or interacting.
170
- isRendered = blockRendering
171
- ? false
172
- : super.renderTrajectoriesInternal(viewState, noInterpolate);
173
- // We update the current render state.
174
- if (isRendered) {
175
- /** @private */
176
- this.renderedViewState = Object.assign({}, viewState);
177
- if (this.getRenderer().container) {
178
- this.getRenderer().container.style.transform = '';
179
- }
180
- }
181
- return isRendered;
140
+ detachFromMap() {
141
+ var _a;
142
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.removeLayer(this.vectorLayer);
143
+ super.detachFromMap();
182
144
  }
183
145
  /**
184
146
  * Return the delay in ms before the next rendering.
185
147
  * @private
186
148
  */
187
149
  getRefreshTimeInMs() {
188
- return super.getRefreshTimeInMs(this.map.getView().getZoom());
150
+ var _a;
151
+ return super.getRefreshTimeInMs(((_a = this.map.getView()) === null || _a === void 0 ? void 0 : _a.getZoom()) || 0);
152
+ }
153
+ highlight(feature) {
154
+ this.highlightVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
189
155
  }
190
156
  /**
191
157
  * On move end we update the websocket with the new bbox.
@@ -193,12 +159,36 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
193
159
  * @private
194
160
  * @override
195
161
  */
196
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
197
- onMoveEnd(evt) {
198
- if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
199
- return;
162
+ /**
163
+ * Highlight the trajectory of journey.
164
+ * @private
165
+ */
166
+ highlightTrajectory(id) {
167
+ var _a, _b, _c, _d;
168
+ if (!id) {
169
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
170
+ return Promise.resolve([]);
200
171
  }
201
- this.setBbox();
172
+ return this.api
173
+ .getFullTrajectory(id, this.mode, this.getGeneralizationLevelByZoom(Math.floor(((_d = (_c = this.map) === null || _c === void 0 ? void 0 : _c.getView()) === null || _d === void 0 ? void 0 : _d.getZoom()) || 0)))
174
+ .then((data) => {
175
+ var _a, _b, _c, _d, _e;
176
+ const fullTrajectory = data.content;
177
+ if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
178
+ return [];
179
+ }
180
+ const features = format.readFeatures(fullTrajectory);
181
+ (_c = (_b = this.vectorLayer) === null || _b === void 0 ? void 0 : _b.getSource()) === null || _c === void 0 ? void 0 : _c.clear(true);
182
+ if (features.length) {
183
+ (_e = (_d = this.vectorLayer) === null || _d === void 0 ? void 0 : _d.getSource()) === null || _e === void 0 ? void 0 : _e.addFeatures(features);
184
+ }
185
+ return features;
186
+ })
187
+ .catch(() => {
188
+ var _a, _b;
189
+ (_b = (_a = this.vectorLayer) === null || _a === void 0 ? void 0 : _a.getSource()) === null || _b === void 0 ? void 0 : _b.clear(true);
190
+ return [];
191
+ });
202
192
  }
203
193
  /**
204
194
  * Function called on moveend event only when the zoom has changed.
@@ -207,22 +197,37 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
207
197
  * @private
208
198
  * @override
209
199
  */
200
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
201
+ onMoveEnd(evt) {
202
+ if (!this.isUpdateBboxOnMoveEnd || !this.getVisible()) {
203
+ return;
204
+ }
205
+ this.setBbox();
206
+ }
210
207
  // eslint-disable-next-line no-unused-vars
211
208
  onZoomEnd() {
212
209
  super.onZoomEnd();
213
- if (!this.isUpdateBboxOnMoveEnd || !this.visible) {
210
+ if (!this.isUpdateBboxOnMoveEnd || !this.getVisible()) {
214
211
  return;
215
212
  }
216
213
  if (this.selectedVehicleId) {
217
214
  this.highlightTrajectory(this.selectedVehicleId);
218
215
  }
219
216
  }
220
- highlight(feature) {
221
- this.highlightVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
222
- }
223
- select(feature) {
224
- this.selectVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
225
- this.highlightTrajectory(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
217
+ /**
218
+ * Remove the trajectory form the list if necessary.
219
+ *
220
+ * @private
221
+ */
222
+ purgeTrajectory(trajectory, extent, zoom) {
223
+ var _a;
224
+ const center = (_a = this.map.getView()) === null || _a === void 0 ? void 0 : _a.getCenter();
225
+ if (!extent && !center) {
226
+ // In that case the view is not zoomed yet so we can't calculate the extent of the map,
227
+ // it will trigger a js error on calculateExtent function.
228
+ return false;
229
+ }
230
+ return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom() || 0);
226
231
  }
227
232
  // /**
228
233
  // * Update the cursor style when hovering a vehicle.
@@ -254,19 +259,61 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
254
259
  // super.onFeatureClick(features, layer, coordinate);
255
260
  // this.highlightTrajectory(this.selectedVehicleId);
256
261
  // }
262
+ // @ts-expect-error
263
+ renderTrajectories(noInterpolate) {
264
+ if (!this.map) {
265
+ return;
266
+ }
267
+ const view = this.map.getView();
268
+ // it could happen that the view is set but without center yet,
269
+ // so the calcualteExtent will trigger an error.
270
+ if (!(view === null || view === void 0 ? void 0 : view.getCenter())) {
271
+ return;
272
+ }
273
+ super.renderTrajectories({
274
+ center: view.getCenter(),
275
+ extent: view.calculateExtent(),
276
+ pixelRatio: this.pixelRatio,
277
+ resolution: view.getResolution(),
278
+ rotation: view.getRotation(),
279
+ size: this.map.getSize(),
280
+ zoom: view.getZoom(),
281
+ }, noInterpolate);
282
+ }
257
283
  /**
258
- * Remove the trajectory form the list if necessary.
259
- *
284
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
260
285
  * @private
286
+ * @override
261
287
  */
262
- purgeTrajectory(trajectory, extent, zoom) {
263
- const center = this.map.getView().getCenter();
264
- if (!extent && !center) {
265
- // In that case the view is not zoomed yet so we can't calculate the extent of the map,
266
- // it will trigger a js error on calculateExtent function.
288
+ renderTrajectoriesInternal(viewState, noInterpolate) {
289
+ var _a;
290
+ if (!((_a = this.map) === null || _a === void 0 ? void 0 : _a.getView())) {
267
291
  return false;
268
292
  }
269
- return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
293
+ let isRendered = false;
294
+ const blockRendering = this.allowRenderWhenAnimating
295
+ ? false
296
+ : this.map.getView().getAnimating() ||
297
+ this.map.getView().getInteracting();
298
+ // Don't render the map when the map is animating or interacting.
299
+ isRendered = blockRendering
300
+ ? false
301
+ : super.renderTrajectoriesInternal(viewState, noInterpolate);
302
+ // We update the current render state.
303
+ if (isRendered) {
304
+ /** @private */
305
+ this.renderedViewState = Object.assign({}, viewState);
306
+ // @ts-expect-error - we are in the same class
307
+ const { container } = this.getRenderer();
308
+ if (container) {
309
+ container.style.transform = '';
310
+ }
311
+ }
312
+ return isRendered;
313
+ }
314
+ select(feature) {
315
+ this.selectVehicle(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
316
+ this.highlightTrajectory(feature === null || feature === void 0 ? void 0 : feature.get('train_id'));
270
317
  }
271
318
  /**
272
319
  * Send the current bbox to the websocket
@@ -274,45 +321,13 @@ class RealtimeLayer extends RealtimeLayerMixin(MobilityLayerMixin(Layer)) {
274
321
  * @private
275
322
  */
276
323
  setBbox(extent, zoom) {
277
- super.setBbox(extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
278
- }
279
- /**
280
- * Highlight the trajectory of journey.
281
- * @private
282
- */
283
- highlightTrajectory(id) {
284
- var _a, _b;
285
- if (!id) {
286
- this.vectorLayer.getSource().clear(true);
287
- return Promise.resolve([]);
324
+ var _a, _b, _c, _d;
325
+ const extentt = extent ||
326
+ ((_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.calculateExtent());
327
+ if (!extentt) {
328
+ return;
288
329
  }
289
- return this.api
290
- .getFullTrajectory(id, this.mode, this.getGeneralizationLevelByZoom(Math.floor(((_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView()) === null || _b === void 0 ? void 0 : _b.getZoom()) || 0)))
291
- .then((data) => {
292
- var _a;
293
- const fullTrajectory = data.content;
294
- if (!((_a = fullTrajectory === null || fullTrajectory === void 0 ? void 0 : fullTrajectory.features) === null || _a === void 0 ? void 0 : _a.length)) {
295
- return [];
296
- }
297
- const features = format.readFeatures(fullTrajectory);
298
- this.vectorLayer.getSource().clear(true);
299
- if (features.length) {
300
- this.vectorLayer.getSource().addFeatures(features);
301
- }
302
- return features;
303
- })
304
- .catch(() => {
305
- this.vectorLayer.getSource().clear(true);
306
- return [];
307
- });
308
- }
309
- /**
310
- * Create a copy of the RealtimeLayer.
311
- * @param {Object} newOptions Options to override
312
- * @return {RealtimeLayer} A RealtimeLayer
313
- */
314
- clone(newOptions) {
315
- return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
330
+ super.setBbox(extentt, zoom || ((_d = (_c = this.map) === null || _c === void 0 ? void 0 : _c.getView()) === null || _d === void 0 ? void 0 : _d.getZoom()) || 0);
316
331
  }
317
332
  }
318
333
  export default RealtimeLayer;