mobility-toolbox-js 3.0.0-beta.2 → 3.0.0-beta.20

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 +344 -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 +16 -10
  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 +22160 -14512
  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 +4 -1
  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 +101 -0
  87. package/ol/layers/Layer.js +17 -0
  88. package/ol/layers/MaplibreLayer.d.ts +160 -0
  89. package/ol/layers/MaplibreLayer.js +88 -24
  90. package/ol/layers/MaplibreStyleLayer.d.ts +242 -0
  91. package/ol/layers/MaplibreStyleLayer.js +291 -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 +31 -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 +98 -0
  99. package/ol/mixins/MobilityLayerMixin.js +1 -4
  100. package/ol/mixins/PropertiesLayerMixin.d.ts +135 -0
  101. package/ol/mixins/PropertiesLayerMixin.js +108 -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
@@ -1,8 +1,8 @@
1
1
  import { Layer } from 'ol/layer';
2
2
  import { Source } from 'ol/source';
3
+ import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
3
4
  import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
4
5
  import MaplibreStyleLayerRenderer from '../renderers/MaplibreStyleLayerRenderer';
5
- import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
6
6
  /**
7
7
  * Layer for visualizing a specific set of layer from a MapboxLayer.
8
8
  *
@@ -22,79 +22,6 @@ import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
22
22
  * @extends {ol/layer/Layer~Layer}
23
23
  */
24
24
  class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
25
- get beforeId() {
26
- return this.get('beforeId');
27
- }
28
- set beforeId(newValue) {
29
- this.set('beforeId', newValue);
30
- }
31
- get layers() {
32
- return this.get('layers');
33
- }
34
- set layers(newValue) {
35
- this.set('layers', newValue);
36
- }
37
- get layersFilter() {
38
- return this.get('layersFilter');
39
- }
40
- set layersFilter(newValue) {
41
- this.set('layersFilter', newValue);
42
- }
43
- get mapboxLayer() {
44
- // eslint-disable-next-line no-console
45
- console.warn('Deprecated. Use maplibreLayer instead.');
46
- return this.get('maplibreLayer');
47
- }
48
- get maplibreLayer() {
49
- return this.get('maplibreLayer');
50
- }
51
- set maplibreLayer(newValue) {
52
- this.set('maplibreLayer', newValue);
53
- }
54
- get queryRenderedLayersFilter() {
55
- return this.get('queryRenderedLayersFilter');
56
- }
57
- set queryRenderedLayersFilter(newValue) {
58
- this.set('queryRenderedLayersFilter', newValue);
59
- }
60
- get sources() {
61
- return this.get('sources');
62
- }
63
- set sources(newValue) {
64
- this.set('sources', newValue);
65
- }
66
- /**
67
- * @deprecated
68
- */
69
- get styleLayer() {
70
- // eslint-disable-next-line no-console
71
- console.warn('Deprecated. Use layers instead.');
72
- return this.layers[0];
73
- }
74
- /**
75
- * @deprecated
76
- */
77
- set styleLayer(newValue) {
78
- // eslint-disable-next-line no-console
79
- console.warn('Deprecated. Use layers instead.');
80
- this.layers = [newValue];
81
- }
82
- /**
83
- * @deprecated
84
- */
85
- get styleLayers() {
86
- // eslint-disable-next-line no-console
87
- console.warn('Deprecated. Use layers instead.');
88
- return this.layers;
89
- }
90
- /**
91
- * @deprecated
92
- */
93
- set styleLayers(newValue) {
94
- // eslint-disable-next-line no-console
95
- console.warn('Deprecated. Use layers instead.');
96
- this.layers = newValue;
97
- }
98
25
  /**
99
26
  * Constructor.
100
27
  *
@@ -105,8 +32,19 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
105
32
  * @param {FilterFunction} [options.layersFilter] Filter function to decide which style layer to apply visiblity on. If not provided, the 'layers' property is used.
106
33
  * @param {FilterFunction} [options.queryRenderedLayersFilter] Filter function to decide which style layer are available for query.
107
34
  */
