mobility-toolbox-js 3.0.0-beta.1 → 3.0.0-beta.11

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 (92) hide show
  1. package/api/HttpAPI.d.ts +20 -0
  2. package/api/HttpAPI.js +1 -11
  3. package/api/RealtimeAPI.d.ts +365 -0
  4. package/api/RealtimeAPI.js +101 -88
  5. package/api/RoutingAPI.d.ts +37 -0
  6. package/api/RoutingAPI.js +1 -1
  7. package/api/StopsAPI.d.ts +44 -0
  8. package/api/StopsAPI.js +15 -9
  9. package/api/WebSocketAPI.d.ts +153 -0
  10. package/api/index.d.ts +3 -0
  11. package/api/typedefs.d.ts +178 -0
  12. package/common/controls/StopFinderControlCommon.d.ts +53 -0
  13. package/common/index.d.ts +2 -0
  14. package/common/mixins/RealtimeLayerMixin.d.ts +273 -0
  15. package/common/styles/index.d.ts +4 -0
  16. package/common/styles/realtimeDefaultStyle.d.ts +36 -0
  17. package/common/styles/realtimeDelayStyle.d.ts +12 -0
  18. package/common/styles/realtimeHeadingStyle.d.ts +12 -0
  19. package/common/styles/realtimeSimpleStyle.d.ts +4 -0
  20. package/common/typedefs.d.ts +212 -0
  21. package/common/utils/compareDepartures.d.ts +10 -0
  22. package/common/utils/constants.d.ts +5 -0
  23. package/common/utils/createCanvas.d.ts +10 -0
  24. package/common/utils/createDefaultCopyrightElt.d.ts +5 -0
  25. package/common/utils/createDefaultStopFinderElt.d.ts +5 -0
  26. package/common/utils/createRealtimeFilters.d.ts +12 -0
  27. package/common/utils/debounceDeparturesMessages.d.ts +12 -0
  28. package/common/utils/debounceWebsocketMessages.d.ts +11 -0
  29. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  30. package/common/utils/getLayersAsFlatArray.js +5 -1
  31. package/common/utils/getMapGlCopyrights.d.ts +17 -0
  32. package/common/utils/getRealtimeModeSuffix.d.ts +9 -0
  33. package/common/utils/getUrlWithParams.d.ts +8 -0
  34. package/common/utils/getVehiclePosition.d.ts +16 -0
  35. package/common/utils/getVehiclePosition.js +3 -2
  36. package/common/utils/index.d.ts +16 -0
  37. package/common/utils/realtimeConfig.d.ts +64 -0
  38. package/common/utils/removeDuplicate.d.ts +9 -0
  39. package/common/utils/renderTrajectories.d.ts +16 -0
  40. package/common/utils/sortAndFilterDepartures.d.ts +15 -0
  41. package/common/utils/sortByDelay.d.ts +3 -0
  42. package/common/utils/timeUtils.d.ts +23 -0
  43. package/common/utils/toMercatorExtent.d.ts +5 -0
  44. package/iife.d.ts +2 -0
  45. package/index.d.ts +9 -0
  46. package/maplibre/controls/CopyrightControl.d.ts +35 -0
  47. package/maplibre/controls/index.d.ts +1 -0
  48. package/maplibre/index.d.ts +5 -0
  49. package/maplibre/layers/Layer.d.ts +28 -0
  50. package/maplibre/layers/RealtimeLayer.d.ts +160 -0
  51. package/maplibre/layers/RealtimeLayer.js +2 -2
  52. package/maplibre/layers/index.d.ts +2 -0
  53. package/maplibre/utils/getMercatorResolution.d.ts +7 -0
  54. package/maplibre/utils/getSourceCoordinates.d.ts +7 -0
  55. package/maplibre/utils/index.d.ts +2 -0
  56. package/mbt.js +5752 -6987
  57. package/mbt.js.map +4 -4
  58. package/mbt.min.js +55 -55
  59. package/mbt.min.js.map +4 -4
  60. package/ol/controls/CopyrightControl.d.ts +31 -0
  61. package/ol/controls/CopyrightControl.js +18 -8
  62. package/ol/controls/RoutingControl.d.ts +209 -0
  63. package/ol/controls/RoutingControl.js +4 -1
  64. package/ol/controls/StopFinderControl.d.ts +37 -0
  65. package/ol/controls/StopFinderControl.js +4 -1
  66. package/ol/controls/index.d.ts +3 -0
  67. package/ol/index.d.ts +6 -0
  68. package/ol/layers/MaplibreLayer.d.ts +183 -0
  69. package/ol/layers/MaplibreLayer.js +133 -10
  70. package/ol/layers/MaplibreStyleLayer.d.ts +241 -0
  71. package/ol/layers/MaplibreStyleLayer.js +61 -46
  72. package/ol/layers/RealtimeLayer.d.ts +285 -0
  73. package/ol/layers/RealtimeLayer.js +12 -6
  74. package/ol/layers/index.d.ts +3 -0
  75. package/ol/mixins/MobilityLayerMixin.d.ts +98 -0
  76. package/ol/mixins/MobilityLayerMixin.js +1 -4
  77. package/ol/mixins/PropertiesLayerMixin.d.ts +127 -0
  78. package/ol/mixins/PropertiesLayerMixin.js +6 -65
  79. package/ol/renderers/MaplibreLayerRenderer.d.ts +20 -0
  80. package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +20 -0
  81. package/ol/renderers/RealtimeLayerRenderer.d.ts +22 -0
  82. package/ol/renderers/RealtimeLayerRenderer.js +9 -9
  83. package/ol/styles/fullTrajectoryDelayStyle.d.ts +6 -0
  84. package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
  85. package/ol/styles/index.d.ts +3 -0
  86. package/ol/styles/routingStyle.d.ts +4 -0
  87. package/ol/utils/getFeatureInfoAtCoordinate.d.ts +8 -0
  88. package/ol/utils/getFeatureInfoAtCoordinate.js +2 -2
  89. package/ol/utils/index.d.ts +1 -0
  90. package/package.json +19 -21
  91. package/setupTests.d.ts +1 -0
  92. package/ol/layers/MapGlLayer.js +0 -142
