mobility-toolbox-js 3.0.0-beta.9 → 3.0.1-beta.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 (87) hide show
  1. package/api/HttpAPI.d.ts +5 -16
  2. package/api/HttpAPI.js +0 -11
  3. package/api/RealtimeAPI.d.ts +221 -176
  4. package/api/RealtimeAPI.js +317 -258
  5. package/api/RoutingAPI.d.ts +21 -11
  6. package/api/RoutingAPI.js +17 -7
  7. package/api/StopsAPI.d.ts +20 -14
  8. package/api/StopsAPI.js +17 -11
  9. package/api/WebSocketAPI.d.ts +60 -66
  10. package/api/WebSocketAPI.js +164 -164
  11. package/api/index.js +1 -1
  12. package/api/typedefs.d.ts +0 -102
  13. package/api/typedefs.js +27 -42
  14. package/common/controls/StopFinderControlCommon.d.ts +12 -12
  15. package/common/controls/StopFinderControlCommon.js +31 -31
  16. package/common/index.d.ts +1 -1
  17. package/common/index.js +1 -1
  18. package/common/mixins/RealtimeLayerMixin.d.ts +157 -163
  19. package/common/mixins/RealtimeLayerMixin.js +401 -393
  20. package/common/styles/realtimeDefaultStyle.js +6 -6
  21. package/common/styles/realtimeHeadingStyle.js +5 -5
  22. package/common/typedefs.d.ts +13 -6
  23. package/common/typedefs.js +7 -1
  24. package/common/utils/compareDepartures.d.ts +2 -2
  25. package/common/utils/compareDepartures.js +2 -2
  26. package/common/utils/debounceWebsocketMessages.d.ts +1 -1
  27. package/common/utils/getMapGlCopyrights.d.ts +1 -1
  28. package/common/utils/getMapGlCopyrights.js +3 -3
  29. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  30. package/common/utils/getRealtimeModeSuffix.js +1 -0
  31. package/common/utils/getVehiclePosition.d.ts +5 -4
  32. package/common/utils/getVehiclePosition.js +9 -3
  33. package/common/utils/renderTrajectories.d.ts +1 -1
  34. package/common/utils/renderTrajectories.js +6 -6
  35. package/common/utils/sortAndFilterDepartures.d.ts +1 -1
  36. package/common/utils/sortAndFilterDepartures.js +1 -1
  37. package/common/utils/sortByDelay.d.ts +2 -2
  38. package/common/utils/sortByDelay.js +5 -1
  39. package/maplibre/layers/Layer.d.ts +1 -1
  40. package/maplibre/layers/Layer.js +1 -1
  41. package/maplibre/layers/RealtimeLayer.d.ts +87 -66
  42. package/maplibre/layers/RealtimeLayer.js +30 -6
  43. package/maplibre/utils/getSourceCoordinates.js +5 -5
  44. package/mbt.js +20988 -13287
  45. package/mbt.js.map +4 -4
  46. package/mbt.min.js +61 -58
  47. package/mbt.min.js.map +4 -4
  48. package/ol/controls/RoutingControl.d.ts +82 -89
  49. package/ol/controls/RoutingControl.js +217 -219
  50. package/ol/controls/StopFinderControl.d.ts +3 -3
  51. package/ol/controls/StopFinderControl.js +2 -2
  52. package/ol/index.d.ts +1 -0
  53. package/ol/index.js +1 -0
  54. package/ol/layers/Layer.d.ts +101 -0
  55. package/ol/layers/Layer.js +25 -0
  56. package/ol/layers/MaplibreLayer.d.ts +121 -24
  57. package/ol/layers/MaplibreLayer.js +98 -27
  58. package/ol/layers/MaplibreStyleLayer.d.ts +93 -91
  59. package/ol/layers/MaplibreStyleLayer.js +281 -257
  60. package/ol/layers/RealtimeLayer.d.ts +119 -121
  61. package/ol/layers/RealtimeLayer.js +143 -134
  62. package/ol/layers/VectorLayer.d.ts +18 -0
  63. package/ol/layers/VectorLayer.js +32 -0
  64. package/ol/layers/index.d.ts +2 -0
  65. package/ol/layers/index.js +3 -0
  66. package/ol/mixins/MobilityLayerMixin.d.ts +32 -34
  67. package/ol/mixins/PropertiesLayerMixin.d.ts +60 -51
  68. package/ol/mixins/PropertiesLayerMixin.js +114 -79
  69. package/ol/mixins/index.d.ts +1 -0
  70. package/ol/mixins/index.js +2 -0
  71. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
  72. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  73. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
  74. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  75. package/ol/renderers/RealtimeLayerRenderer.d.ts +6 -6
  76. package/ol/renderers/RealtimeLayerRenderer.js +56 -51
  77. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
  78. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  79. package/package.json +31 -31
  80. package/setupTests.js +3 -4
  81. package/types/common.d.ts +55 -48
  82. package/types/index.d.ts +1 -1
  83. package/types/realtime.d.ts +91 -93
  84. package/types/routing.d.ts +60 -60
  85. package/types/stops.d.ts +62 -62
  86. package/ol/layers/MapGlLayer.d.ts +0 -144
  87. package/ol/layers/MapGlLayer.js +0 -144
