mobility-toolbox-js 3.0.1-beta.0 → 3.0.1-beta.2
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.
- package/README.md +11 -3
- package/api/HttpAPI.js +1 -3
- package/api/RealtimeAPI.d.ts +47 -47
- package/api/RealtimeAPI.js +74 -74
- package/api/WebSocketAPI.js +0 -1
- package/common/controls/StopFinderControlCommon.d.ts +1 -1
- package/common/controls/StopFinderControlCommon.js +1 -1
- package/common/styles/realtimeDefaultStyle.js +0 -5
- package/common/styles/realtimeHeadingStyle.js +0 -5
- package/common/styles/realtimeSimpleStyle.d.ts +0 -1
- package/common/styles/realtimeSimpleStyle.js +0 -1
- package/common/typedefs.d.ts +0 -117
- package/common/typedefs.js +0 -31
- package/common/utils/RealtimeEngine.d.ts +214 -0
- package/common/utils/RealtimeEngine.js +554 -0
- package/common/utils/getLayersAsFlatArray.d.ts +0 -1
- package/common/utils/getLayersAsFlatArray.js +0 -1
- package/common/utils/getVehiclePosition.js +1 -4
- package/common/utils/realtimeConfig.d.ts +1 -1
- package/common/utils/realtimeConfig.js +0 -1
- package/common/utils/renderTrajectories.d.ts +1 -0
- package/common/utils/renderTrajectories.js +1 -0
- package/common/utils/sortAndFilterDepartures.d.ts +1 -0
- package/common/utils/sortAndFilterDepartures.js +1 -0
- package/maplibre/controls/CopyrightControl.d.ts +9 -6
- package/maplibre/controls/CopyrightControl.js +11 -8
- package/maplibre/layers/Layer.d.ts +7 -6
- package/maplibre/layers/Layer.js +1 -2
- package/maplibre/layers/RealtimeLayer.d.ts +54 -111
- package/maplibre/layers/RealtimeLayer.js +126 -114
- package/maplibre/utils/getSourceCoordinates.d.ts +1 -0
- package/maplibre/utils/getSourceCoordinates.js +5 -4
- package/mbt.js +6960 -14605
- package/mbt.js.map +4 -4
- package/mbt.min.js +68 -71
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +13 -5
- package/ol/controls/CopyrightControl.js +13 -5
- package/ol/controls/RoutingControl.d.ts +29 -18
- package/ol/controls/RoutingControl.js +44 -56
- package/ol/controls/StopFinderControl.d.ts +21 -2
- package/ol/controls/StopFinderControl.js +22 -3
- package/ol/index.d.ts +0 -1
- package/ol/index.js +0 -1
- package/ol/layers/Layer.d.ts +17 -92
- package/ol/layers/Layer.js +17 -3
- package/ol/layers/MaplibreLayer.d.ts +47 -114
- package/ol/layers/MaplibreLayer.js +102 -46
- package/ol/layers/MaplibreStyleLayer.d.ts +67 -147
- package/ol/layers/MaplibreStyleLayer.js +170 -123
- package/ol/layers/RealtimeLayer.d.ts +85 -218
- package/ol/layers/RealtimeLayer.js +170 -181
- package/ol/layers/VectorLayer.d.ts +1 -2
- package/ol/layers/VectorLayer.js +7 -6
- package/ol/renderers/MaplibreLayerRenderer.d.ts +9 -0
- package/ol/renderers/MaplibreLayerRenderer.js +35 -137
- package/ol/renderers/MaplibreStyleLayerRenderer.js +2 -2
- package/ol/renderers/RealtimeLayerRenderer.d.ts +1 -1
- package/ol/renderers/RealtimeLayerRenderer.js +6 -31
- package/ol/styles/fullTrajectoryDelayStyle.js +5 -7
- package/ol/styles/fullTrajectoryStyle.d.ts +1 -2
- package/ol/styles/fullTrajectoryStyle.js +5 -7
- package/ol/styles/routingStyle.d.ts +0 -1
- package/ol/styles/routingStyle.js +13 -10
- package/ol/utils/defineDeprecatedProperties.d.ts +10 -0
- package/ol/utils/defineDeprecatedProperties.js +180 -0
- package/package.json +40 -39
- package/setupTests.js +14 -0
- package/types/common.d.ts +4 -27
- package/types/realtime.d.ts +7 -2
- package/common/mixins/RealtimeLayerMixin.d.ts +0 -267
- package/common/mixins/RealtimeLayerMixin.js +0 -751
- package/ol/mixins/MobilityLayerMixin.d.ts +0 -96
- package/ol/mixins/MobilityLayerMixin.js +0 -6
- package/ol/mixins/PropertiesLayerMixin.d.ts +0 -136
- package/ol/mixins/PropertiesLayerMixin.js +0 -178
- package/ol/mixins/index.d.ts +0 -1
- package/ol/mixins/index.js +0 -2
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import debounce from 'lodash.debounce';
|
|
2
2
|
import { Layer } from 'ol/layer';
|
|
3
|
+
import { unByKey } from 'ol/Observable';
|
|
3
4
|
import { Source } from 'ol/source';
|
|
4
5
|
import { VECTOR_TILE_FEATURE_PROPERTY } from '../../common';
|
|
5
|
-
import MobilityLayerMixin from '../mixins/MobilityLayerMixin';
|
|
6
6
|
import MaplibreStyleLayerRenderer from '../renderers/MaplibreStyleLayerRenderer';
|
|
7
|
+
import defineDeprecatedProperties from '../utils/defineDeprecatedProperties';
|
|
7
8
|
let deprecated = () => { };
|
|
8
9
|
if (typeof window !== 'undefined' &&
|
|
9
10
|
new URLSearchParams(window.location.search).get('deprecated')) {
|
|
@@ -13,33 +14,113 @@ if (typeof window !== 'undefined' &&
|
|
|
13
14
|
}, 1000);
|
|
14
15
|
}
|
|
15
16
|
/**
|
|
16
|
-
* Layer
|
|
17
|
+
* Layer that helps show/hide a specific subset of style layers of a [MaplibreLayer](./MaplibreLayer.js~MaplibreLayer.html).
|
|
17
18
|
*
|
|
18
19
|
* @example
|
|
19
|
-
* import {
|
|
20
|
+
* import { MaplibreLayer, MaplibreStyleLayer } from 'mobility-toolbox-js/ol';
|
|
20
21
|
*
|
|
21
|
-
* const maplibreLayer = new
|
|
22
|
-
*
|
|
22
|
+
* const maplibreLayer = new MaplibreLayer({
|
|
23
|
+
* apiKey: 'yourApiKey',
|
|
23
24
|
* });
|
|
24
25
|
*
|
|
25
|
-
* const layer = new
|
|
26
|
+
* const layer = new MaplibreStyleLayer({
|
|
26
27
|
* maplibreLayer: maplibreLayer,
|
|
27
|
-
*
|
|
28
|
+
* layersFilter: (layer) => {
|
|
29
|
+
* // show/hide only style layers related to stations
|
|
30
|
+
* return /station/.test(layer.id);
|
|
31
|
+
* },
|
|
28
32
|
* });
|
|
29
33
|
*
|
|
30
|
-
* @
|
|
34
|
+
* @see <a href="/example/ol-maplibre-style-layer">OpenLayers MaplibreStyle layer example</a>
|
|
31
35
|
* @extends {ol/layer/Layer~Layer}
|
|
36
|
+
* @public
|
|
32
37
|
*/
|
|
33
|
-
class MaplibreStyleLayer extends
|
|
38
|
+
class MaplibreStyleLayer extends Layer {
|
|
39
|
+
get beforeId() {
|
|
40
|
+
return this.get('beforeId');
|
|
41
|
+
}
|
|
42
|
+
set beforeId(newValue) {
|
|
43
|
+
this.set('beforeId', newValue);
|
|
44
|
+
}
|
|
45
|
+
get layers() {
|
|
46
|
+
return this.get('layers');
|
|
47
|
+
}
|
|
48
|
+
set layers(newValue) {
|
|
49
|
+
this.set('layers', newValue);
|
|
50
|
+
}
|
|
51
|
+
get layersFilter() {
|
|
52
|
+
return this.get('layersFilter');
|
|
53
|
+
}
|
|
54
|
+
set layersFilter(newValue) {
|
|
55
|
+
this.set('layersFilter', newValue);
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* @deprecated Use MaplibreStyleLayer.maplibreLayer instead.
|
|
59
|
+
*/
|
|
60
|
+
get mapboxLayer() {
|
|
61
|
+
deprecated('Deprecated. Use maplibreLayer instead.');
|
|
62
|
+
return this.get('maplibreLayer');
|
|
63
|
+
}
|
|
64
|
+
get maplibreLayer() {
|
|
65
|
+
return this.get('maplibreLayer');
|
|
66
|
+
}
|
|
67
|
+
set maplibreLayer(newValue) {
|
|
68
|
+
this.set('maplibreLayer', newValue);
|
|
69
|
+
}
|
|
70
|
+
get queryRenderedLayersFilter() {
|
|
71
|
+
return this.get('queryRenderedLayersFilter');
|
|
72
|
+
}
|
|
73
|
+
set queryRenderedLayersFilter(newValue) {
|
|
74
|
+
this.set('queryRenderedLayersFilter', newValue);
|
|
75
|
+
}
|
|
76
|
+
get sources() {
|
|
77
|
+
return this.get('sources');
|
|
78
|
+
}
|
|
79
|
+
set sources(newValue) {
|
|
80
|
+
this.set('sources', newValue);
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* @deprecated Use MaplibreStyleLayer.layer instead.
|
|
84
|
+
*/
|
|
85
|
+
get styleLayer() {
|
|
86
|
+
deprecated('Deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
87
|
+
return this.layers[0];
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* @deprecated
|
|
91
|
+
*/
|
|
92
|
+
set styleLayer(newValue) {
|
|
93
|
+
deprecated('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
94
|
+
this.layers = [newValue];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
98
|
+
*/
|
|
99
|
+
/**
|
|
100
|
+
* @deprecated
|
|
101
|
+
*/
|
|
102
|
+
get styleLayers() {
|
|
103
|
+
deprecated('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
|
|
104
|
+
return this.layers;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* @deprecated
|
|
108
|
+
*/
|
|
109
|
+
set styleLayers(newValue) {
|
|
110
|
+
deprecated('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
|
|
111
|
+
this.layers = newValue;
|
|
112
|
+
}
|
|
34
113
|
/**
|
|
35
114
|
* Constructor.
|
|
36
115
|
*
|
|
37
116
|
* @param {Object} options
|
|
38
|
-
* @param {
|
|
39
|
-
* @param {maplibregl.SourceSpecification[]} [options.sources] The source to add to the style on load.
|
|
117
|
+
* @param {string} [options.beforeId] The style layer id to use when the options.layers property is defined, unsused otherwise.
|
|
40
118
|
* @param {maplibregl.AddLayerObject[]} [options.layers] The layers to add to the style on load.
|
|
41
119
|
* @param {FilterFunction} [options.layersFilter] Filter function to decide which style layer to apply visiblity on. If not provided, the 'layers' property is used.
|
|
120
|
+
* @param {MaplibreLayer} [options.maplibreLayer] The MaplibreLayer to use.
|
|
42
121
|
* @param {FilterFunction} [options.queryRenderedLayersFilter] Filter function to decide which style layer are available for query.
|
|
122
|
+
* @param {{[id: string]:maplibregl.SourceSpecification}} [options.sources] The sources to add to the style on load.
|
|
123
|
+
* @public
|
|
43
124
|
*/
|
|
44
125
|
constructor(options = {
|
|
45
126
|
mapLibreOptions: { style: { layers: [], sources: {}, version: 8 } },
|
|
@@ -52,12 +133,29 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
52
133
|
// eslint-disable-next-line no-param-reassign
|
|
53
134
|
delete options.mapboxLayer;
|
|
54
135
|
}
|
|
136
|
+
if (options.styleLayers) {
|
|
137
|
+
deprecated('options.styleLayers is deprecated. Use options.layers instead.');
|
|
138
|
+
// eslint-disable-next-line no-param-reassign
|
|
139
|
+
options.layers = options.styleLayers;
|
|
140
|
+
// eslint-disable-next-line no-param-reassign
|
|
141
|
+
delete options.styleLayers;
|
|
142
|
+
}
|
|
143
|
+
if (options.styleLayersFilter) {
|
|
144
|
+
deprecated('options.styleLayersFilter is deprecated. Use options.layersFilter instead.');
|
|
145
|
+
// eslint-disable-next-line no-param-reassign
|
|
146
|
+
options.layersFilter = options.styleLayersFilter;
|
|
147
|
+
// eslint-disable-next-line no-param-reassign
|
|
148
|
+
delete options.styleLayersFilter;
|
|
149
|
+
}
|
|
55
150
|
super(Object.assign({ source: new Source({}) }, options));
|
|
56
151
|
this.highlightedFeatures = [];
|
|
152
|
+
this.olEventsKeys = [];
|
|
57
153
|
this.selectedFeatures = [];
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
154
|
+
// For backward compatibility with v2
|
|
155
|
+
defineDeprecatedProperties(this, options);
|
|
156
|
+
// For cloning
|
|
157
|
+
this.set('options', options);
|
|
158
|
+
this.beforeId = options.beforeId;
|
|
61
159
|
this.onLoad = this.onLoad.bind(this);
|
|
62
160
|
if (!this.layersFilter && this.layers) {
|
|
63
161
|
this.layersFilter = (layer) => {
|
|
@@ -65,7 +163,6 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
65
163
|
};
|
|
66
164
|
}
|
|
67
165
|
}
|
|
68
|
-
/** @private */
|
|
69
166
|
addLayers() {
|
|
70
167
|
var _a;
|
|
71
168
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !Array.isArray(this.layers)) {
|
|
@@ -85,7 +182,6 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
85
182
|
this.applyLayoutVisibility();
|
|
86
183
|
}
|
|
87
184
|
}
|
|
88
|
-
/** @private */
|
|
89
185
|
addSources() {
|
|
90
186
|
var _a;
|
|
91
187
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !this.sources) {
|
|
@@ -130,17 +226,17 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
130
226
|
* @override
|
|
131
227
|
*/
|
|
132
228
|
attachToMap(map) {
|
|
133
|
-
if (this.maplibreLayer && !this.maplibreLayer.
|
|
229
|
+
if (this.maplibreLayer && !this.maplibreLayer.getMapInternal()) {
|
|
134
230
|
map.addLayer(this.maplibreLayer);
|
|
135
231
|
}
|
|
136
|
-
|
|
137
|
-
if (!
|
|
232
|
+
const mapInternal = this.getMapInternal();
|
|
233
|
+
if (!mapInternal || !this.maplibreLayer) {
|
|
138
234
|
return;
|
|
139
235
|
}
|
|
140
|
-
if (!
|
|
236
|
+
if (!mapInternal.getTargetElement()) {
|
|
141
237
|
// If ther e is no target element the mapLibreMap is not yet created, we
|
|
142
238
|
// relaunch the initialisation when it's the case.
|
|
143
|
-
this.olEventsKeys.push(
|
|
239
|
+
this.olEventsKeys.push(mapInternal.on('change:target', () => {
|
|
144
240
|
this.attachToMap(map);
|
|
145
241
|
}));
|
|
146
242
|
return;
|
|
@@ -171,15 +267,27 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
171
267
|
this.detachFromMap();
|
|
172
268
|
this.attachToMap(map);
|
|
173
269
|
}
|
|
270
|
+
}),
|
|
271
|
+
// When the style changes we wait that it is loaded to relaunch the onLoad
|
|
272
|
+
this.maplibreLayer.on('propertychange', (evt) => {
|
|
273
|
+
if (evt.key === 'style') {
|
|
274
|
+
evt.target.maplibreMap.once('styledata', () => {
|
|
275
|
+
evt.target.maplibreMap.once('idle', () => {
|
|
276
|
+
this.onLoad();
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
}
|
|
174
280
|
}));
|
|
175
281
|
}
|
|
176
282
|
/**
|
|
177
|
-
* Create a copy of the
|
|
178
|
-
*
|
|
179
|
-
* @
|
|
283
|
+
* Create a copy of the MaplibreStyleLayer.
|
|
284
|
+
*
|
|
285
|
+
* @param {Object} newOptions Options to override. See constructor.
|
|
286
|
+
* @return {MapboxStyleLayer} A MaplibreStyleLayer.
|
|
287
|
+
* @public
|
|
180
288
|
*/
|
|
181
289
|
clone(newOptions) {
|
|
182
|
-
return new MaplibreStyleLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
290
|
+
return new MaplibreStyleLayer(Object.assign(Object.assign({}, this.get('options')), newOptions));
|
|
183
291
|
}
|
|
184
292
|
createRenderer() {
|
|
185
293
|
return new MaplibreStyleLayerRenderer(this);
|
|
@@ -190,17 +298,18 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
190
298
|
*/
|
|
191
299
|
detachFromMap() {
|
|
192
300
|
var _a;
|
|
301
|
+
unByKey(this.olEventsKeys);
|
|
193
302
|
if ((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) {
|
|
194
303
|
this.maplibreLayer.mapLibreMap.off('load', this.onLoad);
|
|
195
304
|
this.removeLayers();
|
|
196
305
|
this.removeSources();
|
|
197
306
|
}
|
|
198
|
-
super.detachFromMap();
|
|
199
307
|
}
|
|
200
308
|
/**
|
|
201
309
|
* Request feature information for a given coordinate.
|
|
202
310
|
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
203
311
|
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
312
|
+
* @deprecated Use getFeatureInfoAtCoordinate([layer], coordinate) from mobility-toolbox-ol package instead.
|
|
204
313
|
*/
|
|
205
314
|
getFeatureInfoAtCoordinate(coordinate) {
|
|
206
315
|
var _a;
|
|
@@ -217,6 +326,7 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
217
326
|
let layers = this.layers || [];
|
|
218
327
|
if (this.layersFilter) {
|
|
219
328
|
layers = mapLibreMap.getStyle().layers.filter(this.layersFilter);
|
|
329
|
+
console.log(layers);
|
|
220
330
|
}
|
|
221
331
|
if (this.queryRenderedLayersFilter) {
|
|
222
332
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -251,11 +361,11 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
251
361
|
/**
|
|
252
362
|
* Highlight a list of features.
|
|
253
363
|
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
254
|
-
* @
|
|
364
|
+
* @deprecated Use layer.setFeatureState(features, {hover: true|false}) instead.
|
|
255
365
|
*/
|
|
256
366
|
highlight(features = []) {
|
|
257
367
|
var _a;
|
|
258
|
-
deprecated(`Deprecated. Use layer.setFeatureState(features, {
|
|
368
|
+
deprecated(`Deprecated. Use layer.setFeatureState(features, {hover: true}) instead.`);
|
|
259
369
|
// Filter out selected features
|
|
260
370
|
const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
|
|
261
371
|
.map((feat) => feat.getId())
|
|
@@ -268,7 +378,6 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
268
378
|
}
|
|
269
379
|
/**
|
|
270
380
|
* On Maplibre map load callback function. Add style layers and dynaimc filters.
|
|
271
|
-
* @private
|
|
272
381
|
*/
|
|
273
382
|
onLoad() {
|
|
274
383
|
var _a;
|
|
@@ -285,7 +394,6 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
285
394
|
}
|
|
286
395
|
this.applyLayoutVisibility();
|
|
287
396
|
}
|
|
288
|
-
/** @private */
|
|
289
397
|
removeLayers() {
|
|
290
398
|
var _a;
|
|
291
399
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !Array.isArray(this.layers)) {
|
|
@@ -301,7 +409,22 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
301
409
|
});
|
|
302
410
|
}
|
|
303
411
|
}
|
|
304
|
-
/**
|
|
412
|
+
// /**
|
|
413
|
+
// * Set filter that determines which features should be rendered in a style layer.
|
|
414
|
+
// * @param {maplibregl.filter} filter Determines which features should be rendered in a style layer.
|
|
415
|
+
// */
|
|
416
|
+
// setFilter(filter: { [key: string]: any }) {
|
|
417
|
+
// if (!this.maplibreLayer?.mapLibreMap) {
|
|
418
|
+
// return;
|
|
419
|
+
// }
|
|
420
|
+
// const { mapLibreMap } = this.maplibreLayer;
|
|
421
|
+
// this.styleLayers.forEach(({ id }) => {
|
|
422
|
+
// if (id && filter && mapLibreMap.getLayer(id)) {
|
|
423
|
+
// // @ts-expect-error
|
|
424
|
+
// mapLibreMap.setFilter(id, filter);
|
|
425
|
+
// }
|
|
426
|
+
// });
|
|
427
|
+
// }
|
|
305
428
|
removeSources() {
|
|
306
429
|
var _a;
|
|
307
430
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !this.sources) {
|
|
@@ -319,7 +442,7 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
319
442
|
/**
|
|
320
443
|
* Select a list of features.
|
|
321
444
|
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
322
|
-
* @
|
|
445
|
+
* @deprecated Use layer.setFeatureState(features, {selected: true|false}) instead.
|
|
323
446
|
*/
|
|
324
447
|
select(features = []) {
|
|
325
448
|
deprecated(`Deprecated. Use layer.setFeatureState(features, {selected: true}) instead.`);
|
|
@@ -328,9 +451,10 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
328
451
|
this.setHoverState(this.selectedFeatures || [], true);
|
|
329
452
|
}
|
|
330
453
|
/**
|
|
331
|
-
* Set the feature state of the features.
|
|
332
|
-
*
|
|
333
|
-
* @param {
|
|
454
|
+
* Set the [feature state](https://maplibre.org/maplibre-style-spec/expressions/#feature-state) of the features.
|
|
455
|
+
*
|
|
456
|
+
* @param {ol/Feature~Feature[]} features
|
|
457
|
+
* @param {{[key: string]: any}} state The feature state
|
|
334
458
|
* @public
|
|
335
459
|
*/
|
|
336
460
|
setFeatureState(features, state) {
|
|
@@ -338,7 +462,7 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
338
462
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !features.length) {
|
|
339
463
|
return;
|
|
340
464
|
}
|
|
341
|
-
const
|
|
465
|
+
const mapLibreMap = this.maplibreLayer.mapLibreMap;
|
|
342
466
|
features.forEach((feature) => {
|
|
343
467
|
const { source, sourceLayer } = feature.get(VECTOR_TILE_FEATURE_PROPERTY) || {};
|
|
344
468
|
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
@@ -358,98 +482,21 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
358
482
|
* Set if features are hovered or not.
|
|
359
483
|
* @param {Array<ol/Feature~Feature>} features
|
|
360
484
|
* @param {boolean} state Is the feature hovered
|
|
361
|
-
* @
|
|
485
|
+
* @deprecated Use layer.setFeatureState(features, {hover: true|false}) instead.
|
|
362
486
|
*/
|
|
363
487
|
setHoverState(features, state) {
|
|
364
488
|
deprecated(`Deprecated. Use layer.setFeatureState(features, {hover: ${state}}) instead.`);
|
|
365
489
|
this.setFeatureState(features, { hover: state });
|
|
366
490
|
}
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
set layers(newValue) {
|
|
377
|
-
this.set('layers', newValue);
|
|
378
|
-
}
|
|
379
|
-
get layersFilter() {
|
|
380
|
-
return this.get('layersFilter');
|
|
381
|
-
}
|
|
382
|
-
set layersFilter(newValue) {
|
|
383
|
-
this.set('layersFilter', newValue);
|
|
384
|
-
}
|
|
385
|
-
get mapboxLayer() {
|
|
386
|
-
deprecated('Deprecated. Use maplibreLayer instead.');
|
|
387
|
-
return this.get('maplibreLayer');
|
|
388
|
-
}
|
|
389
|
-
get maplibreLayer() {
|
|
390
|
-
return this.get('maplibreLayer');
|
|
391
|
-
}
|
|
392
|
-
set maplibreLayer(newValue) {
|
|
393
|
-
this.set('maplibreLayer', newValue);
|
|
394
|
-
}
|
|
395
|
-
get queryRenderedLayersFilter() {
|
|
396
|
-
return this.get('queryRenderedLayersFilter');
|
|
397
|
-
}
|
|
398
|
-
set queryRenderedLayersFilter(newValue) {
|
|
399
|
-
this.set('queryRenderedLayersFilter', newValue);
|
|
400
|
-
}
|
|
401
|
-
get sources() {
|
|
402
|
-
return this.get('sources');
|
|
403
|
-
}
|
|
404
|
-
// /**
|
|
405
|
-
// * Set filter that determines which features should be rendered in a style layer.
|
|
406
|
-
// * @param {maplibregl.filter} filter Determines which features should be rendered in a style layer.
|
|
407
|
-
// */
|
|
408
|
-
// setFilter(filter: { [key: string]: any }) {
|
|
409
|
-
// if (!this.maplibreLayer?.mapLibreMap) {
|
|
410
|
-
// return;
|
|
411
|
-
// }
|
|
412
|
-
// const { mapLibreMap } = this.maplibreLayer;
|
|
413
|
-
// this.styleLayers.forEach(({ id }) => {
|
|
414
|
-
// if (id && filter && mapLibreMap.getLayer(id)) {
|
|
415
|
-
// // @ts-expect-error
|
|
416
|
-
// mapLibreMap.setFilter(id, filter);
|
|
417
|
-
// }
|
|
418
|
-
// });
|
|
419
|
-
// }
|
|
420
|
-
set sources(newValue) {
|
|
421
|
-
this.set('sources', newValue);
|
|
422
|
-
}
|
|
423
|
-
/**
|
|
424
|
-
* @deprecated
|
|
425
|
-
*/
|
|
426
|
-
get styleLayer() {
|
|
427
|
-
deprecated('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
428
|
-
return this.layers[0];
|
|
429
|
-
}
|
|
430
|
-
/**
|
|
431
|
-
* @deprecated
|
|
432
|
-
*/
|
|
433
|
-
set styleLayer(newValue) {
|
|
434
|
-
deprecated('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
435
|
-
this.layers = [newValue];
|
|
436
|
-
}
|
|
437
|
-
/**
|
|
438
|
-
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
439
|
-
*/
|
|
440
|
-
/**
|
|
441
|
-
* @deprecated
|
|
442
|
-
*/
|
|
443
|
-
get styleLayers() {
|
|
444
|
-
deprecated('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
|
|
445
|
-
return this.layers;
|
|
446
|
-
}
|
|
447
|
-
/**
|
|
448
|
-
* @deprecated
|
|
449
|
-
*/
|
|
450
|
-
set styleLayers(newValue) {
|
|
451
|
-
deprecated('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
|
|
452
|
-
this.layers = newValue;
|
|
491
|
+
setMapInternal(map) {
|
|
492
|
+
if (map) {
|
|
493
|
+
super.setMapInternal(map);
|
|
494
|
+
this.attachToMap(map);
|
|
495
|
+
}
|
|
496
|
+
else {
|
|
497
|
+
this.detachFromMap();
|
|
498
|
+
super.setMapInternal(map);
|
|
499
|
+
}
|
|
453
500
|
}
|
|
454
501
|
}
|
|
455
502
|
export default MaplibreStyleLayer;
|