mobility-toolbox-js 3.0.0-beta.19 → 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.
- package/api/HttpAPI.d.ts +5 -5
- package/api/RealtimeAPI.d.ts +204 -171
- package/api/RealtimeAPI.js +306 -258
- package/api/RoutingAPI.d.ts +4 -4
- package/api/StopsAPI.d.ts +4 -4
- package/api/WebSocketAPI.d.ts +60 -66
- package/api/WebSocketAPI.js +164 -164
- package/api/index.js +1 -1
- package/common/controls/StopFinderControlCommon.d.ts +11 -11
- package/common/controls/StopFinderControlCommon.js +30 -30
- package/common/index.d.ts +1 -1
- package/common/index.js +1 -1
- package/common/mixins/RealtimeLayerMixin.d.ts +149 -155
- package/common/mixins/RealtimeLayerMixin.js +395 -395
- package/common/styles/realtimeDefaultStyle.js +6 -6
- package/common/styles/realtimeHeadingStyle.js +5 -5
- package/common/utils/getMapGlCopyrights.d.ts +1 -1
- package/common/utils/getMapGlCopyrights.js +3 -3
- package/common/utils/getVehiclePosition.d.ts +2 -2
- package/common/utils/getVehiclePosition.js +7 -7
- package/common/utils/renderTrajectories.js +5 -5
- package/common/utils/sortByDelay.js +5 -5
- package/maplibre/layers/RealtimeLayer.d.ts +59 -64
- package/maplibre/layers/RealtimeLayer.js +8 -8
- package/maplibre/utils/getSourceCoordinates.js +5 -5
- package/mbt.js +7205 -7031
- package/mbt.js.map +4 -4
- package/mbt.min.js +25 -25
- package/mbt.min.js.map +4 -4
- package/ol/controls/RoutingControl.d.ts +81 -87
- package/ol/controls/RoutingControl.js +216 -218
- package/ol/layers/Layer.d.ts +9 -9
- package/ol/layers/MaplibreLayer.d.ts +10 -10
- package/ol/layers/MaplibreLayer.js +9 -3
- package/ol/layers/MaplibreStyleLayer.d.ts +77 -76
- package/ol/layers/MaplibreStyleLayer.js +237 -238
- package/ol/layers/RealtimeLayer.d.ts +92 -96
- package/ol/layers/RealtimeLayer.js +139 -131
- package/ol/mixins/MobilityLayerMixin.d.ts +9 -9
- package/ol/mixins/PropertiesLayerMixin.d.ts +33 -36
- package/ol/mixins/PropertiesLayerMixin.js +73 -72
- package/ol/renderers/MaplibreLayerRenderer.js +3 -3
- package/ol/renderers/MaplibreStyleLayerRenderer.d.ts +6 -6
- package/ol/renderers/MaplibreStyleLayerRenderer.js +14 -17
- package/ol/renderers/RealtimeLayerRenderer.d.ts +6 -6
- package/ol/renderers/RealtimeLayerRenderer.js +54 -52
- package/ol/utils/getFeatureInfoAtCoordinate.d.ts +1 -1
- package/ol/utils/getFeatureInfoAtCoordinate.js +10 -16
- package/package.json +6 -5
- package/setupTests.js +3 -4
- package/types/common.d.ts +53 -49
- package/types/index.d.ts +1 -1
- package/types/realtime.d.ts +91 -93
- package/types/routing.d.ts +60 -60
- package/types/stops.d.ts +62 -62
|
@@ -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('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer 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('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
80
|
-
this.layers = [newValue];
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* @deprecated
|
|
84
|
-
*/
|
|
85
|
-
get styleLayers() {
|
|
86
|
-
// eslint-disable-next-line no-console
|
|
87
|
-
console.warn('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.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('MaplibreStyleLayer.styleLayers is deprecated. Use MaplibreStyleLayer.layers instead.');
|
|
96
|
-
this.layers = newValue;
|
|
97
|
-
}
|
|
98
25
|
/**
|
|
99
26
|
* Constructor.
|
|
100
27
|
*
|
|
@@ -106,7 +33,7 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
106
33
|
* @param {FilterFunction} [options.queryRenderedLayersFilter] Filter function to decide which style layer are available for query.
|
|
107
34
|
*/
|
|
108
35
|
constructor(options = {
|
|
109
|
-
mapLibreOptions: { style: {
|
|
36
|
+
mapLibreOptions: { style: { layers: [], sources: {}, version: 8 } },
|
|
110
37
|
}) {
|
|
111
38
|
/** Manage renamed property for backward compatibility with v2 */
|
|
112
39
|
if (options.mapboxLayer) {
|
|
@@ -130,8 +57,64 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
130
57
|
};
|
|
131
58
|
}
|
|
132
59
|
}
|
|
133
|
-
|
|
134
|
-
|
|
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
|
+
}
|
|
135
118
|
}
|
|
136
119
|
/**
|
|
137
120
|
* Initialize the layer.
|
|
@@ -170,7 +153,7 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
170
153
|
}
|
|
171
154
|
// Apply the visibiltity when layer's visibility change.
|
|
172
155
|
this.olEventsKeys.push(
|
|
173
|
-
// @ts-expect-error
|
|
156
|
+
// @ts-expect-error 'load' is a custom event
|
|
174
157
|
this.maplibreLayer.on('load', this.onLoad.bind(this)), this.on('change:visible', (evt) => {
|
|
175
158
|
// Once the map is loaded we can apply visiblity without waiting
|
|
176
159
|
// the style. Maplibre take care of the application of style changes.
|
|
@@ -182,6 +165,17 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
182
165
|
}
|
|
183
166
|
}));
|
|
184
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
|
+
}
|
|
185
179
|
/**
|
|
186
180
|
* Terminate the layer.
|
|
187
181
|
* @override
|
|
@@ -195,90 +189,138 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
195
189
|
}
|
|
196
190
|
super.detachFromMap();
|
|
197
191
|
}
|
|
198
|
-
/**
|
|
199
|
-
|
|
192
|
+
/**
|
|
193
|
+
* Request feature information for a given coordinate.
|
|
194
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
195
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
196
|
+
*/
|
|
197
|
+
getFeatureInfoAtCoordinate(coordinate) {
|
|
200
198
|
var _a;
|
|
201
|
-
|
|
202
|
-
|
|
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)) {
|
|
202
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
203
203
|
}
|
|
204
204
|
const { mapLibreMap } = this.maplibreLayer;
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
205
|
+
// Ignore the getFeatureInfo until the Maplibre map is loaded
|
|
206
|
+
if (!mapLibreMap.isStyleLoaded()) {
|
|
207
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
208
|
+
}
|
|
209
|
+
// We query features only on style layers used by this layer.
|
|
210
|
+
let layers = this.layers || [];
|
|
211
|
+
if (this.layersFilter) {
|
|
212
|
+
layers = mapLibreMap.getStyle().layers.filter(this.layersFilter);
|
|
213
|
+
}
|
|
214
|
+
if (this.queryRenderedLayersFilter) {
|
|
215
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
216
|
+
layers = mapLibreMap
|
|
217
|
+
.getStyle()
|
|
218
|
+
.layers.filter(this.queryRenderedLayersFilter);
|
|
211
219
|
}
|
|
220
|
+
return Promise.resolve({
|
|
221
|
+
coordinate,
|
|
222
|
+
features: [],
|
|
223
|
+
layer: this,
|
|
224
|
+
});
|
|
225
|
+
// this.maplibreLayer
|
|
226
|
+
// .getFeatureInfoAtCoordinate(coordinate, {
|
|
227
|
+
// layers: layers.map((layer) => layer && layer.id),
|
|
228
|
+
// validate: false,
|
|
229
|
+
// })
|
|
230
|
+
// .then((featureInfo: LayerGetFeatureInfoResponse) => {
|
|
231
|
+
// const features: Feature[] = featureInfo.features.filter(
|
|
232
|
+
// (feature: Feature) => {
|
|
233
|
+
// // @ts-expect-error
|
|
234
|
+
// return this.featureInfoFilter(
|
|
235
|
+
// feature,
|
|
236
|
+
// this.map?.getView().getResolution(),
|
|
237
|
+
// ) as Feature[];
|
|
238
|
+
// },
|
|
239
|
+
// );
|
|
240
|
+
// this.highlight(features);
|
|
241
|
+
// return { ...featureInfo, features, layer: this };
|
|
242
|
+
// });
|
|
212
243
|
}
|
|
213
|
-
/**
|
|
214
|
-
|
|
244
|
+
/**
|
|
245
|
+
* Highlight a list of features.
|
|
246
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
247
|
+
* @private
|
|
248
|
+
*/
|
|
249
|
+
highlight(features = []) {
|
|
215
250
|
var _a;
|
|
216
|
-
|
|
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)) {
|
|
217
270
|
return;
|
|
218
271
|
}
|
|
272
|
+
this.addSources();
|
|
273
|
+
this.addLayers();
|
|
219
274
|
const { mapLibreMap } = this.maplibreLayer;
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
225
|
-
});
|
|
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);
|
|
226
279
|
}
|
|
280
|
+
this.applyLayoutVisibility();
|
|
227
281
|
}
|
|
228
282
|
/** @private */
|
|
229
|
-
|
|
283
|
+
removeLayers() {
|
|
230
284
|
var _a;
|
|
231
285
|
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !Array.isArray(this.layers)) {
|
|
232
286
|
return;
|
|
233
287
|
}
|
|
234
288
|
const { mapLibreMap } = this.maplibreLayer;
|
|
235
289
|
if (mapLibreMap) {
|
|
236
|
-
this.layers.forEach((
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
id &&
|
|
241
|
-
!mapLibreMap.getLayer(id)) {
|
|
242
|
-
mapLibreMap.addLayer(layer, this.beforeId);
|
|
290
|
+
this.layers.forEach((styleLayer) => {
|
|
291
|
+
const { id } = styleLayer;
|
|
292
|
+
if (id && mapLibreMap.getLayer(id)) {
|
|
293
|
+
mapLibreMap.removeLayer(id);
|
|
243
294
|
}
|
|
244
295
|
});
|
|
245
|
-
this.applyLayoutVisibility();
|
|
246
296
|
}
|
|
247
297
|
}
|
|
248
298
|
/** @private */
|
|
249
|
-
|
|
299
|
+
removeSources() {
|
|
250
300
|
var _a;
|
|
251
|
-
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !
|
|
301
|
+
if (!((_a = this.maplibreLayer) === null || _a === void 0 ? void 0 : _a.mapLibreMap) || !this.sources) {
|
|
252
302
|
return;
|
|
253
303
|
}
|
|
254
304
|
const { mapLibreMap } = this.maplibreLayer;
|
|
255
305
|
if (mapLibreMap) {
|
|
256
|
-
this.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
mapLibreMap.removeLayer(id);
|
|
306
|
+
Object.keys(this.sources).forEach((id) => {
|
|
307
|
+
if (mapLibreMap.getSource(id)) {
|
|
308
|
+
mapLibreMap.removeSource(id);
|
|
260
309
|
}
|
|
261
310
|
});
|
|
262
311
|
}
|
|
263
312
|
}
|
|
264
313
|
/**
|
|
265
|
-
*
|
|
314
|
+
* Select a list of features.
|
|
315
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
266
316
|
* @private
|
|
267
317
|
*/
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
this.
|
|
274
|
-
this.addLayers();
|
|
275
|
-
const { mapLibreMap } = this.maplibreLayer;
|
|
276
|
-
const style = mapLibreMap.getStyle();
|
|
277
|
-
if ((style === null || style === void 0 ? void 0 : style.layers) && this.layersFilter) {
|
|
278
|
-
const styles = style.layers.filter(this.layersFilter);
|
|
279
|
-
this.set('disabled', !styles.length);
|
|
280
|
-
}
|
|
281
|
-
this.applyLayoutVisibility();
|
|
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);
|
|
282
324
|
}
|
|
283
325
|
/**
|
|
284
326
|
* Set the feature state of the features.
|
|
@@ -309,57 +351,53 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
309
351
|
});
|
|
310
352
|
}
|
|
311
353
|
/**
|
|
312
|
-
*
|
|
313
|
-
* @param {ol/
|
|
314
|
-
* @
|
|
354
|
+
* Set if features are hovered or not.
|
|
355
|
+
* @param {Array<ol/Feature~Feature>} features
|
|
356
|
+
* @param {boolean} state Is the feature hovered
|
|
357
|
+
* @private
|
|
315
358
|
*/
|
|
316
|
-
|
|
317
|
-
var _a;
|
|
359
|
+
setHoverState(features, state) {
|
|
318
360
|
// eslint-disable-next-line no-console
|
|
319
|
-
console.warn(`Deprecated.
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
// );
|
|
360
|
-
// this.highlight(features);
|
|
361
|
-
// return { ...featureInfo, features, layer: this };
|
|
362
|
-
// });
|
|
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');
|
|
363
401
|
}
|
|
364
402
|
// /**
|
|
365
403
|
// * Set filter that determines which features should be rendered in a style layer.
|
|
@@ -372,87 +410,48 @@ class MaplibreStyleLayer extends MobilityLayerMixin(Layer) {
|
|
|
372
410
|
// const { mapLibreMap } = this.maplibreLayer;
|
|
373
411
|
// this.styleLayers.forEach(({ id }) => {
|
|
374
412
|
// if (id && filter && mapLibreMap.getLayer(id)) {
|
|
375
|
-
// // @ts-
|
|
413
|
+
// // @ts-expect-error
|
|
376
414
|
// mapLibreMap.setFilter(id, filter);
|
|
377
415
|
// }
|
|
378
416
|
// });
|
|
379
417
|
// }
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
* @param {Array<ol/Feature~Feature>} features
|
|
383
|
-
* @param {boolean} state Is the feature hovered
|
|
384
|
-
* @private
|
|
385
|
-
*/
|
|
386
|
-
setHoverState(features, state) {
|
|
387
|
-
// eslint-disable-next-line no-console
|
|
388
|
-
console.warn(`Deprecated. Use layer.setFeatureState(features, {hover: ${state}}) instead.`);
|
|
389
|
-
this.setFeatureState(features, { hover: state });
|
|
418
|
+
set sources(newValue) {
|
|
419
|
+
this.set('sources', newValue);
|
|
390
420
|
}
|
|
391
421
|
/**
|
|
392
|
-
*
|
|
393
|
-
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
394
|
-
* @private
|
|
422
|
+
* @deprecated
|
|
395
423
|
*/
|
|
396
|
-
|
|
424
|
+
get styleLayer() {
|
|
397
425
|
// eslint-disable-next-line no-console
|
|
398
|
-
console.warn(
|
|
399
|
-
this.
|
|
400
|
-
this.selectedFeatures = features;
|
|
401
|
-
this.setHoverState(this.selectedFeatures || [], true);
|
|
426
|
+
console.warn('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
427
|
+
return this.layers[0];
|
|
402
428
|
}
|
|
403
429
|
/**
|
|
404
|
-
*
|
|
405
|
-
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
406
|
-
* @private
|
|
430
|
+
* @deprecated
|
|
407
431
|
*/
|
|
408
|
-
|
|
409
|
-
var _a;
|
|
432
|
+
set styleLayer(newValue) {
|
|
410
433
|
// eslint-disable-next-line no-console
|
|
411
|
-
console.warn(
|
|
412
|
-
|
|
413
|
-
const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
|
|
414
|
-
.map((feat) => feat.getId())
|
|
415
|
-
.includes(feature.getId()))) || [];
|
|
416
|
-
// Remove previous highlight
|
|
417
|
-
this.setHoverState(filtered, false);
|
|
418
|
-
this.highlightedFeatures = features;
|
|
419
|
-
// Add highlight
|
|
420
|
-
this.setHoverState(this.highlightedFeatures, true);
|
|
434
|
+
console.warn('MaplibreStyleLayer.styleLayer is deprecated. Use MaplibreStyleLayer.layer instead.');
|
|
435
|
+
this.layers = [newValue];
|
|
421
436
|
}
|
|
422
437
|
/**
|
|
423
438
|
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
424
439
|
*/
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
const style = mapLibreMap.getStyle();
|
|
433
|
-
const visibilityValue = this.getVisible() ? 'visible' : 'none';
|
|
434
|
-
const layers = style.layers || [];
|
|
435
|
-
for (let i = 0; i < layers.length; i += 1) {
|
|
436
|
-
const layer = layers[i];
|
|
437
|
-
if (this.layersFilter(layer)) {
|
|
438
|
-
const { id } = layer;
|
|
439
|
-
if (mapLibreMap.getLayer(id)) {
|
|
440
|
-
mapLibreMap.setLayoutProperty(id, 'visibility', visibilityValue);
|
|
441
|
-
if (this.getMinZoom() || this.getMaxZoom()) {
|
|
442
|
-
mapLibreMap.setLayerZoomRange(id, this.getMinZoom() ? this.getMinZoom() - 1 : 0, // Maplibre zoom = ol zoom - 1
|
|
443
|
-
this.getMaxZoom() ? this.getMaxZoom() - 1 : 24);
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
}
|
|
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;
|
|
448
447
|
}
|
|
449
448
|
/**
|
|
450
|
-
*
|
|
451
|
-
* @param {Object} newOptions Options to override.
|
|
452
|
-
* @return {MapboxStyleLayer} A MapboxStyleLayer.
|
|
449
|
+
* @deprecated
|
|
453
450
|
*/
|
|
454
|
-
|
|
455
|
-
|
|
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;
|
|
456
455
|
}
|
|
457
456
|
}
|
|
458
457
|
export default MaplibreStyleLayer;
|