@@ -1,8 +1,13 @@
1
+ import Source from 'ol/source/Source';
2
+ import BaseEvent from 'ol/events/Event';
3
+ import Layer from 'ol/layer/Layer';
4
+ import debounce from 'lodash.debounce';
1
5
  import { Map } from 'maplibre-gl';
2
- import MapGlLayer from './MapGlLayer';
6
+ import { getUrlWithParams, getMapGlCopyrights } from '../../common/utils';
7
+ import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
3
8
  import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
4
9
  /**
5
- * This layer is meant to facilitate the use of the geOps Maps api in an OpenLayers map using Maplibre.
10
+ * An OpenLayers layer able to display data from the [geOps Maps API](https://developer.geops.io/apis/maps).
6
11
  *
7
12
  * @example
8
13
  * import { MaplibreLayer } from 'mobility-toolbox-js/ol';
@@ -28,10 +33,40 @@ import MaplibreLayerRenderer from '../renderers/MaplibreLayerRenderer';
28
33
  * @extends {ol/layer/Layer~Layer}
29
34
  * @public
30
35
  */
31
- export default class MaplibreLayer extends MapGlLayer {
32
- /** @private */
33
- get maplibreMap() {
34
- return this.mbMap;
36
+ class MaplibreLayer extends MobilityLayerMixin(Layer) {
37
+ get apiKey() {
38
+ return this.get('apiKey');
39
+ }
40
+ set apiKey(newValue) {
41
+ this.set('apiKey', newValue);
42
+ }
43
+ get apiKeyName() {
44
+ return this.get('apiKeyName');
45
+ }
46
+ set apiKeyName(newValue) {
47
+ this.set('apiKeyName', newValue);
48
+ }
49
+ get mbMap() {
50
+ console.warn('Deprecated. Use layer.maplibreMap.');
51
+ return this.maplibreMap;
52
+ }
53
+ get queryRenderedFeaturesOptions() {
54
+ return this.get('queryRenderedFeaturesOptions');
55
+ }
56
+ set queryRenderedFeaturesOptions(newValue) {
57
+ this.set('queryRenderedFeaturesOptions', newValue);
58
+ }
59
+ get style() {
60
+ return this.get('style');
61
+ }
62
+ set style(newValue) {
63
+ this.set('style', newValue);
64
+ }
65
+ get url() {
66
+ return this.get('url');
67
+ }
68
+ set url(newValue) {
69
+ this.set('url', newValue);
35
70
  }
36
71
  /**
37
72
  * Constructor.
@@ -44,21 +79,108 @@ export default class MaplibreLayer extends MapGlLayer {
44
79
  * @param {string} [options.url="https://maps.geops.io"] The geOps Maps api url.
45
80
  */
46
81
  constructor(options) {
47
- super(Object.assign({}, options));
82
+ super(Object.assign(Object.assign({ source: new Source({
83
+ attributions: () => {
84
+ return ((this.maplibreMap && getMapGlCopyrights(this.maplibreMap)) || []);
85
+ },
86
+ }), apiKeyName: 'key', style: 'travic_v2', url: 'https://maps.geops.io' }, (options || {})), {
87
+ // @ts-expect-error mapOptions must be saved by the mixin in this.options
88
+ mapOptions: Object.assign({ interactive: false, trackResize: false, attributionControl: false }, ((options === null || options === void 0 ? void 0 : options.mapOptions) || {})), queryRenderedFeaturesOptions: Object.assign({}, ((options === null || options === void 0 ? void 0 : options.queryRenderedFeaturesOptions) || {})) }));
48
89
  }
49
90
  /**
50
- * @private
91
+ * Initialize the layer and listen to feature clicks.
92
+ * @param {ol/Map~Map} map
51
93
  */
52
- createRenderer() {
53
- return new MaplibreLayerRenderer(this);
94
+ attachToMap(map) {
95
+ super.attachToMap(map);
96
+ this.loadMbMap();
97
+ const updateMaplibreMapDebounced = debounce(this.updateMaplibreMap.bind(this), 150);
98
+ this.olListenersKeys.push(this.on('propertychange', (evt) => {
99
+ if (/(apiKey|apiKeyName|url|style)/.test(evt.key)) {
100
+ updateMaplibreMapDebounced();
101
+ }
102
+ }));
103
+ }
104
+ /**
105
+ * Terminate what was initialized in init function. Remove layer, events...
106
+ */
107
+ detachFromMap() {
108
+ if (this.maplibreMap) {
109
+ // Some asynchrone repaints are triggered even if the mbMap has been removed,
110
+ // to avoid display of errors we set an empty function.
111
+ this.maplibreMap.triggerRepaint = () => { };
112
+ this.maplibreMap.remove();
113
+ this.maplibreMap = undefined;
114
+ }
115
+ this.loaded = false;
116
+ super.detachFromMap();
54
117
  }
55
118
  /**
119
+ * Create the Maplibre map.
56
120
  * @private
57
121
  */
122
+ loadMbMap() {
123
+ var _a, _b, _c;
124
+ this.loaded = false;
125
+ this.olListenersKeys.push(
126
+ // @ts-ignore
127
+ (_a = this.map) === null || _a === void 0 ? void 0 : _a.on('change:target', this.loadMbMap.bind(this)));
128
+ if (!((_b = this.map) === null || _b === void 0 ? void 0 : _b.getTargetElement())) {
129
+ return;
130
+ }
131
+ if (!this.visible) {
132
+ // On next change of visibility we load the map
133
+ this.olListenersKeys.push(
134
+ // @ts-ignore
135
+ this.once('change:visible', this.loadMbMap.bind(this)));
136
+ return;
137
+ }
138
+ const container = document.createElement('div');
139
+ container.style.position = 'absolute';
140
+ container.style.width = '100%';
141
+ container.style.height = '100%';
142
+ /**
143
+ * A Maplibre map
144
+ * @type {maplibregl.Map}
145
+ */
146
+ this.maplibreMap = this.createMap(Object.assign({ style: this.getStyle(), container }, (((_c = this.options) === null || _c === void 0 ? void 0 : _c.mapOptions) || {})));
147
+ this.maplibreMap.on('sourcedata', () => {
148
+ var _a;
149
+ (_a = this.getSource()) === null || _a === void 0 ? void 0 : _a.refresh(); // Refresh attribution
150
+ });
151
+ this.maplibreMap.once('load', () => {
152
+ this.loaded = true;
153
+ this.dispatchEvent(new BaseEvent('load'));
154
+ });
155
+ }
156
+ getStyle() {
157
+ // If the style is a complete style object, use it directly.
158
+ if (this.style &&
159
+ typeof this.style === 'object' &&
160
+ this.style.name &&
161
+ this.style.version) {
162
+ return this.style;
163
+ }
164
+ // If the url set is already a complete style url, use it directly.
165
+ if (this.url.includes('style.json')) {
166
+ return this.url;
167
+ }
168
+ /// Otherwise build the complete style url.
169
+ return getUrlWithParams(`${this.url}/styles/${this.style}/style.json`, {
170
+ [this.apiKeyName]: this.apiKey,
171
+ }).toString();
172
+ }
58
173
  // eslint-disable-next-line class-methods-use-this
59
174
  createMap(options) {
60
175
  return new Map(options);
61
176
  }
177
+ createRenderer() {
178
+ return new MaplibreLayerRenderer(this);
179
+ }
180
+ updateMaplibreMap() {
181
+ var _a;
182
+ (_a = this.maplibreMap) === null || _a === void 0 ? void 0 : _a.setStyle(this.getStyle(), { diff: false });
183
+ }
62
184
  /**
63
185
  * Create a copy of the MaplibreLayer.
64
186
  * @param {MaplibreLayerOptions} newOptions Options to override
@@ -68,3 +190,4 @@ export default class MaplibreLayer extends MapGlLayer {
68
190
  return new MaplibreLayer(Object.assign(Object.assign({}, (this.options || {})), (newOptions || {})));
69
191
  }
70
192
  }
193
+ export default MaplibreLayer;
@@ -0,0 +1,241 @@
1
+ import { Feature, Map } from 'ol';
2
+ import { Coordinate } from 'ol/coordinate';
3
+ import { ObjectEvent } from 'ol/Object';
4
+ import { Layer } from 'ol/layer';
5
+ import { FeatureState } from 'maplibre-gl';
6
+ import { Source } from 'ol/source';
7
+ import { LayerGetFeatureInfoResponse } from '../../types';
8
+ import { FilterFunction } from '../../common/typedefs';
9
+ import MaplibreLayer, { MaplibreLayerOptions } from './MaplibreLayer';
10
+ import MaplibreStyleLayerRenderer from '../renderers/MaplibreStyleLayerRenderer';
11
+ export type MaplibreStyleLayerOptions = MaplibreLayerOptions & {
12
+ beforeId?: string;
13
+ maplibreLayer?: MaplibreLayer;
14
+ layers?: maplibregl.AddLayerObject[];
15
+ layersFilter?: FilterFunction;
16
+ queryRenderedLayersFilter?: FilterFunction;
17
+ };
18
+ declare const MaplibreStyleLayer_base: {
19
+ new (...args: any[]): {
20
+ options?: import("../mixins/PropertiesLayerMixin").PropertiesLayerMixinOptions | undefined;
21
+ olListenersKeys: import("ol/events").EventsKey[];
22
+ children: Layer<Source, import("ol/renderer/Layer").default<any>>[];
23
+ get copyrights(): string;
24
+ set copyrights(newCopyrights: string | string[]);
25
+ disabled: boolean;
26
+ readonly group: string;
27
+ readonly hitTolerance: boolean;
28
+ readonly key: string;
29
+ readonly map: Map;
30
+ readonly name: string;
31
+ olLayer: Layer<Source, import("ol/renderer/Layer").default<any>>;
32
+ parent: Layer<Source, import("ol/renderer/Layer").default<any>>;
33
+ visible: boolean;
34
+ setMapInternal: ((map: Map) => void) & ((map: Map | null) => void);
35
+ onChildrenChange(oldValue: Layer<Source, import("ol/renderer/Layer").default<any>>[]): void;
36
+ attachToMap(map: Map): void;
37
+ detachFromMap(): void;
38
+ flat(): any[];
39
+ addEventListener: (type: string, listener: import("ol/events").Listener) => void;
40
+ removeEventListener: (type: string, listener: import("ol/events").Listener) => void;
41
+ on: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
42
+ render: (frameState: import("ol/Map").FrameState | null, target: HTMLElement) => HTMLElement | null;
43
+ once: import("ol/layer/Layer").LayerOnSignature<import("ol/events").EventsKey>;
44
+ un: import("ol/layer/Layer").LayerOnSignature<void>;
45
+ getSource: () => Source | null;
46
+ getRenderSource: () => Source | null;
47
+ getFeatures: (pixel: import("ol/pixel").Pixel) => Promise<import("ol/Feature").FeatureLike[]>;
48
+ getData: (pixel: import("ol/pixel").Pixel) => Float32Array | Uint8ClampedArray | Uint8Array | DataView | null;
49
+ isVisible: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => boolean;
50
+ getAttributions: (view?: import("ol").View | import("ol/View").ViewStateLayerStateExtent | undefined) => string[];
51
+ unrender: () => void;
52
+ getDeclutter: () => string;
53
+ renderDeclutter: (frameState: import("ol/Map").FrameState, layerState: import("ol/layer/Layer").State) => void;
54
+ renderDeferred: (frameState: import("ol/Map").FrameState) => void;
55
+ getMapInternal: () => Map | null;
56
+ setMap: (map: Map | null) => void;
57
+ setSource: (source: Source | null) => void;
58
+ getRenderer: () => import("ol/renderer/Layer").default<any> | null;
59
+ hasRenderer: () => boolean;
60
+ getBackground: () => false | import("ol/layer/Base").BackgroundColor;
61
+ getClassName: () => string;
62
+ getLayerState: (managed?: boolean | undefined) => import("ol/layer/Layer").State;
63
+ getLayersArray: (array?: Layer<Source, import("ol/renderer/Layer").default<any>>[] | undefined) => Layer<Source, import("ol/renderer/Layer").default<any>>[];
64
+ getLayerStatesArray: (states?: import("ol/layer/Layer").State[] | undefined) => import("ol/layer/Layer").State[];
65
+ getExtent: () => import("ol/extent").Extent | undefined;
66
+ getMaxResolution: () => number;
67
+ getMinResolution: () => number;
68
+ getMinZoom: () => number;
69
+ getMaxZoom: () => number;
70
+ getOpacity: () => number;
71
+ getSourceState: () => import("ol/source/Source").State;
72
+ getVisible: () => boolean;
73
+ getZIndex: () => number | undefined;
74
+ setBackground: (background?: import("ol/layer/Base").BackgroundColor | undefined) => void;
75
+ setExtent: (extent: import("ol/extent").Extent | undefined) => void;
76
+ setMaxResolution: (maxResolution: number) => void;
77
+ setMinResolution: (minResolution: number) => void;
78
+ setMaxZoom: (maxZoom: number) => void;
79
+ setMinZoom: (minZoom: number) => void;
80
+ setOpacity: (opacity: number) => void;
81
+ setVisible: (visible: boolean) => void;
82
+ setZIndex: (zindex: number) => void;
83
+ get: (key: string) => any;
84
+ getKeys: () => string[];
85
+ getProperties: () => {
86
+ [x: string]: any;
87
+ };
88
+ getPropertiesInternal: () => {
89
+ [x: string]: any;
90
+ } | null;
91
+ hasProperties: () => boolean;
92
+ notify: (key: string, oldValue: any) => void;
93
+ addChangeListener: (key: string, listener: import("ol/events").Listener) => void;
94
+ removeChangeListener: (key: string, listener: import("ol/events").Listener) => void;
95
+ set: (key: string, value: any, silent?: boolean | undefined) => void;
96
+ setProperties: (values: {
97
+ [x: string]: any;
98
+ }, silent?: boolean | undefined) => void;
99
+ unset: (key: string, silent?: boolean | undefined) => void;
100
+ changed: () => void;
101
+ getRevision: () => number;
102
+ dispatchEvent: (event: string | import("ol/events/Event").default) => boolean | undefined;
103
+ getListeners: (type: string) => import("ol/events").Listener[] | undefined;
104
+ hasListener: (type?: string | undefined) => boolean;
105
+ dispose: () => void;
106
+ };
107
+ } & typeof Layer;
108
+ /**
109
+ * Layer for visualizing a specific set of layer from a MapboxLayer.
110
+ *
111
+ * @example
112
+ * import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
113
+ *
114
+ * const maplibreLayer = new MapboxLayer({
115
+ * url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
116
+ * });
117
+ *
118
+ * const layer = new MapboxStyleLayer({
119
+ * maplibreLayer: maplibreLayer,
120
+ * styleLayersFilter: () => {},
121
+ * });
122
+ *
123
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
124
+ * @extends {ol/layer/Layer~Layer}
125
+ */
126
+ declare class MaplibreStyleLayer extends MaplibreStyleLayer_base {
127
+ highlightedFeatures: Feature[];
128
+ selectedFeatures: Feature[];
129
+ get beforeId(): string;
130
+ set beforeId(newValue: string[]);
131
+ get layers(): maplibregl.AddLayerObject[];
132
+ set layers(newValue: maplibregl.AddLayerObject[]);
133
+ get layersFilter(): (layer: maplibregl.LayerSpecification) => boolean;
134
+ set layersFilter(newValue: (layer: maplibregl.LayerSpecification) => boolean);
135
+ get mapboxLayer(): MaplibreLayer | undefined;
136
+ get maplibreLayer(): MaplibreLayer;
137
+ set maplibreLayer(newValue: MaplibreLayer);
138
+ get queryRenderedLayersFilter(): (layer: maplibregl.LayerSpecification) => boolean;
139
+ set queryRenderedLayersFilter(newValue: (layer: maplibregl.LayerSpecification) => boolean);
140
+ get sources(): {
141
+ [key: string]: maplibregl.SourceSpecification;
142
+ };
143
+ set sources(newValue: {
144
+ [key: string]: maplibregl.SourceSpecification;
145
+ });
146
+ /**
147
+ * @deprecated
148
+ */
149
+ get styleLayer(): maplibregl.AddLayerObject;
150
+ /**
151
+ * @deprecated
152
+ */
153
+ set styleLayer(newValue: maplibregl.AddLayerObject);
154
+ /**
155
+ * @deprecated
156
+ */
157
+ get styleLayers(): maplibregl.AddLayerObject[];
158
+ /**
159
+ * @deprecated
160
+ */
161
+ set styleLayers(newValue: maplibregl.AddLayerObject[]);
162
+ /**
163
+ * Constructor.
164
+ *
165
+ * @param {Object} options
166
+ * @param {MapboxLayer} [options.maplibreLayer] The MaplibreLayer to use.
167
+ * @param {maplibregl.SourceSpecification[]} [options.sources] The source to add to the style on load.
168
+ * @param {maplibregl.AddLayerObject[]} [options.layers] The layers to add to the style on load.
169
+ * @param {FilterFunction} [options.layersFilter] Filter function to decide which style layer to apply visiblity on. If not provided, the 'layers' property is used.
170
+ * @param {FilterFunction} [options.queryRenderedLayersFilter] Filter function to decide which style layer are available for query.
171
+ */
172
+ constructor(options: MaplibreStyleLayerOptions);
173
+ createRenderer(): MaplibreStyleLayerRenderer;
174
+ /**
175
+ * Initialize the layer.
176
+ * @param {ol/Map~Map} map the Maplibre map.
177
+ * @override
178
+ */
179
+ attachToMap(map: Map): void;
180
+ /**
181
+ * Terminate the layer.
182
+ * @override
183
+ */
184
+ detachFromMap(): void;
185
+ /** @private */
186
+ addSources(): void;
187
+ /** @private */
188
+ removeSources(): void;
189
+ /** @private */
190
+ addLayers(): void;
191
+ /** @private */
192
+ removeLayers(): void;
193
+ /**
194
+ * On Maplibre map load callback function. Add style layers and dynaimc filters.
195
+ * @private
196
+ */
197
+ onLoad(): void;
198
+ /**
199
+ * Set the feature state of the features.
200
+ * @param {Array<ol/Feature~Feature>} features
201
+ * @param {{[key:string]:boolean}} state The feature state
202
+ * @public
203
+ */
204
+ setFeatureState(features: Feature[], state: FeatureState): void;
205
+ /**
206
+ * Request feature information for a given coordinate.
207
+ * @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
208
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
209
+ */
210
+ getFeatureInfoAtCoordinate(coordinate: Coordinate): Promise<LayerGetFeatureInfoResponse>;
211
+ /**
212
+ * Set if features are hovered or not.
213
+ * @param {Array<ol/Feature~Feature>} features
214
+ * @param {boolean} state Is the feature hovered
215
+ * @private
216
+ */
217
+ setHoverState(features: Feature[], state: boolean): void;
218
+ /**
219
+ * Select a list of features.
220
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
221
+ * @private
222
+ */
223
+ select(features?: Feature[]): void;
224
+ /**
225
+ * Highlight a list of features.
226
+ * @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
227
+ * @private
228
+ */
229
+ highlight(features?: Feature[]): void;
230
+ /**
231
+ * Apply visibility to style layers that fits the styleLayersFilter function.
232
+ */
233
+ applyLayoutVisibility(evt?: ObjectEvent): void;
234
+ /**
235
+ * Create a copy of the MapboxStyleLayer.
236
+ * @param {Object} newOptions Options to override.
237
+ * @return {MapboxStyleLayer} A MapboxStyleLayer.
238
+ */
239
+ clone(newOptions: MaplibreStyleLayerOptions): MaplibreStyleLayer;
240
+ }
241
+ export default MaplibreStyleLayer;
@@ -135,35 +135,37 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
135
135
  if (!this.map || !this.maplibreLayer) {
136
136
  return;
137
137
  }
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
138
+ if (!this.map.getTargetElement()) {
139
+ // If ther e is no target element the maplibreMap is not yet created, we
142
140
  // relaunch the initialisation when it's the case.
143
141
  this.olListenersKeys.push(this.map.on('change:target', () => {
144
142
  this.attachToMap(map);
145
143
  }));
146
144
  return;
147
145
  }
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);
146
+ // Apply the initial visibility if possible otherwise we wait for the load event of the layer
147
+ const { maplibreMap } = this.maplibreLayer;
148
+ if (maplibreMap) {
149
+ // maplibreMap.loaded() and maplibreMap.isStyleLoaded() are reliable only on the first call of init.
150
+ // On the next call (when a topic change for example), these functions returns false because
151
+ // the style is being modified.
152
+ // That's why we rely on a property instead for the next calls.
153
+ if (maplibreMap.loaded()) {
154
+ this.onLoad();
155
+ }
156
+ else {
157
+ maplibreMap.once('load', this.onLoad);
158
+ }
157
159
  }
158
160
  // Apply the visibiltity when layer's visibility change.
159
- this.olListenersKeys.push(this.on('change:visible', (evt) => {
161
+ this.olListenersKeys.push(
162
+ // @ts-expect-error 'load' is a custom event
163
+ this.maplibreLayer.on('load', this.onLoad.bind(this)), this.on('change:visible', (evt) => {
160
164
  // Once the map is loaded we can apply visiblity without waiting
161
165
  // the style. Maplibre take care of the application of style changes.
162
166
  this.applyLayoutVisibility(evt);
163
- }),
164
- // @ts-expect-error 'load' is a custom event form mobility-toolbox-js
165
- this.maplibreLayer.on('load', this.onLoad), this.on('propertychange', (evt) => {
166
- if (/(sources|layers|layersFilter|maplibreLayer|beforeId|)/.test(evt.key)) {
167
+ }), this.on('propertychange', (evt) => {
168
+ if (/(sources|layers|layersFilter|maplibreLayer|beforeId)/.test(evt.key)) {
167
169
  this.detachFromMap();
168
170
  this.attachToMap(map);
169
171
  }
@@ -185,13 +187,12 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
185
187
  /** @private */
186
188
  addSources() {
187
189
  var _a;
188
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.sources)) {
190
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !this.sources) {
189
191
  return;
190
192
  }
191
193
  const { maplibreMap } = this.maplibreLayer;
192
194
  if (maplibreMap) {
193
- this.sources.forEach((source) => {
194
- const { id } = source;
195
+ Object.entries(this.sources).forEach(([id, source]) => {
195
196
  if (!maplibreMap.getSource(id)) {
196
197
  maplibreMap.addSource(id, source);
197
198
  }
@@ -201,13 +202,12 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
201
202
  /** @private */
202
203
  removeSources() {
203
204
  var _a;
204
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !Array.isArray(this.layers)) {
205
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !this.sources) {
205
206
  return;
206
207
  }
207
208
  const { maplibreMap } = this.maplibreLayer;
208
209
  if (maplibreMap) {
209
- this.sources.forEach((source) => {
210
- const { id } = source;
210
+ Object.keys(this.sources).forEach((id) => {
211
211
  if (maplibreMap.getSource(id)) {
212
212
  maplibreMap.removeSource(id);
213
213
  }
@@ -268,6 +268,34 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
268
268
  this.disabled = !styles.length;
269
269
  }
270
270
  }
271
+ /**
272
+ * Set the feature state of the features.
273
+ * @param {Array<ol/Feature~Feature>} features
274
+ * @param {{[key:string]:boolean}} state The feature state
275
+ * @public
276
+ */
277
+ setFeatureState(features, state) {
278
+ var _a;
279
+ if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !features.length) {
280
+ return;
281
+ }
282
+ const { maplibreMap } = this.maplibreLayer;
283
+ features.forEach((feature) => {
284
+ const { source, sourceLayer } = feature.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
285
+ if ((!source && !sourceLayer) || !feature.getId()) {
286
+ if (!feature.getId()) {
287
+ // eslint-disable-next-line no-console
288
+ console.warn("No feature's id found. To use the feature state functionnality, tiles must be generated with --generate-ids. See https://github.com/Maplibre/tippecanoe#adding-calculated-attributes.", feature.getId(), feature.getProperties());
289
+ }
290
+ return;
291
+ }
292
+ maplibreMap.setFeatureState({
293
+ id: feature.getId(),
294
+ source,
295
+ sourceLayer,
296
+ }, state);
297
+ });
298
+ }
271
299
  /**
272
300
  * Request feature information for a given coordinate.
273
301
  * @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
@@ -275,6 +303,8 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
275
303
  */
276
304
  getFeatureInfoAtCoordinate(coordinate) {
277
305
  var _a;
306
+ // eslint-disable-next-line no-console
307
+ console.warn(`Deprecated. getFeatureInfoAtCoordinate([layer], coordinate) from ol package instead.`);
278
308
  if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap)) {
279
309
  return Promise.resolve({ coordinate, features: [], layer: this });
280
310
  }
@@ -342,26 +372,9 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
342
372
  * @private
343
373
  */
344
374
  setHoverState(features, state) {
345
- var _a;
346
- if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.maplibreMap) || !features.length) {
347
- return;
348
- }
349
- const { maplibreMap } = this.maplibreLayer;
350
- features.forEach((feature) => {
351
- const { source, sourceLayer } = feature.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
352
- if ((!source && !sourceLayer) || !feature.getId()) {
353
- if (!feature.getId()) {
354
- // eslint-disable-next-line no-console
355
- console.warn("No feature's id found. To use the feature state functionnality, tiles must be generated with --generate-ids. See https://github.com/Maplibre/tippecanoe#adding-calculated-attributes.", feature.getId(), feature.getProperties());
356
- }
357
- return;
358
- }
359
- maplibreMap.setFeatureState({
360
- id: feature.getId(),
361
- source,
362
- sourceLayer,
363
- }, { hover: state });
364
- });
375
+ // eslint-disable-next-line no-console
376
+ console.warn(`Deprecated. Use layer.setFeatureState(features, {hover: ${state}}) instead.`);
377
+ this.setFeatureState(features, { hover: state });
365
378
  }
366
379
  /**
367
380
  * Select a list of features.
@@ -369,6 +382,8 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
369
382
  * @private
370
383
  */
371
384
  select(features = []) {
385
+ // eslint-disable-next-line no-console
386
+ console.warn(`Deprecated. Use layer.setFeatureState(features, {selected: true}) instead.`);
372
387
  this.setHoverState(this.selectedFeatures || [], false);
373
388
  this.selectedFeatures = features;
374
389
  this.setHoverState(this.selectedFeatures || [], true);
@@ -380,6 +395,8 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
380
395
  */
381
396
  highlight(features = []) {
382
397
  var _a;
398
+ // eslint-disable-next-line no-console
399
+ console.warn(`Deprecated. Use layer.setFeatureState(features, {highlighted: true}) instead.`);
383
400
  // Filter out selected features
384
401
  const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
385
402
  .map((feat) => feat.getId())
@@ -392,8 +409,6 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
392
409
  }
393
410
  /**
394
411
  * Apply visibility to style layers that fits the styleLayersFilter function.
395
- *
396
- * @private
397
412
  */
398
413
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
399
414
  applyLayoutVisibility(evt) {