108
- constructor(options) {
109
- super(Object.assign({ source: new Source({}) }, (options || {})));
35
+ constructor(options = {
36
+ mapLibreOptions: { style: { layers: [], sources: {}, version: 8 } },
37
+ }) {
38
+ /** Manage renamed property for backward compatibility with v2 */
39
+ if (options.mapboxLayer) {
40
+ // eslint-disable-next-line no-console
41
+ console.warn('options.mapboxLayer is deprecated. Use options.maplibreLayer instead.');
42
+ // eslint-disable-next-line no-param-reassign
43
+ options.maplibreLayer = options.mapboxLayer;
44
+ // eslint-disable-next-line no-param-reassign
45
+ delete options.mapboxLayer;
46
+ }
47
+ super(Object.assign({ source: new Source({}) }, options));
110
48
  this.highlightedFeatures = [];
111
49
  this.selectedFeatures = [];
112
50
  /**
@@ -119,8 +57,64 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
119
57
  };
120
58
  }
121
59
  }
122
- createRenderer() {
123
- return new MaplibreStyleLayerRenderer(this);
60
+ /** @private */
61
+ addLayers() {
62
+ var _a;
63
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !Array.isArray(this.layers)) {
64
+ return;
65
+ }
66
+ const { mapLibreMap } = this.maplibreLayer;
67
+ if (mapLibreMap) {
68
+ this.layers.forEach((layer) => {
69
+ // @ts-expect-error source is optional but exists in TS definition
70
+ const { id, source } = layer;
71
+ if ((!source || (source && mapLibreMap.getSource(source))) &&
72
+ id &&
73
+ !mapLibreMap.getLayer(id)) {
74
+ mapLibreMap.addLayer(layer, this.beforeId);
75
+ }
76
+ });
77
+ this.applyLayoutVisibility();
78
+ }
79
+ }
80
+ /** @private */
81
+ addSources() {
82
+ var _a;
83
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !this.sources) {
84
+ return;
85
+ }
86
+ const { mapLibreMap } = this.maplibreLayer;
87
+ if (mapLibreMap) {
88
+ Object.entries(this.sources).forEach(([id, source]) => {
89
+ if (!mapLibreMap.getSource(id)) {
90
+ mapLibreMap.addSource(id, source);
91
+ }
92
+ });
93
+ }
94
+ }
95
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
96
+ applyLayoutVisibility(evt) {
97
+ var _a, _b;
98
+ if (!((_b = (_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) === null || _b === void 0 ? void 0 : _b.getStyle()) || !this.layersFilter) {
99
+ return;
100
+ }
101
+ const { mapLibreMap } = this.maplibreLayer;
102
+ const style = mapLibreMap.getStyle();
103
+ const visibilityValue = this.getVisible() ? 'visible' : 'none';
104
+ const layers = style.layers || [];
105
+ for (let i = 0; i < layers.length; i += 1) {
106
+ const layer = layers[i];
107
+ if (this.layersFilter(layer)) {
108
+ const { id } = layer;
109
+ if (mapLibreMap.getLayer(id)) {
110
+ mapLibreMap.setLayoutProperty(id, 'visibility', visibilityValue);
111
+ if (this.getMinZoom() || this.getMaxZoom()) {
112
+ mapLibreMap.setLayerZoomRange(id, this.getMinZoom() ? this.getMinZoom() - 1 : 0, // Maplibre zoom = ol zoom - 1
113
+ this.getMaxZoom() ? this.getMaxZoom() - 1 : 24);
114
+ }
115
+ }
116
+ }
117
+ }
124
118
  }
125
119
  /**
126
120
  * Initialize the layer.
@@ -135,139 +129,66 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
135
129
  if (!this.map || !this.maplibreLayer) {
136
130
  return;
137
131
  }
138
- // Apply the initial visibiltity.
139
- const { maplibreMap } = this.maplibreLayer;
140
- if (!maplibreMap) {
141
- // If the maplibreMap is not yet created because the map has no target yet, we
132
+ if (!this.map.getTargetElement()) {
133
+ // If ther e is no target element the mapLibreMap is not yet created, we
142
134
  // relaunch the initialisation when it's the case.
143
- this.olListenersKeys.push(this.map.on('change:target', () => {
135
+ this.olEventsKeys.push(this.map.on('change:target', () => {
144
136
  this.attachToMap(map);
145
137
  }));
146
138
  return;
147
139
  }
148
- // maplibreMap.loaded() and maplibreMap.isStyleLoaded() are reliable only on the first call of init.
149
- // On the next call (when a topic change for example), these functions returns false because
150
- // the style is being modified.
151
- // That's why we rely on a property instead for the next calls.
152
- if (maplibreMap.loaded()) {
153
- this.onLoad();
154
- }
155
- else {
156
- maplibreMap.once('load', this.onLoad);
140
+ // Apply the initial visibility if possible otherwise we wait for the load event of the layer
141
+ const { mapLibreMap } = this.maplibreLayer;
142
+ if (mapLibreMap) {
143
+ // mapLibreMap.loaded() and mapLibreMap.isStyleLoaded() are reliable only on the first call of init.
144
+ // On the next call (when a topic change for example), these functions returns false because
145
+ // the style is being modified.
146
+ // That's why we rely on a property instead for the next calls.
147
+ if (mapLibreMap.loaded()) {
148
+ this.onLoad();
149
+ }
150
+ else {
151
+ mapLibreMap.once('load', this.onLoad);
152
+ }
157
153
  }
158
154
  // Apply the visibiltity when layer's visibility change.
159
- this.olListenersKeys.push(
160
- // @ts-expect-error 'load' is a custom event form mobility-toolbox-js
155
+ this.olEventsKeys.push(
156
+ // @ts-expect-error 'load' is a custom event
161
157
  this.maplibreLayer.on('load', this.onLoad.bind(this)), this.on('change:visible', (evt) => {
162
158
  // Once the map is loaded we can apply visiblity without waiting
163
159
  // the style. Maplibre take care of the application of style changes.
164
160
  this.applyLayoutVisibility(evt);
165
161
  }), this.on('propertychange', (evt) => {
166
- if (/(sources|layers|layersFilter|maplibreLayer|beforeId|)/.test(evt.key)) {
162
+ if (/(sources|layers|layersFilter|maplibreLayer|beforeId)/.test(evt.key)) {
167
163
  this.detachFromMap();
168
164
  this.attachToMap(map);
169
165
  }
170
166
  }));
171
167
  }
168
+ /**
169
+ * Create a copy of the MapboxStyleLayer.
170
+ * @param {Object} newOptions Options to override.
171
+ * @return {MapboxStyleLayer} A MapboxStyleLayer.
172
+ */
173
+ clone(newOptions) {
174
+ return new MaplibreStyleLayer(Object.assign(Object.assign({}, this.options), newOptions));
175
+ }
176
+ createRenderer() {
177
+ return new MaplibreStyleLayerRenderer(this);
178
+ }
172
179
  /**
173
180
  * Terminate the layer.
174
181
  * @override
175
182
  */
176
183
  detachFromMap() {
177
184
  var _a;
178
- if ((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) {
179
- this.maplibreLayer.maplibreMap.off('load', this.onLoad);
185
+ if ((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) {
186
+ this.maplibreLayer.mapLibreMap.off('load', this.onLoad);
180
187
  this.removeLayers();
181
188
  this.removeSources();
182
189
  }
183
190
  super.detachFromMap();
184
191
  }
185
- /** @private */
186
- addSources() {
187
- var _a;
188
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.sources)) {
189
- return;
190
- }
191
- const { maplibreMap } = this.maplibreLayer;
192
- if (maplibreMap) {
193
- this.sources.forEach((source) => {
194
- const { id } = source;
195
- if (!maplibreMap.getSource(id)) {
196
- maplibreMap.addSource(id, source);
197
- }
198
- });
199
- }
200
- }
201
- /** @private */
202
- removeSources() {
203
- var _a;
204
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.layers)) {
205
- return;
206
- }
207
- const { maplibreMap } = this.maplibreLayer;
208
- if (maplibreMap) {
209
- this.sources.forEach((source) => {
210
- const { id } = source;
211
- if (maplibreMap.getSource(id)) {
212
- maplibreMap.removeSource(id);
213
- }
214
- });
215
- }
216
- }
217
- /** @private */
218
- addLayers() {
219
- var _a;
220
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.layers)) {
221
- return;
222
- }
223
- const { maplibreMap } = this.maplibreLayer;
224
- if (maplibreMap) {
225
- this.layers.forEach((layer) => {
226
- // @ts-expect-error source is optional but exists in TS definition
227
- const { id, source } = layer;
228
- if ((!source || (source && maplibreMap.getSource(source))) &&
229
- id &&
230
- !maplibreMap.getLayer(id)) {
231
- maplibreMap.addLayer(layer, this.beforeId);
232
- }
233
- });
234
- this.applyLayoutVisibility();
235
- }
236
- }
237
- /** @private */
238
- removeLayers() {
239
- var _a;
240
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.layers)) {
241
- return;
242
- }
243
- const { maplibreMap } = this.maplibreLayer;
244
- if (maplibreMap) {
245
- this.layers.forEach((styleLayer) => {
246
- const { id } = styleLayer;
247
- if (id && maplibreMap.getLayer(id)) {
248
- maplibreMap.removeLayer(id);
249
- }
250
- });
251
- }
252
- }
253
- /**
254
- * On Maplibre map load callback function. Add style layers and dynaimc filters.
255
- * @private
256
- */
257
- onLoad() {
258
- var _a;
259
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap)) {
260
- return;
261
- }
262
- this.addSources();
263
- this.addLayers();
264
- const { maplibreMap } = this.maplibreLayer;
265
- const style = maplibreMap.getStyle();
266
- if ((style === null || style === void 0 ? void 0 : style.layers) && this.layersFilter) {
267
- const styles = style.layers.filter(this.layersFilter);
268
- this.disabled = !styles.length;
269
- }
270
- }
271
192
  /**
272
193
  * Request feature information for a given coordinate.
273
194
  * @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
@@ -275,30 +196,31 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
275
196
  */
