mobility-toolbox-js 3.0.0-beta.8 → 3.0.0

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 (130) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +20 -0
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +404 -0
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +47 -0
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +44 -0
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +147 -0
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.d.ts +3 -0
  13. package/api/index.js +1 -1
  14. package/api/typedefs.d.ts +76 -0
  15. package/api/typedefs.js +27 -42
  16. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  17. package/common/controls/StopFinderControlCommon.js +32 -32
  18. package/common/index.d.ts +2 -0
  19. package/common/index.js +1 -1
  20. package/common/styles/index.d.ts +4 -0
  21. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  22. package/common/styles/realtimeDefaultStyle.js +6 -11
  23. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  24. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  25. package/common/styles/realtimeHeadingStyle.js +5 -10
  26. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  27. package/common/styles/realtimeSimpleStyle.js +0 -1
  28. package/common/typedefs.d.ts +102 -0
  29. package/common/typedefs.js +6 -31
  30. package/common/utils/RealtimeEngine.d.ts +214 -0
  31. package/common/utils/RealtimeEngine.js +554 -0
  32. package/common/utils/compareDepartures.d.ts +10 -0
  33. package/common/utils/compareDepartures.js +2 -2
  34. package/common/utils/constants.d.ts +5 -0
  35. package/common/utils/createCanvas.d.ts +10 -0
  36. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  37. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  38. package/common/utils/createRealtimeFilters.d.ts +12 -0
  39. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  40. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  41. package/common/utils/getLayersAsFlatArray.d.ts +2 -0
  42. package/common/utils/getLayersAsFlatArray.js +0 -1
  43. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  44. package/common/utils/getMapGlCopyrights.js +3 -3
  45. package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
  46. package/common/utils/getRealtimeModeSuffix.js +1 -0
  47. package/common/utils/getUrlWithParams.d.ts +8 -0
  48. package/common/utils/getVehiclePosition.d.ts +17 -0
  49. package/common/utils/getVehiclePosition.js +6 -3
  50. package/common/utils/index.d.ts +16 -0
  51. package/common/utils/realtimeConfig.d.ts +64 -0
  52. package/common/utils/realtimeConfig.js +0 -1
  53. package/common/utils/removeDuplicate.d.ts +9 -0
  54. package/common/utils/renderTrajectories.d.ts +17 -0
  55. package/common/utils/renderTrajectories.js +7 -6
  56. package/common/utils/sortAndFilterDepartures.d.ts +16 -0
  57. package/common/utils/sortAndFilterDepartures.js +2 -1
  58. package/common/utils/sortByDelay.d.ts +3 -0
  59. package/common/utils/sortByDelay.js +5 -1
  60. package/common/utils/timeUtils.d.ts +23 -0
  61. package/common/utils/toMercatorExtent.d.ts +5 -0
  62. package/iife.d.ts +2 -0
  63. package/index.d.ts +9 -0
  64. package/maplibre/controls/CopyrightControl.d.ts +38 -0
  65. package/maplibre/controls/CopyrightControl.js +11 -8
  66. package/maplibre/controls/index.d.ts +1 -0
  67. package/maplibre/index.d.ts +5 -0
  68. package/maplibre/layers/Layer.d.ts +29 -0
  69. package/maplibre/layers/Layer.js +2 -3
  70. package/maplibre/layers/RealtimeLayer.d.ts +124 -0
  71. package/maplibre/layers/RealtimeLayer.js +154 -118
  72. package/maplibre/layers/index.d.ts +2 -0
  73. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  74. package/maplibre/utils/getSourceCoordinates.d.ts +8 -0
  75. package/maplibre/utils/getSourceCoordinates.js +6 -5
  76. package/maplibre/utils/index.d.ts +2 -0
  77. package/mbt.js +14585 -14557
  78. package/mbt.js.map +4 -4
  79. package/mbt.min.js +75 -75
  80. package/mbt.min.js.map +4 -4
  81. package/ol/controls/CopyrightControl.d.ts +39 -0
  82. package/ol/controls/CopyrightControl.js +13 -5
  83. package/ol/controls/RoutingControl.d.ts +213 -0
  84. package/ol/controls/RoutingControl.js +250 -264
  85. package/ol/controls/StopFinderControl.d.ts +56 -0
  86. package/ol/controls/StopFinderControl.js +24 -5
  87. package/ol/controls/index.d.ts +3 -0
  88. package/ol/index.d.ts +6 -0
  89. package/ol/layers/Layer.d.ts +26 -0
  90. package/ol/layers/Layer.js +39 -0
  91. package/ol/layers/MaplibreLayer.d.ts +91 -0
  92. package/ol/layers/MaplibreLayer.js +154 -31
  93. package/ol/layers/MaplibreStyleLayer.d.ts +157 -0
  94. package/ol/layers/MaplibreStyleLayer.js +281 -210
  95. package/ol/layers/RealtimeLayer.d.ts +150 -0
  96. package/ol/layers/RealtimeLayer.js +210 -206
  97. package/ol/layers/VectorLayer.d.ts +17 -0
  98. package/ol/layers/VectorLayer.js +33 -0
  99. package/ol/layers/index.d.ts +5 -0
  100. package/ol/layers/index.js +3 -0
  101. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -0
  102. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  103. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  104. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  105. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  106. package/ol/renderers/RealtimeLayerRenderer.js +50 -70
  107. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  108. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  109. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  110. package/ol/styles/fullTrajectoryStyle.js +5 -7
  111. package/ol/styles/index.d.ts +3 -0
  112. package/ol/styles/routingStyle.d.ts +3 -0
  113. package/ol/styles/routingStyle.js +13 -10
  114. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  115. package/ol/utils/defineDeprecatedProperties.js +180 -0
  116. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  117. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  118. package/ol/utils/index.d.ts +1 -0
  119. package/package.json +44 -44
  120. package/setupTests.d.ts +1 -0
  121. package/setupTests.js +17 -4
  122. package/types/common.d.ts +53 -69
  123. package/types/index.d.ts +1 -1
  124. package/types/realtime.d.ts +98 -95
  125. package/types/routing.d.ts +60 -60
  126. package/types/stops.d.ts +62 -62
  127. package/common/mixins/RealtimeLayerMixin.js +0 -743
  128. package/ol/layers/MapGlLayer.js +0 -142
  129. package/ol/mixins/MobilityLayerMixin.js +0 -9
  130. package/ol/mixins/PropertiesLayerMixin.js +0 -142
