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