@@ -8,21 +8,39 @@ import Layer from './Layer';
8
8
  import { getSourceCoordinates } from '../utils';
9
9
  import toMercatorExtent from '../../common/utils/toMercatorExtent';
10
10
  /**
11
- * Responsible for loading and display data from a geOps realtime API.
11
+ * A Maplibre layer able to display data from the [geOps Realtime API](https://developer.geops.io/apis/realtime/).
12
12
  *
13
13
  * @example
14
- * import { RealtimeLayer } from 'mobility-toolbox-js/Maplibre';
14
+ * import { Map } from 'maplibre-gl';
15
+ * import { RealtimeLayer } from 'mobility-toolbox-js/maplibre';
15
16
  *
17
+ * // Define the map
18
+ * const map = new Map({ ... });
19
+ *
20
+ * // Define your layer map
16
21
  * const layer = new RealtimeLayer({
17
22
  * apiKey: "yourApiKey"
18
23
  * // url: "wss://api.geops.io/tracker-ws/v1/",
19
24
  * });
20
25
  *
26
+ * // Add the layer to your map *
27
+ * map.on('load', () => {
28
+ * map.addLayer(layer);
29
+ * });
30
+ *
21
31
  *
22
32
  * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
33
+ * @see <a href="/example/mb-realtime>Live example</a>
23
34
  *
24
- * @implements {maplibregl.CustomLayer}
35
+ * @implements {maplibregl.CustomLayerInterface}
25
36
  * @extends {maplibregl.Evented}
37
+ * @classproperty {function} filter - Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
38
+ * @classproperty {RealtimeMode} mode - The realtime mode to use.
39
+ * @classproperty {RealtimeMot[]} mots - Filter trains by its mode of transportation. It filters trains on backend side.
40
+ * @classproperty {RealtimeTenant} tenant - Filter trains by its tenant. It filters trains on backend side.
41
+ * @classproperty {function} sort - Sort trains. This function must be fast, it is executed on every render frame.
42
+ * @classproperty {function} style - Function to style the vehicles.
43
+ s
26
44
  * @public
27
45
  */
28
46
  class RealtimeLayer extends RealtimeLayerMixin(Layer) {
@@ -31,13 +49,19 @@ class RealtimeLayer extends RealtimeLayerMixin(Layer) {
31
49
  *
32
50
  * @param {RealtimeLayerOptions} options
33
51
  * @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
- *
52
+ * @param {FilterFunction} options.filter Filter out a train. This function must be fast, it is executed for every trajectory on every render frame.
53
+ * @param {getMotsByZoomFunction} options.getMotsByZoom Returns for each zoom level the list of MOTs to display. It filters trains on backend side.
54
+ * @param {number} [options.minZoomInterpolation=8] Minimal zoom level where to start to interpolate train positions.
55
+ * @param {RealtimeMode} [options.mode='topographic'] The realtime mode to use.
56
+ * @param {SortFunction} options.sort Sort trains. This function must be fast, it is executed on every render frame.
57
+ * @param {RealtimeStyleFunction} options.style Function to style the vehicles.
58
+ * @param {RealtimeTenant} options.tenant Filter trains by its tenant. It filters trains on backend side.
59
+ * @param {string} [options.url="wss://api.geops.io/tracker-ws/v1/"] The geOps Realtime API url.
36
60
  */
37
61
  constructor(options = {}) {
38
62
  var _a;
39
63
  const canvas = document.createElement('canvas');
40
- super(Object.assign({ canvas }, options));
64
+ super(Object.assign({ canvas, id: 'realtime' }, options));
41
65
  /** @private */
42
66
  this.source = {
43
67
  id: this.id,
@@ -4,17 +4,17 @@
4
4
  */
5
5
  export const getSourceCoordinates = (map, pixelRatio = 1) => {
6
6
  // 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
7
+ const { height, width } = map.getCanvas();
8
+ // @ts-expect-error
9
9
  const leftTop = map.unproject({ x: 0, y: 0 });
10
- // @ts-ignore
10
+ // @ts-expect-error
11
11
  const leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
12
- // @ts-ignore
12
+ // @ts-expect-error
13
13
  const rightBottom = map.unproject({
14
14
  x: width / pixelRatio,
15
15
  y: height / pixelRatio,
16
16
  });
17
- // @ts-ignore
17
+ // @ts-expect-error
18
18
  const rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
19
19
  return [
20
20
  [leftTop.lng, leftTop.lat],