@@ -1,47 +1,86 @@
1
- // @ts-nocheck
2
- import { fromLonLat } from 'ol/proj';
3
- import { getWidth, getHeight } from 'ol/extent';
4
- import transformRotate from '@turf/transform-rotate';
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
12
+ var _RealtimeLayer_internalId;
5
13
  import { point } from '@turf/helpers';
6
- import RealtimeLayerMixin from '../../common/mixins/RealtimeLayerMixin';
7
- import Layer from './Layer';
14
+ import transformRotate from '@turf/transform-rotate';
15
+ import { getHeight, getWidth } from 'ol/extent';
16
+ import { fromLonLat } from 'ol/proj';
17
+ import RealtimeEngine from '../../common/utils/RealtimeEngine';
8
18
  import { getSourceCoordinates } from '../utils';
9
- import toMercatorExtent from '../../common/utils/toMercatorExtent';
19
+ import Layer from './Layer';
10
20
  /**
11
- * Responsible for loading and display data from a geOps realtime API.
21
+ * A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
12
22
  *
13
23
  * @example
14
- * import { RealtimeLayer } from 'mobility-toolbox-js/Maplibre';
24
+ * import { Map } from 'maplibre-gl';
25
+ * import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
15
26
  *
27
+ * // Define the map
28
+ * const map = new Map({ ... });
29
+ *
30
+ * // Define your layer map
16
31
  * const layer = new RealtimeLayer({
17
32
  * apiKey: "yourApiKey"
18
33
  * // url: "wss://api.geops.io/tracker-ws/v1/",
19
34
  * });
20
35
  *
36
+ * // Add the layer to your map *
37
+ * map.on('load', () => {
38
+ * map.addLayer(layer);
39
+ * });
40
+ *
21
41
  *
22
42
  * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
43
+ * @see <a href="/example/mb-realtime>MapLibre Realtime layer example</a>
23
44
  *
24
- * @implements {maplibregl.CustomLayer}
45
+ * @implements {maplibregl.CustomLayerInterface}
25
46
  * @extends {maplibregl.Evented}
47
+ * @classproperty {function} filter - Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
48
+ * @classproperty {RealtimeMode} mode - The realtime mode to use.
49
+ * @classproperty {RealtimeMot[]} mots - Filter trains by its mode of transportation. It filters trains on backend side.
50
+ * @classproperty {RealtimeTenant} tenant - Filter trains by its tenant. It filters trains on backend side.
51
+ * @classproperty {function} sort - Sort trains. This function must be fast, it is executed on every render frame.
52
+ * @classproperty {function} style - Function to style the vehicles.
53
+ s
26
54
  * @public
27
55
  */