276
197
  getFeatureInfoAtCoordinate(coordinate) {
277
198
  var _a;
278
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap)) {
199
+ // eslint-disable-next-line no-console
200
+ console.warn(`Deprecated. getFeatureInfoAtCoordinate([layer], coordinate) from ol package instead.`);
201
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap)) {
279
202
  return Promise.resolve({ coordinate, features: [], layer: this });
280
203
  }
281
- const { maplibreMap } = this.maplibreLayer;
204
+ const { mapLibreMap } = this.maplibreLayer;
282
205
  // Ignore the getFeatureInfo until the Maplibre map is loaded
283
- if (!maplibreMap.isStyleLoaded()) {
206
+ if (!mapLibreMap.isStyleLoaded()) {
284
207
  return Promise.resolve({ coordinate, features: [], layer: this });
285
208
  }
286
209
  // We query features only on style layers used by this layer.
287
210
  let layers = this.layers || [];
288
211
  if (this.layersFilter) {
289
- layers = maplibreMap.getStyle().layers.filter(this.layersFilter);
212
+ layers = mapLibreMap.getStyle().layers.filter(this.layersFilter);
290
213
  }
291
214
  if (this.queryRenderedLayersFilter) {
292
- // @ts-ignore
293
215
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
294
- layers = maplibreMap
216
+ layers = mapLibreMap
295
217
  .getStyle()
296
218
  .layers.filter(this.queryRenderedLayersFilter);
297
219
  }
298
220
  return Promise.resolve({
221
+ coordinate,
299
222
  features: [],
300
223
  layer: this,
301
- coordinate,
302
224
  });
303
225
  // this.maplibreLayer
304
226
  // .getFeatureInfoAtCoordinate(coordinate, {
@@ -308,7 +230,7 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
308
230
  // .then((featureInfo: LayerGetFeatureInfoResponse) => {
309
231
  // const features: Feature[] = featureInfo.features.filter(
310
232
  // (feature: Feature) => {
311
- // // @ts-ignore
233
+ // // @ts-expect-error
312
234
  // return this.featureInfoFilter(
313
235
  // feature,
314
236
  // this.map?.getView().getResolution(),
@@ -319,34 +241,99 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
319
241
  // return { ...featureInfo, features, layer: this };
320
242
  // });
321
243
  }
