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