28
- class RealtimeLayer extends RealtimeLayerMixin(Layer) {
56
+ class RealtimeLayer extends Layer {
29
57
  /**
30
58
  * Constructor.
31
59
  *
32
60
  * @param {RealtimeLayerOptions} options
33
61
  * @param {string} options.apiKey Access key for [geOps apis](https://developer.geops.io/).
34
- * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps realtime API url.
35
- *
62
+ * @param {FilterFunction} options.filter Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
63
+ * @param {getMotsByZoomFunction} options.getMotsByZoom Returns for each zoom level the list of MOTs to display. It filters trains on backend side.
64
+ * @param {number} [options.minZoomInterpolation=8] Minimal zoom level where to start to interpolate train positions.
65
+ * @param {RealtimeMode} [options.mode='topographic'] The realtime mode to use.
66
+ * @param {SortFunction} options.sort Sort trains. This function must be fast, it is executed on every render frame.
67
+ * @param {RealtimeStyleFunction} options.style Function to style the vehicles.
68
+ * @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
69
+ * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
36
70
  */
37
71
  constructor(options = {}) {
38
72
  var _a;
39
- const canvas = document.createElement('canvas');
40
- super(Object.assign({ canvas }, options));
41
- /** @private */
73
+ const id = (options === null || options === void 0 ? void 0 : options.id) || 'realtime';
74
+ super(Object.assign(Object.assign({}, options), { id: 'realtime-custom-' + id }));
75
+ _RealtimeLayer_internalId.set(this, void 0);
76
+ __classPrivateFieldSet(this, _RealtimeLayer_internalId, id, "f");
77
+ this.engine = new RealtimeEngine(Object.assign({ getViewState: this.getViewState.bind(this), onRender: this.onRealtimeEngineRender.bind(this) }, options));
78
+ this.sourceId = __classPrivateFieldGet(this, _RealtimeLayer_internalId, "f");
42
79
  this.source = {
43
- id: this.id,
44
- type: 'canvas',
80
+ // Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
81
+ animate: true,
82
+ // @ts-expect-error bad type definition
83
+ attribution: (_a = options.attribution) === null || _a === void 0 ? void 0 : _a.join(', '),
45
84
  canvas: this.canvas,
46
85
  // Set a default coordinates, it will be overrides on next data update
47
86
  coordinates: [
@@ -50,108 +89,47 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
50
89
  [2, 2],
51
90
  [0, 0],
52
91
  ],
53
- // Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
54
- animate: true,
55
- attribution: (_a = options.attribution) === null || _a === void 0 ? void 0 : _a.join(', '),
56
92
  loaded: true,
93
+ type: 'canvas',
57
94
  };
58
- /** @private */
59
95
  this.layer = {
60
- id: `${this.id}-raster`,
61
- type: 'raster',
62
- source: this.id,
96
+ id: __classPrivateFieldGet(this, _RealtimeLayer_internalId, "f"),
63
97
  layout: {
64
98
  visibility: 'visible',
65
99
  },
66
100
  paint: {
67
- 'raster-opacity': 1,
68
101
  'raster-fade-duration': 0,
102
+ 'raster-opacity': 1,
69
103
  'raster-resampling': 'nearest', // important otherwise it looks blurry
70
104
  },
105
+ source: this.sourceId,
106
+ type: 'raster',
71
107
  };
72
- /** @private */
73
108
  this.onLoad = this.onLoad.bind(this);
74
- /** @private */
75
109
  this.onMove = this.onMove.bind(this);
76
- /** @private */
77
110
  this.onMoveEnd = this.onMoveEnd.bind(this);
78
- /** @private */
79
111
  this.onZoomEnd = this.onZoomEnd.bind(this);
80
112
  }
81
113
  /**
82
- * Add sources, layers and listeners to the map.
83
- */
84
- onAdd(map, gl) {
85
- super.onAdd(map, gl);
86
- if (map.isStyleLoaded()) {
87
- this.onLoad();
88
- }
89
- map.on('load', this.onLoad);
90
- }
91
- /**
92
- * Remove source, layers and listeners from the map.
93
- */
94
- onRemove(map, gl) {
95
- map.off('load', this.onLoad);
96
- if (map.getLayer(this.layer.id)) {
97
- map.removeLayer(this.layer.id);
98
- }
99
- if (map.getSource(this.id)) {
100
- map.removeSource(this.id);
101
- }
102
- super.onRemove(map, gl);
103
- }
104
- onLoad() {
105
- if (!this.map.getSource(this.id)) {
106
- this.map.addSource(this.id, this.source);
107
- }
108
- if (!this.map.getLayer(this.layer.id)) {
109
- this.map.addLayer(this.layer, this.id);
110
- }
111
- this.start();
112
- }
113
- /**
114
- * Start updating vehicles position.
115
- *
116
- * @public
117
- */
118
- start() {
119
- super.start();
120
- this.map.on('move', this.onMove);
121
- this.map.on('moveend', this.onMoveEnd);
122
- this.map.on('zoomend', this.onZoomEnd);
123
- }
124
- /**
125
- * Stop updating vehicles position.
126
- *
127
- * @public
128
- */
129
- stop() {
130
- var _a, _b, _c;
131
- super.stop();
132
- (_a = this.map) === null || _a === void 0 ? void 0 : _a.off('move', this.onMove);
133
- (_b = this.map) === null || _b === void 0 ? void 0 : _b.off('moveend', this.onMoveEnd);
134
- (_c = this.map) === null || _c === void 0 ? void 0 : _c.off('zoomend', this.onZoomEnd);
135
- }
136
- /**
137
- * Render the trajectories using current map's size, resolution and rotation.
138
- * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
114
+ * Return the current view state. Used by the RealtimeEngine.
139
115
  * @private
140
116
  */
141
- renderTrajectories(noInterpolate = false) {
117
+ getViewState() {
142
118
  if (!this.map) {
143
- return;
119
+ return {};
144
120
  }
145
121
  if (!this.pixelRatio) {
146
122
  this.pixelRatio = 1;
147
123
  }
148
- const { width, height } = this.map.getCanvas();
124
+ const { height, width } = this.map.getCanvas();
149
125
  const center = this.map.getCenter();
150
126
  // We use turf here to have good transform.
127
+ // @ts-expect-error bad type definition
151
128
  const leftBottom = this.map.unproject({
152
129
  x: 0,
153
130
  y: height / this.pixelRatio,
154
131
  }); // southWest
132
+ // @ts-expect-error bad type definition
155
133
  const rightTop = this.map.unproject({
156
134
  x: width / this.pixelRatio,
157
135
  y: 0,
@@ -167,60 +145,118 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
167
145
  const yResolution = getHeight(bounds) / (height / this.pixelRatio);
168
146
  const res = Math.max(xResolution, yResolution);
169
147
  // Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
170
- const viewState = {
171
- size: [width / this.pixelRatio, height / this.pixelRatio],
148
+ return {
172
149
  center: fromLonLat([center.lng, center.lat]),
173
150
  extent: bounds,
151
+ pixelRatio: this.pixelRatio,
174
152
  resolution: res,
175
- zoom: this.map.getZoom() - 1,
176
153
  rotation: -(this.map.getBearing() * Math.PI) / 180,
177
- pixelRatio: this.pixelRatio,
154
+ size: [width / this.pixelRatio, height / this.pixelRatio],
155
+ visible: true,
156
+ zoom: this.map.getZoom() - 1,
178
157
  };
179
- super.renderTrajectories(viewState, noInterpolate);
180
158
  }
181
159
  /**
182
- * Return the delay in ms before the next rendering.
160
+ * Add sources, layers and listeners to the map.
183
161
  */
184
- getRefreshTimeInMs() {
185
- return super.getRefreshTimeInMs(this.map.getZoom());
162
+ onAdd(map, gl) {
163
+ super.onAdd(map, gl);
164
+ this.engine.attachToMap();
165
+ if (map.isStyleLoaded()) {
166
+ this.onLoad();
167
+ }
168
+ map.on('load', this.onLoad);
169
+ }
170
+ onLoad() {
171
+ var _a, _b, _c, _d;
172
+ if (!((_a = this.map) === null || _a === void 0 ? void 0 : _a.getSource(this.sourceId))) {
173
+ (_b = this.map) === null || _b === void 0 ? void 0 : _b.addSource(this.sourceId, this.source);
174
+ }
175
+ if (!((_c = this.map) === null || _c === void 0 ? void 0 : _c.getLayer(this.layer.id))) {
176
+ (_d = this.map) === null || _d === void 0 ? void 0 : _d.addLayer(this.layer, this.id);
177
+ }
178
+ this.start();
186
179
  }
187
180
  /**
188
- * Remove the trajectory form the list if necessary.
181
+ * Callback on 'move' event.
189
182
  */
190
- purgeTrajectory(trajectory, extent, zoom) {
191
- return super.purgeTrajectory(trajectory, extent || toMercatorExtent(this.map.getBounds()), zoom || Math.floor(this.map.getZoom() - 1));
183
+ onMove() {
184
+ this.engine.renderTrajectories();
192
185
  }
193
186
  /**
194
- * Send the current bbox to the websocket
187
+ * Callback on 'moveend' event.
195
188
  */
196
- setBbox(extent, zoom) {
197
- super.setBbox(extent || toMercatorExtent(this.map.getBounds()), zoom || this.map.getZoom() - 1);
189
+ onMoveEnd() {
190
+ this.engine.renderTrajectories();
191
+ if (this.engine.isUpdateBboxOnMoveEnd) {
192
+ this.engine.setBbox();
193
+ }
198
194
  }
199
- renderTrajectoriesInternal(viewState, noInterpolate = false) {
200
- const render = super.renderTrajectoriesInternal(viewState, noInterpolate);
201
- if (render && this.map.style) {
195
+ /**
196
+ * Callback when the RealtimeEngine has rendered successfully.
197
+ */
198
+ onRealtimeEngineRender() {
199
+ var _a;
200
+ if ((_a = this.map) === null || _a === void 0 ? void 0 : _a.style) {
202
201
  const extent = getSourceCoordinates(this.map, this.pixelRatio);
203
- const source = this.map.getSource(this.id);
202
+ const source = this.map.getSource(this.sourceId);
204
203
  if (source) {
204
+ // @ts-expect-error bad type definition
205
205
  source.setCoordinates(extent);
206
206
  }
207
207
  }
208
- return render;
209
208
  }
210
209
  /**
211
- * Callback on 'move' event.
210
+ * Remove source, layers and listeners from the map.
212
211
  */
213
- onMove() {
214
- this.renderTrajectories();
212
+ onRemove(map, gl) {
213
+ this.engine.detachFromMap();
214
+ this.stop();
215
+ map.off('load', this.onLoad);
216
+ if (map.getLayer(this.layer.id)) {
217
+ map.removeLayer(this.layer.id);
218
+ }
219
+ if (map.getSource(this.sourceId)) {
220
+ map.removeSource(this.sourceId);
221
+ }
222
+ super.onRemove(map, gl);
223
+ }
224
+ onZoomEnd() {
225
+ this.engine.onZoomEnd();
215
226
  }
216
227
  /**
217
- * Callback on 'moveend' event.
228
+ * Start updating vehicles position.
229
+ *
230
+ * @public
218
231
  */
219
- onMoveEnd() {
220
- this.renderTrajectories();
221
- if (this.isUpdateBboxOnMoveEnd) {
222
- this.setBbox();
223
- }
232
+ start() {
233
+ var _a, _b, _c;
234
+ this.engine.start();
235
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('move', this.onMove);
236
+ (_b = this.map) === null || _b === void 0 ? void 0 : _b.on('moveend', this.onMoveEnd);
237
+ (_c = this.map) === null || _c === void 0 ? void 0 : _c.on('zoomend', this.onZoomEnd);
238
+ }
239
+ /**
240
+ * Stop updating vehicles position.
241
+ *
242
+ * @public
243
+ */
244
+ stop() {
245
+ var _a, _b, _c;
246
+ this.engine.stop();
247
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.off('move', this.onMove);
248
+ (_b = this.map) === null || _b === void 0 ? void 0 : _b.off('moveend', this.onMoveEnd);
249
+ (_c = this.map) === null || _c === void 0 ? void 0 : _c.off('zoomend', this.onZoomEnd);
250
+ }
251
+ get canvas() {
252
+ return this.engine.canvas;
253
+ }
254
+ get pixelRatio() {
255
+ return this.engine.pixelRatio || 1;
256
+ }
257
+ set pixelRatio(pixelRatio) {
258
+ this.engine.pixelRatio = pixelRatio || 1;
224
259
  }
225
260
  }
261
+ _RealtimeLayer_internalId = new WeakMap();
226
262
  export default RealtimeLayer;
@@ -0,0 +1,2 @@
1
+ export { default as Layer } from "./Layer";
2
+ export { default as RealtimeLayer } from "./RealtimeLayer";
@@ -0,0 +1,7 @@
1
+ import { AnyMapGlMap } from '../../types';
2
+ /**
3
+ * Get the current resolution of a Maplibre map.
4
+ * @param {maplibregl.Map} map A map object.
5
+ */
6
+ declare const getMercatorResolution: (map: AnyMapGlMap) => number;
7
+ export default getMercatorResolution;
@@ -0,0 +1,8 @@
1
+ import { AnyMapGlMap } from '../../types';
2
+ /**
3
+ * Get the canvas source coordinates of the current map's extent.
4
+ * @param {maplibregl.Map} map A map object.
5
+ * @param {number} [pixelRatio=1] The pixel ratio.
6
+ */
7
+ export declare const getSourceCoordinates: (map: AnyMapGlMap, pixelRatio?: number) => number[][];
8
+ export default getSourceCoordinates;
@@ -1,20 +1,21 @@
1
1
  /**
2
2
  * Get the canvas source coordinates of the current map's extent.
3
3
  * @param {maplibregl.Map} map A map object.
4
+ * @param {number} [pixelRatio=1] The pixel ratio.
4
5
  */
5
6
  export const getSourceCoordinates = (map, pixelRatio = 1) => {
6
7
  // Requesting getBounds is not enough when we rotate the map, so we request manually each corner.
7
- const { width, height } = map.getCanvas();
8
- // @ts-ignore
8
+ const { height, width } = map.getCanvas();
9
+ // @ts-expect-error - to fix
9
10
  const leftTop = map.unproject({ x: 0, y: 0 });
10
- // @ts-ignore
11
+ // @ts-expect-error - to fix
11
12
  const leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
12
- // @ts-ignore
13
+ // @ts-expect-error - to fix
13
14
  const rightBottom = map.unproject({
14
15
  x: width / pixelRatio,
15
16
  y: height / pixelRatio,
16
17
  });
17
- // @ts-ignore
18
+ // @ts-expect-error - to fix
18
19
  const rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
19
20
  return [
20
21
  [leftTop.lng, leftTop.lat],
@@ -0,0 +1,2 @@
1
+ export { default as getSourceCoordinates } from "./getSourceCoordinates";
2
+ export { default as getMercatorResolution } from "./getMercatorResolution";