322
- // /**
323
- // * Set filter that determines which features should be rendered in a style layer.
324
- // * @param {maplibregl.filter} filter Determines which features should be rendered in a style layer.
325
- // */
326
- // setFilter(filter: { [key: string]: any }) {
327
- // if (!this.maplibreLayer?.maplibreMap) {
328
- // return;
329
- // }
330
- // const { maplibreMap } = this.maplibreLayer;
331
- // this.styleLayers.forEach(({ id }) => {
332
- // if (id && filter && maplibreMap.getLayer(id)) {
333
- // // @ts-ignore
334
- // maplibreMap.setFilter(id, filter);
335
- // }
336
- // });
337
- // }
338
244
  /**
339
- * Set if features are hovered or not.
340
- * @param {Array<ol/Feature~Feature>} features
341
- * @param {boolean} state Is the feature hovered
245
+ * Highlight a list of features.
246
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
342
247
  * @private
343
248
  */
344
- setHoverState(features, state) {
249
+ highlight(features = []) {
345
250
  var _a;
346
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !features.length) {
251
+ // eslint-disable-next-line no-console
252
+ console.warn(`Deprecated. Use layer.setFeatureState(features, {highlighted: true}) instead.`);
253
+ // Filter out selected features
254
+ const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
255
+ .map((feat) => feat.getId())
256
+ .includes(feature.getId()))) || [];
257
+ // Remove previous highlight
258
+ this.setHoverState(filtered, false);
259
+ this.highlightedFeatures = features;
260
+ // Add highlight
261
+ this.setHoverState(this.highlightedFeatures, true);
262
+ }
263
+ /**
264
+ * On Maplibre map load callback function. Add style layers and dynaimc filters.
265
+ * @private
266
+ */
267
+ onLoad() {
268
+ var _a;
269
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap)) {
270
+ return;
271
+ }
272
+ this.addSources();
273
+ this.addLayers();
274
+ const { mapLibreMap } = this.maplibreLayer;
275
+ const style = mapLibreMap.getStyle();
276
+ if ((style === null || style === void 0 ? void 0 : style.layers) && this.layersFilter) {
277
+ const styles = style.layers.filter(this.layersFilter);
278
+ this.set('disabled', !styles.length);
279
+ }
280
+ this.applyLayoutVisibility();
281
+ }
282
+ /** @private */
283
+ removeLayers() {
284
+ var _a;
285
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !Array.isArray(this.layers)) {
347
286
  return;
348
287
  }
