mobility-toolbox-js 3.0.0-beta.9 → 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 (105) hide show
  1. package/README.md +11 -3
  2. package/api/HttpAPI.d.ts +5 -16
  3. package/api/HttpAPI.js +1 -14
  4. package/api/RealtimeAPI.d.ts +188 -143
  5. package/api/RealtimeAPI.js +265 -206
  6. package/api/RoutingAPI.d.ts +21 -11
  7. package/api/RoutingAPI.js +17 -7
  8. package/api/StopsAPI.d.ts +20 -14
  9. package/api/StopsAPI.js +17 -11
  10. package/api/WebSocketAPI.d.ts +60 -66
  11. package/api/WebSocketAPI.js +164 -165
  12. package/api/index.js +1 -1
  13. package/api/typedefs.d.ts +0 -102
  14. package/api/typedefs.js +27 -42
  15. package/common/controls/StopFinderControlCommon.d.ts +13 -13
  16. package/common/controls/StopFinderControlCommon.js +32 -32
  17. package/common/index.d.ts +1 -1
  18. package/common/index.js +1 -1
  19. package/common/styles/realtimeDefaultStyle.js +6 -11
  20. package/common/styles/realtimeHeadingStyle.js +5 -10
  21. package/common/styles/realtimeSimpleStyle.d.ts +0 -1
  22. package/common/styles/realtimeSimpleStyle.js +0 -1
  23. package/common/typedefs.d.ts +11 -121
  24. package/common/typedefs.js +6 -31
  25. package/common/utils/RealtimeEngine.d.ts +214 -0
  26. package/common/utils/RealtimeEngine.js +554 -0
  27. package/common/utils/compareDepartures.d.ts +2 -2
  28. package/common/utils/compareDepartures.js +2 -2
  29. package/common/utils/debounceWebsocketMessages.d.ts +1 -1
  30. package/common/utils/getLayersAsFlatArray.d.ts +0 -1
  31. package/common/utils/getLayersAsFlatArray.js +0 -1
  32. package/common/utils/getMapGlCopyrights.d.ts +1 -1
  33. package/common/utils/getMapGlCopyrights.js +3 -3
  34. package/common/utils/getRealtimeModeSuffix.d.ts +1 -0
  35. package/common/utils/getRealtimeModeSuffix.js +1 -0
  36. package/common/utils/getVehiclePosition.d.ts +5 -4
  37. package/common/utils/getVehiclePosition.js +6 -3
  38. package/common/utils/realtimeConfig.d.ts +1 -1
  39. package/common/utils/realtimeConfig.js +0 -1
  40. package/common/utils/renderTrajectories.d.ts +2 -1
  41. package/common/utils/renderTrajectories.js +7 -6
  42. package/common/utils/sortAndFilterDepartures.d.ts +2 -1
  43. package/common/utils/sortAndFilterDepartures.js +2 -1
  44. package/common/utils/sortByDelay.d.ts +2 -2
  45. package/common/utils/sortByDelay.js +5 -1
  46. package/maplibre/controls/CopyrightControl.d.ts +9 -6
  47. package/maplibre/controls/CopyrightControl.js +11 -8
  48. package/maplibre/layers/Layer.d.ts +8 -7
  49. package/maplibre/layers/Layer.js +2 -3
  50. package/maplibre/layers/RealtimeLayer.d.ts +82 -118
  51. package/maplibre/layers/RealtimeLayer.js +154 -118
  52. package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
  53. package/maplibre/utils/getSourceCoordinates.js +6 -5
  54. package/mbt.js +14611 -14591
  55. package/mbt.js.map +4 -4
  56. package/mbt.min.js +75 -75
  57. package/mbt.min.js.map +4 -4
  58. package/ol/controls/CopyrightControl.d.ts +13 -5
  59. package/ol/controls/CopyrightControl.js +13 -5
  60. package/ol/controls/RoutingControl.d.ts +105 -101
  61. package/ol/controls/RoutingControl.js +250 -264
  62. package/ol/controls/StopFinderControl.d.ts +24 -5
  63. package/ol/controls/StopFinderControl.js +24 -5
  64. package/ol/layers/Layer.d.ts +26 -0
  65. package/ol/layers/Layer.js +39 -0
  66. package/ol/layers/MaplibreLayer.d.ts +56 -28
  67. package/ol/layers/MaplibreLayer.js +154 -31
  68. package/ol/layers/MaplibreStyleLayer.d.ts +71 -149
  69. package/ol/layers/MaplibreStyleLayer.js +281 -210
  70. package/ol/layers/RealtimeLayer.d.ts +95 -230
  71. package/ol/layers/RealtimeLayer.js +209 -211
  72. package/ol/layers/VectorLayer.d.ts +17 -0
  73. package/ol/layers/VectorLayer.js +33 -0
  74. package/ol/layers/index.d.ts +2 -0
  75. package/ol/layers/index.js +3 -0
  76. package/ol/renderers/MaplibreLayerRenderer.d.ts +0 -20
  77. package/ol/renderers/MaplibreLayerRenderer.js +142 -114
  78. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
  79. package/ol/renderers/MaplibreStyleLayerRenderer.js +20 -23
  80. package/ol/renderers/RealtimeLayerRenderer.d.ts +7 -7
  81. package/ol/renderers/RealtimeLayerRenderer.js +46 -66
  82. package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
  83. package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
  84. package/ol/styles/fullTrajectoryStyle.js +5 -7
  85. package/ol/styles/routingStyle.d.ts +0 -1
  86. package/ol/styles/routingStyle.js +13 -10
  87. package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
  88. package/ol/utils/defineDeprecatedProperties.js +180 -0
  89. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
  90. package/ol/utils/getFeatureInfoAtCoordinate.js +11 -17
  91. package/package.json +44 -44
  92. package/setupTests.js +17 -4
  93. package/types/common.d.ts +53 -69
  94. package/types/index.d.ts +1 -1
  95. package/types/realtime.d.ts +98 -95
  96. package/types/routing.d.ts +60 -60
  97. package/types/stops.d.ts +62 -62
  98. package/common/mixins/RealtimeLayerMixin.d.ts +0 -273
  99. package/common/mixins/RealtimeLayerMixin.js +0 -743
  100. package/ol/layers/MapGlLayer.d.ts +0 -144
  101. package/ol/layers/MapGlLayer.js +0 -144
  102. package/ol/mixins/MobilityLayerMixin.d.ts +0 -98
  103. package/ol/mixins/MobilityLayerMixin.js +0 -6
  104. package/ol/mixins/PropertiesLayerMixin.d.ts +0 -127
  105. package/ol/mixins/PropertiesLayerMixin.js +0 -143