349
- const { maplibreMap } = this.maplibreLayer;
288
+ const { mapLibreMap } = this.maplibreLayer;
289
+ if (mapLibreMap) {
290
+ this.layers.forEach((styleLayer) => {
291
+ const { id } = styleLayer;
292
+ if (id && mapLibreMap.getLayer(id)) {
293
+ mapLibreMap.removeLayer(id);
294
+ }
295
+ });
296
+ }
297
+ }
298
+ /** @private */
299
+ removeSources() {
300
+ var _a;
301
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !this.sources) {
302
+ return;
303
+ }
304
+ const { mapLibreMap } = this.maplibreLayer;
305
+ if (mapLibreMap) {
306
+ Object.keys(this.sources).forEach((id) => {
307
+ if (mapLibreMap.getSource(id)) {
308
+ mapLibreMap.removeSource(id);
309
+ }
310
+ });
311
+ }
312
+ }
313
+ /**
314
+ * Select a list of features.
315
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
316
+ * @private
317
+ */
318
+ select(features = []) {
319
+ // eslint-disable-next-line no-console
320
+ console.warn(`Deprecated. Use layer.setFeatureState(features, {selected: true}) instead.`);
321
+ this.setHoverState(this.selectedFeatures || [], false);
322
+ this.selectedFeatures = features;
323
+ this.setHoverState(this.selectedFeatures || [], true);
324
+ }
325
+ /**
326
+ * Set the feature state of the features.
327
+ * @param {Array<ol/Feature~Feature>} features
328
+ * @param {{[key:string]:boolean}} state The feature state
329
+ * @public
330
+ */
331
+ setFeatureState(features, state) {
332
+ var _a;
333
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !features.length) {
334
+ return;
335
+ }
336
+ const { mapLibreMap } = this.maplibreLayer;
350
337
  features.forEach((feature) => {
351
338
  const { source, sourceLayer } = feature.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
352
339
  if ((!source && !sourceLayer) || !feature.getId()) {
@@ -356,76 +343,115 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
356
343
  }
357
344
  return;
358
345
  }
359
- maplibreMap.setFeatureState({
346
+ mapLibreMap.setFeatureState({
360
347
  id: feature.getId(),
361
348
  source,
362
349
  sourceLayer,
363
- }, { hover: state });
350
+ }, state);
364
351
  });
365
352
  }
366
353
  /**
367
- * Select a list of features.
368
- * @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
354
+ * Set if features are hovered or not.
355
+ * @param {Array<ol/Feature~Feature>} features
356
+ * @param {boolean} state Is the feature hovered
369
357
  * @private
370
358
  */
371
- select(features = []) {
372
- this.setHoverState(this.selectedFeatures || [], false);
373
- this.selectedFeatures = features;
374
- this.setHoverState(this.selectedFeatures || [], true);
359
+ setHoverState(features, state) {
360
+ // eslint-disable-next-line no-console
361
+ console.warn(`Deprecated. Use layer.setFeatureState(features, {hover: ${state}}) instead.`);
362
+ this.setFeatureState(features, { hover: state });
363
+ }
364
+ get beforeId() {
365
+ return this.get('beforeId');
366
+ }
367
+ set beforeId(newValue) {
368
+ this.set('beforeId', newValue);
369
+ }
370
+ get layers() {
371
+ return this.get('layers');
372
+ }
373
+ set layers(newValue) {
374
+ this.set('layers', newValue);
375
+ }
376
+ get layersFilter() {
377
+ return this.get('layersFilter');
378
+ }
379
+ set layersFilter(newValue) {
380
+ this.set('layersFilter', newValue);
381
+ }
382
+ get mapboxLayer() {
383
+ // eslint-disable-next-line no-console
384
+ console.warn('Deprecated. Use maplibreLayer instead.');
385
+ return this.get('maplibreLayer');
386
+ }
387
+ get maplibreLayer() {
388
+ return this.get('maplibreLayer');
389
+ }
390
+ set maplibreLayer(newValue) {
391
+ this.set('maplibreLayer', newValue);
392
+ }
393
+ get queryRenderedLayersFilter() {
394
+ return this.get('queryRenderedLayersFilter');
395
+ }
396
+ set queryRenderedLayersFilter(newValue) {
397
+ this.set('queryRenderedLayersFilter', newValue);
398
+ }
399
+ get sources() {
400
+ return this.get('sources');
401
+ }
402
+ // /**
403
+ // * Set filter that determines which features should be rendered in a style layer.
404
+ // * @param {maplibregl.filter} filter Determines which features should be rendered in a style layer.
405
+ // */
406
+ // setFilter(filter: { [key: string]: any }) {
407
+ // if (!this.maplibreLayer?.mapLibreMap) {
408
+ // return;
409
+ // }
410
+ // const { mapLibreMap } = this.maplibreLayer;
411
+ // this.styleLayers.forEach(({ id }) => {
412
+ // if (id && filter && mapLibreMap.getLayer(id)) {
413
+ // // @ts-expect-error
414
+ // mapLibreMap.setFilter(id, filter);
415
+ // }
416
+ // });
417
+ // }
418
+ set sources(newValue) {
419
+ this.set('sources', newValue);
375
420
  }
376
421
  /**
377
- * Highlight a list of features.
378
- * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
379
- * @private
422
+ * @deprecated
380
423
  */
381
- highlight(features = []) {
382
- var _a;
383
- // Filter out selected features
384
- const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
385
- .map((feat) => feat.getId())
386
- .includes(feature.getId()))) || [];
387
- // Remove previous highlight
388
- this.setHoverState(filtered, false);
389
- this.highlightedFeatures = features;
390
- // Add highlight
391
- this.setHoverState(this.highlightedFeatures, true);
424
+ get styleLayer() {
425
+ // eslint-disable-next-line no-console
426
+ console.warn('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
427
+ return this.layers[0];
428
+ }
429
+ /**
430
+ * @deprecated
431
+ */
432
+ set styleLayer(newValue) {
433
+ // eslint-disable-next-line no-console
434
+ console.warn('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
435
+ this.layers = [newValue];
392
436
  }
393
437
  /**
394
438
  * Apply visibility to style layers that fits the styleLayersFilter function.
395
- *
396
- * @private
397
439
  */
398
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
399
- applyLayoutVisibility(evt) {
400
- var _a, _b;
401
- if (!((_b = (_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) === null || _b === void 0 ? void 0 : _b.getStyle()) || !this.layersFilter) {
402
- return;
403
- }
404
- const { maplibreMap } = this.maplibreLayer;
405
- const style = maplibreMap.getStyle();
406
- const visibilityValue = this.getVisible() ? 'visible' : 'none';
407
- const layers = style.layers || [];
408
- for (let i = 0; i < layers.length; i += 1) {
409
- const layer = layers[i];
410
- if (this.layersFilter(layer)) {
411
- const { id } = layer;
412
- if (maplibreMap.getLayer(id)) {
413
- maplibreMap.setLayoutProperty(id, 'visibility', visibilityValue);
414
- if (this.getMinZoom() || this.getMaxZoom()) {
415
- maplibreMap.setLayerZoomRange(id, this.getMinZoom() ? this.getMinZoom() - 1 : 0, // Maplibre zoom = ol zoom - 1
416
- this.getMaxZoom() ? this.getMaxZoom() - 1 : 24);
417
- }
418
- }
419
- }
420
- }
440
+ /**
441
+ * @deprecated
442
+ */
443
+ get styleLayers() {
444
+ // eslint-disable-next-line no-console
445
+ console.warn('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
446
+ return this.layers;
421
447
  }
422
448
  /**
423
- * Create a copy of the MapboxStyleLayer.
424
- * @param {Object} newOptions Options to override.
425
- * @return {MapboxStyleLayer} A MapboxStyleLayer.
449
+ * @deprecated
426
450
  */
427
- clone(newOptions) {
428
- return new MaplibreStyleLayer(Object.assign(Object.assign({}, this.options), newOptions));
451
+ set styleLayers(newValue) {
452
+ // eslint-disable-next-line no-console
453
+ console.warn('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
454
+ this.layers = newValue;
429
455
  }
430
456
  }
431
457
  export default MaplibreStyleLayer;