@@ -1,155 +1,73 @@
1
+ import { FeatureState } from 'maplibre-gl';
1
2
  import { Feature, Map } from 'ol';
2
3
  import { Coordinate } from 'ol/coordinate';
3
- import { ObjectEvent } from 'ol/Object';
4
+ import { EventsKey } from 'ol/events';
4
5
  import { Layer } from 'ol/layer';
5
- import { Source } from 'ol/source';
6
- import { LayerGetFeatureInfoResponse } from '../../types';
6
+ import { ObjectEvent } from 'ol/Object';
7
7
  import { FilterFunction } from '../../common/typedefs';
8
- import MaplibreLayer, { MaplibreLayerOptions } from './MaplibreLayer';
8
+ import { LayerGetFeatureInfoResponse } from '../../types';
9
9
  import MaplibreStyleLayerRenderer from '../renderers/MaplibreStyleLayerRenderer';
10
- export type MaplibreStyleLayerOptions = MaplibreLayerOptions & {
10
+ import MaplibreLayer, { MaplibreLayerOptions } from './MaplibreLayer';
11
+ export type MaplibreStyleLayerOptions = {
11
12
  beforeId?: string;
12
- maplibreLayer?: MaplibreLayer;
13
13
  layers?: maplibregl.AddLayerObject[];
14
14
  layersFilter?: FilterFunction;
15
+ maplibreLayer?: MaplibreLayer;
15
16
  queryRenderedLayersFilter?: FilterFunction;
16
- };
17
- declare const MaplibreStyleLayer_base: {
18
- new (...args: any[]): {
19
- options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions | undefined;
20
- olListenersKeys: import("ol/events").EventsKey[];
21
- children: Layer<Source, import("ol/renderer/Layer").default<any>>[];
22
- get copyrights(): string;
23
- set copyrights(newCopyrights: string | string[]);
24
- disabled: boolean;
25
- readonly group: string;
26
- readonly hitTolerance: boolean;
27
- readonly key: string;
28
- readonly map: Map;
29
- readonly name: string;
30
- olLayer: Layer<Source, import("ol/renderer/Layer").default<any>>;
31
- parent: Layer<Source, import("ol/renderer/Layer").default<any>>;
32
- visible: boolean;
33
- setMapInternal: ((map: Map) => void) & ((map: Map | null) => void);
34
- onChildrenChange(oldValue: Layer<Source, import("ol/renderer/Layer").default<any>>[]): void;
35
- attachToMap(map: Map): void;
36
- detachFromMap(): void;
37
- flat(): any[];
38
- addEventListener: (type: string, listener: import("ol/events").Listener) => void;
39
- removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
40
- on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
41
- render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
42
- once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
43
- un: import("ol/layer/Layer").LayerOnSignature<void>;
44
- getSource: () => Source | null;
45
- getRenderSource: () => Source | null;
46
- getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<import("ol/Feature").FeatureLike[]>;
47
- getData: (pixel: import("ol/pixel").Pixel) => Float32Array | Uint8ClampedArray | Uint8Array | DataView | null;
48
- isVisible: (view?: import("ol/View").default | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
49
- getAttributions: (view?: import("ol/View").default | import("ol/View").ViewStateLayerStateExtent | undefined) => string[];
50
- unrender: () => void;
51
- getDeclutter: () => string;
52
- renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
53
- renderDeferred: (frameState: import("ol/Map").FrameState) => void;
54
- getMapInternal: () => Map | null;
55
- setMap: (map: Map | null) => void;
56
- setSource: (source: Source | null) => void;
57
- getRenderer: () => import("ol/renderer/Layer").default<any> | null;
58
- hasRenderer: () => boolean;
59
- getBackground: () => false | import("ol/layer/Base").BackgroundColor;
60
- getClassName: () => string;
61
- getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
62
- getLayersArray: (array?: Layer<Source, import("ol/renderer/Layer").default<any>>[] | undefined) => Layer<Source, import("ol/renderer/Layer").default<any>>[];
63
- getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => import("ol/layer/Layer").State[];
64
- getExtent: () => import("ol/extent").Extent | undefined;
65
- getMaxResolution: () => number;
66
- getMinResolution: () => number;
67
- getMinZoom: () => number;
68
- getMaxZoom: () => number;
69
- getOpacity: () => number;
70
- getSourceState: () => import("ol/source/Source").State;
71
- getVisible: () => boolean;
72
- getZIndex: () => number | undefined;
73
- setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
74
- setExtent: (extent: import("ol/extent").Extent | undefined) => void;
75
- setMaxResolution: (maxResolution: number) => void;
76
- setMinResolution: (minResolution: number) => void;
77
- setMaxZoom: (maxZoom: number) => void;
78
- setMinZoom: (minZoom: number) => void;
79
- setOpacity: (opacity: number) => void;
80
- setVisible: (visible: boolean) => void;
81
- setZIndex: (zindex: number) => void;
82
- get: (key: string) => any;
83
- getKeys: () => string[];
84
- getProperties: () => {
85
- [x: string]: any;
86
- };
87
- getPropertiesInternal: () => {
88
- [x: string]: any;
89
- } | null;
90
- hasProperties: () => boolean;
91
- notify: (key: string, oldValue: any) => void;
92
- addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
93
- removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
94
- set: (key: string, value: any, silent?: boolean | undefined) => void;
95
- setProperties: (values: {
96
- [x: string]: any;
97
- }, silent?: boolean | undefined) => void;
98
- unset: (key: string, silent?: boolean | undefined) => void;
99
- changed: () => void;
100
- getRevision: () => number;
101
- dispatchEvent: (event: string | import("ol/events/Event").default) => boolean | undefined;
102
- getListeners: (type: string) => import("ol/events").Listener[] | undefined;
103
- hasListener: (type?: string | undefined) => boolean;
104
- dispose: () => void;
105
- };
106
- } & typeof Layer;
17
+ } & MaplibreLayerOptions;
107
18
  /**
108
- * Layer for visualizing a specific set of layer from a MapboxLayer.
19
+ * Layer that helps show/hide a specific subset of style layers of a [MaplibreLayer](./MaplibreLayer.js~MaplibreLayer.html).
109
20
  *
110
21
  * @example
111
- * import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
22
+ * import { MaplibreLayer, MaplibreStyleLayer } from 'mobility-toolbox-js/ol';
112
23
  *
113
- * const maplibreLayer = new MapboxLayer({
114
- * url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
24
+ * const maplibreLayer = new MaplibreLayer({
25
+ * apiKey: 'yourApiKey',
115
26
  * });
116
27
  *
117
- * const layer = new MapboxStyleLayer({
28
+ * const layer = new MaplibreStyleLayer({
118
29
  * maplibreLayer: maplibreLayer,
119
- * styleLayersFilter: () => {},
30
+ * layersFilter: (layer) => {
31
+ * // show/hide only style layers related to stations
32
+ * return /station/.test(layer.id);
33
+ * },
120
34
  * });
121
35
  *
122
- * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
36
+ * @see <a href="/example/ol-maplibre-style-layer">OpenLayers MaplibreStyle layer example</a>
123
37
  * @extends {ol/layer/Layer~Layer}
38
+ * @public
124
39
  */
125
- declare class MaplibreStyleLayer extends MaplibreStyleLayer_base {
40
+ declare class MaplibreStyleLayer extends Layer {
126
41
  highlightedFeatures: Feature[];
42
+ olEventsKeys: EventsKey[];
127
43
  selectedFeatures: Feature[];
128
44
  get beforeId(): string;
129
- set beforeId(newValue: string[]);
45
+ set beforeId(newValue: string | undefined);
130
46
  get layers(): maplibregl.AddLayerObject[];
131
47
  set layers(newValue: maplibregl.AddLayerObject[]);
132
48
  get layersFilter(): (layer: maplibregl.LayerSpecification) => boolean;
133
49
  set layersFilter(newValue: (layer: maplibregl.LayerSpecification) => boolean);
50
+ /**
51
+ * @deprecated Use MaplibreStyleLayer.maplibreLayer instead.
52
+ */
134
53
  get mapboxLayer(): MaplibreLayer | undefined;
135
54
  get maplibreLayer(): MaplibreLayer;
136
55
  set maplibreLayer(newValue: MaplibreLayer);
137
56
  get queryRenderedLayersFilter(): (layer: maplibregl.LayerSpecification) => boolean;
138
57
  set queryRenderedLayersFilter(newValue: (layer: maplibregl.LayerSpecification) => boolean);
139
- get sources(): {
140
- [key: string]: maplibregl.SourceSpecification;
141
- };
142
- set sources(newValue: {
143
- [key: string]: maplibregl.SourceSpecification;
144
- });
58
+ get sources(): Record<string, maplibregl.SourceSpecification>;
59
+ set sources(newValue: Record<string, maplibregl.SourceSpecification>);
145
60
  /**
146
- * @deprecated
61
+ * @deprecated Use MaplibreStyleLayer.layer instead.
147
62
  */
148
63
  get styleLayer(): maplibregl.AddLayerObject;
149
64
  /**
150
65
  * @deprecated
151
66
  */
152
67
  set styleLayer(newValue: maplibregl.AddLayerObject);
68
+ /**
69
+ * Apply visibility to style layers that fits the styleLayersFilter function.
70
+ */
153
71
  /**
154
72
  * @deprecated
155
73
  */
@@ -162,74 +80,78 @@ declare class MaplibreStyleLayer extends MaplibreStyleLayer_base {
162
80
  * Constructor.
163
81
  *
164
82
  * @param {Object} options
165
- * @param {MapboxLayer} [options.maplibreLayer] The MaplibreLayer to use.
166
- * @param {maplibregl.SourceSpecification[]} [options.sources] The source to add to the style on load.
83
+ * @param {string} [options.beforeId] The style layer id to use when the options.layers property is defined, unsused otherwise.
167
84
  * @param {maplibregl.AddLayerObject[]} [options.layers] The layers to add to the style on load.
168
85
  * @param {FilterFunction} [options.layersFilter] Filter function to decide which style layer to apply visiblity on. If not provided, the 'layers' property is used.
86
+ * @param {MaplibreLayer} [options.maplibreLayer] The MaplibreLayer to use.
169
87
  * @param {FilterFunction} [options.queryRenderedLayersFilter] Filter function to decide which style layer are available for query.
88
+ * @param {{[id: string]:maplibregl.SourceSpecification}} [options.sources] The sources to add to the style on load.
89
+ * @public
170
90
  */
171
- constructor(options: MaplibreStyleLayerOptions);
172
- createRenderer(): MaplibreStyleLayerRenderer;
91
+ constructor(options?: MaplibreStyleLayerOptions);
92
+ addLayers(): void;
93
+ addSources(): void;
94
+ applyLayoutVisibility(evt?: ObjectEvent): void;
173
95
  /**
174
96
  * Initialize the layer.
175
97
  * @param {ol/Map~Map} map the Maplibre map.
176
98
  * @override
177
99
  */
178
100
  attachToMap(map: Map): void;
101
+ /**
102
+ * Create a copy of the MaplibreStyleLayer.
103
+ *
104
+ * @param {Object} newOptions Options to override. See constructor.
105
+ * @return {MapboxStyleLayer} A MaplibreStyleLayer.
106
+ * @public
107
+ */
108
+ clone(newOptions: MaplibreStyleLayerOptions): MaplibreStyleLayer;
109
+ createRenderer(): MaplibreStyleLayerRenderer;
179
110
  /**
180
111
  * Terminate the layer.
181
112
  * @override
182
113
  */
183
114
  detachFromMap(): void;
184
- /** @private */
185
- addSources(): void;
186
- /** @private */
187
- removeSources(): void;
188
- /** @private */
189
- addLayers(): void;
190
- /** @private */
191
- removeLayers(): void;
192
- /**
193
- * On Maplibre map load callback function. Add style layers and dynaimc filters.
194
- * @private
195
- */
196
- onLoad(): void;
197
115
  /**
198
116
  * Request feature information for a given coordinate.
199
117
  * @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
200
118
  * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
119
+ * @deprecated Use getFeatureInfoAtCoordinate([layer], coordinate) from mobility-toolbox-ol package instead.
201
120
  */
202
121
  getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
203
122
  /**
204
- * Set if features are hovered or not.
205
- * @param {Array<ol/Feature~Feature>} features
206
- * @param {boolean} state Is the feature hovered
207
- * @private
123
+ * Highlight a list of features.
124
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
125
+ * @deprecated Use layer.setFeatureState(features, {hover: true|false}) instead.
208
126
  */
209
- setHoverState(features: Feature[], state: boolean): void;
127
+ highlight(features?: Feature[]): void;
128
+ /**
129
+ * On Maplibre map load callback function. Add style layers and dynaimc filters.
130
+ */
131
+ onLoad(): void;
132
+ removeLayers(): void;
133
+ removeSources(): void;
210
134
  /**
211
135
  * Select a list of features.
212
136
  * @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
213
- * @private
137
+ * @deprecated Use layer.setFeatureState(features, {selected: true|false}) instead.
214
138
  */
215
139
  select(features?: Feature[]): void;
216
140
  /**
217
- * Highlight a list of features.
218
- * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
219
- * @private
220
- */
221
- highlight(features?: Feature[]): void;
222
- /**
223
- * Apply visibility to style layers that fits the styleLayersFilter function.
141
+ * Set the [feature state](https://maplibre.org/maplibre-style-spec/expressions/#feature-state) of the features.
224
142
  *
225
- * @private
143
+ * @param {ol/Feature~Feature[]} features
144
+ * @param {{[key: string]: any}} state The feature state
145
+ * @public
226
146
  */
227
- applyLayoutVisibility(evt?: ObjectEvent): void;
147
+ setFeatureState(features: Feature[], state: FeatureState): void;
228
148
  /**
229
- * Create a copy of the MapboxStyleLayer.
230
- * @param {Object} newOptions Options to override.
231
- * @return {MapboxStyleLayer} A MapboxStyleLayer.
149
+ * Set if features are hovered or not.
150
+ * @param {Array<ol/Feature~Feature>} features
151
+ * @param {boolean} state Is the feature hovered
152
+ * @deprecated Use layer.setFeatureState(features, {hover: true|false}) instead.
232
153
  */
233
- clone(newOptions: MaplibreStyleLayerOptions): MaplibreStyleLayer;
154
+ setHoverState(features: Feature[], state: boolean): void;
155
+ setMapInternal(map: Map): void;
234
156
  }
235
157
  export default MaplibreStyleLayer;