mobility-toolbox-js 2.0.1-beta.13 → 2.1.0
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/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +32 -12
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +33 -9
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/typedefs.js +75 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +54 -27
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +330 -164
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -4
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/realtimeDelayStyle.d.ts +12 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +52 -0
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +26 -15
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +67 -37
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +17 -5
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +12 -5
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -15
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +34 -15
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +8 -6
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +44 -25
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -1
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -4
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +99 -55
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -2
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +26061 -16500
- package/mbt.js.map +4 -4
- package/mbt.min.js +205 -126
- package/mbt.min.js.map +4 -4
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +62 -36
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +601 -357
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +30 -8
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -3
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +5 -5
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +163 -77
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +99 -193
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +362 -171
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +30 -135
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +72 -48
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +34 -18
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +84 -34
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -8
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +26 -24
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +40 -39
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/ol/styles/index.js +2 -2
- package/package.json +81 -133
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.test.js +0 -22
- package/api/TralisAPI.js +0 -359
- package/api/TralisAPI.test.js +0 -67
- package/api/TralisAPIUtils.js +0 -43
- package/common/Tracker.js +0 -93
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -213
- package/common/layers/Layer.test.js +0 -526
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/SearchMixin.js +0 -110
- package/common/mixins/TralisLayerMixin.js +0 -479
- package/common/styles/trackerDefaultStyle.js +0 -197
- package/common/styles/trackerDelayStyle.js +0 -8
- package/common/styles/trackerSimpleStyle.js +0 -18
- package/common/trackerConfig.js +0 -152
- package/common/trackerConfig.test.js +0 -23
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getMapboxStyleUrl.js +0 -22
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/timeUtils.test.js +0 -10
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/TralisLayer.js +0 -182
- package/mapbox/layers/TralisLayer.test.js +0 -38
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.test.js +0 -151
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.test.js +0 -174
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.test.js +0 -231
- package/ol/layers/RoutingLayer.test.js +0 -40
- package/ol/layers/TralisLayer.js +0 -185
- package/ol/layers/TralisLayer.test.js +0 -79
- package/ol/layers/VectorLayer.test.js +0 -87
- package/ol/layers/WMSLayer.test.js +0 -76
|
@@ -1,187 +1,378 @@
|
|
|
1
|
-
import Layer from
|
|
1
|
+
import Layer from './Layer';
|
|
2
|
+
/**
|
|
3
|
+
* Layer for visualizing a specific set of layer from a MapboxLayer.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import { MapboxLayer, MapboxStyleLayer } from 'mobility-toolbox-js/ol';
|
|
7
|
+
*
|
|
8
|
+
* const mapboxLayer = new MapboxLayer({
|
|
9
|
+
* url: 'https://maps.geops.io/styles/travic_v2/style.json?key=[yourApiKey]',
|
|
10
|
+
* });
|
|
11
|
+
*
|
|
12
|
+
* const layer = new MapboxStyleLayer({
|
|
13
|
+
* mapboxLayer: mapboxLayer,
|
|
14
|
+
* styleLayersFilter: () => {},
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
18
|
+
* @extends {Layer}
|
|
19
|
+
*/
|
|
2
20
|
class MapboxStyleLayer extends Layer {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
21
|
+
/**
|
|
22
|
+
* Constructor.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} options
|
|
25
|
+
* @param {MapboxLayer} [options.mapboxLayer] The MapboxLayer to use.
|
|
26
|
+
* @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
|
|
27
|
+
*/
|
|
28
|
+
constructor(options) {
|
|
29
|
+
super(options);
|
|
30
|
+
/**
|
|
31
|
+
* MapboxLayer provided for the style Layer.
|
|
32
|
+
* @type {MapboxLayer}
|
|
33
|
+
* @private
|
|
34
|
+
*/
|
|
35
|
+
this.mapboxLayer = options.mapboxLayer;
|
|
36
|
+
/**
|
|
37
|
+
* Define if the layer has data to display in the current mapbox layer.
|
|
38
|
+
*/
|
|
39
|
+
this.disabled = false;
|
|
40
|
+
/**
|
|
41
|
+
* Function to filter features to be displayed.
|
|
42
|
+
* @type {function}
|
|
43
|
+
* @private
|
|
44
|
+
*/
|
|
45
|
+
this.styleLayersFilter = options.styleLayersFilter;
|
|
46
|
+
/**
|
|
47
|
+
* Mapbox style layer id where to add the style layers.
|
|
48
|
+
* See [mapbox.map.addLayer](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer) documentation.
|
|
49
|
+
* @type {String}
|
|
50
|
+
* @private
|
|
51
|
+
*/
|
|
52
|
+
this.beforeId = options.beforeId;
|
|
53
|
+
/**
|
|
54
|
+
* Function to filter features for getFeatureInfoAtCoordinate method.
|
|
55
|
+
* @type {function}
|
|
56
|
+
* @private
|
|
57
|
+
*/
|
|
58
|
+
this.featureInfoFilter = options.featureInfoFilter || ((obj) => obj);
|
|
59
|
+
/**
|
|
60
|
+
* Function to query the rendered features.
|
|
61
|
+
* @type {function}
|
|
62
|
+
* @private
|
|
63
|
+
*/
|
|
64
|
+
this.queryRenderedLayersFilter = options.queryRenderedLayersFilter;
|
|
65
|
+
/**
|
|
66
|
+
* Array of features to highlight.
|
|
67
|
+
* @type {Array<ol/Feature~Feature>}
|
|
68
|
+
* @private
|
|
69
|
+
*/
|
|
70
|
+
this.highlightedFeatures = [];
|
|
71
|
+
/**
|
|
72
|
+
* Array of selected features.
|
|
73
|
+
* @type {Array<ol/Feature~Feature>}
|
|
74
|
+
* @private
|
|
75
|
+
*/
|
|
76
|
+
this.selectedFeatures = [];
|
|
77
|
+
/**
|
|
78
|
+
* Array of mapbox style layers to add.
|
|
79
|
+
* @type {Array<mapboxgl.styleLayer>}
|
|
80
|
+
* @private
|
|
81
|
+
*/
|
|
82
|
+
this.styleLayers =
|
|
83
|
+
(options.styleLayer ? [options.styleLayer] : options.styleLayers) || [];
|
|
84
|
+
/**
|
|
85
|
+
* @private
|
|
86
|
+
*/
|
|
87
|
+
this.addStyleLayers = this.addStyleLayers.bind(this);
|
|
88
|
+
/**
|
|
89
|
+
* @private
|
|
90
|
+
*/
|
|
91
|
+
this.onLoad = this.onLoad.bind(this);
|
|
92
|
+
if (options.filters) {
|
|
93
|
+
/** @private */
|
|
94
|
+
this.addDynamicFilters = () => {
|
|
95
|
+
this.setFilter(typeof options.filters === 'function'
|
|
96
|
+
? options.filters(this)
|
|
97
|
+
: options.filters);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
if (!this.styleLayersFilter && this.styleLayers) {
|
|
101
|
+
this.styleLayersFilter = (styleLayer) => {
|
|
102
|
+
var _a;
|
|
103
|
+
return !!((_a = this.styleLayers) === null || _a === void 0 ? void 0 : _a.find((sl) => styleLayer.id === sl.id));
|
|
104
|
+
};
|
|
105
|
+
}
|
|
58
106
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
107
|
+
/**
|
|
108
|
+
* Initialize the layer.
|
|
109
|
+
* @param {ol/Map~Map} map the mapbox map.
|
|
110
|
+
* @override
|
|
111
|
+
*/
|
|
112
|
+
attachToMap(map) {
|
|
113
|
+
var _a;
|
|
114
|
+
if (this.mapboxLayer && !this.mapboxLayer.map) {
|
|
115
|
+
(_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.attachToMap(map);
|
|
116
|
+
}
|
|
117
|
+
super.attachToMap(map);
|
|
118
|
+
if (!this.map || !this.mapboxLayer) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
// Apply the initial visibiltity.
|
|
122
|
+
const { mbMap } = this.mapboxLayer;
|
|
123
|
+
if (!mbMap) {
|
|
124
|
+
// If the mbMap is not yet created because the map has no target yet, we
|
|
125
|
+
// relaunch the initialisation when it's the case.
|
|
126
|
+
this.olListenersKeys.push(this.map.on('change:target', () => {
|
|
127
|
+
this.attachToMap(map);
|
|
128
|
+
}));
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
// mbMap.loaded() and mbMap.isStyleLoaded() are reliable only on the first call of init.
|
|
132
|
+
// On the next call (when a topic change for example), these functions returns false because
|
|
133
|
+
// the style is being modified.
|
|
134
|
+
// That's why we rely on a property instead for the next calls.
|
|
135
|
+
if (this.mapboxLayer.loaded || mbMap.isStyleLoaded() || mbMap.loaded()) {
|
|
136
|
+
this.onLoad();
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
mbMap.once('load', this.onLoad);
|
|
140
|
+
}
|
|
141
|
+
// Apply the visibiltity when layer's visibility change.
|
|
142
|
+
this.olListenersKeys.push(
|
|
143
|
+
// @ts-ignore
|
|
144
|
+
this.on('change:visible', (evt) => {
|
|
145
|
+
// Once the map is loaded we can apply visiblity without waiting
|
|
146
|
+
// the style. Mapbox take care of the application of style changes.
|
|
147
|
+
this.applyLayoutVisibility(evt);
|
|
148
|
+
}));
|
|
149
|
+
this.olListenersKeys.push(
|
|
150
|
+
// @ts-ignore
|
|
151
|
+
this.mapboxLayer.on('load', () => {
|
|
152
|
+
this.onLoad();
|
|
153
|
+
}));
|
|
65
154
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
155
|
+
/**
|
|
156
|
+
* Terminate the layer.
|
|
157
|
+
* @override
|
|
158
|
+
*/
|
|
159
|
+
detachFromMap() {
|
|
160
|
+
var _a;
|
|
161
|
+
if ((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap) {
|
|
162
|
+
const { mbMap } = this.mapboxLayer;
|
|
163
|
+
mbMap.off('load', this.onLoad);
|
|
164
|
+
this.removeStyleLayers();
|
|
165
|
+
}
|
|
166
|
+
super.detachFromMap();
|
|
78
167
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
168
|
+
/** @ignore */
|
|
169
|
+
addStyleLayers() {
|
|
170
|
+
var _a;
|
|
171
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
const { mbMap } = this.mapboxLayer;
|
|
175
|
+
this.styleLayers.forEach((styleLayer) => {
|
|
176
|
+
const { id, source } = styleLayer;
|
|
177
|
+
if (mbMap.getSource(source) && id && !mbMap.getLayer(id)) {
|
|
178
|
+
// @ts-ignore
|
|
179
|
+
mbMap.addLayer(styleLayer, this.beforeId);
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
this.applyLayoutVisibility();
|
|
89
183
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
184
|
+
/** @ignore */
|
|
185
|
+
removeStyleLayers() {
|
|
186
|
+
var _a;
|
|
187
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
const { mbMap } = this.mapboxLayer;
|
|
191
|
+
this.styleLayers.forEach((styleLayer) => {
|
|
192
|
+
const { id } = styleLayer;
|
|
193
|
+
if (id && mbMap.getLayer(id)) {
|
|
194
|
+
mbMap.removeLayer(id);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
95
197
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
198
|
+
/**
|
|
199
|
+
* On Mapbox map load callback function. Add style layers and dynaimc filters.
|
|
200
|
+
* @ignore
|
|
201
|
+
*/
|
|
202
|
+
onLoad() {
|
|
203
|
+
var _a;
|
|
204
|
+
this.addStyleLayers();
|
|
205
|
+
if (this.addDynamicFilters) {
|
|
206
|
+
this.addDynamicFilters();
|
|
207
|
+
}
|
|
208
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
const { mbMap } = this.mapboxLayer;
|
|
212
|
+
const style = mbMap.getStyle();
|
|
213
|
+
if (style && this.styleLayersFilter) {
|
|
214
|
+
// @ts-ignore
|
|
215
|
+
const styles = style.layers.filter(this.styleLayersFilter);
|
|
216
|
+
this.disabled = !styles.length;
|
|
217
|
+
}
|
|
101
218
|
}
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
219
|
+
/**
|
|
220
|
+
* Request feature information for a given coordinate.
|
|
221
|
+
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
222
|
+
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
223
|
+
*/
|
|
224
|
+
getFeatureInfoAtCoordinate(coordinate) {
|
|
225
|
+
var _a;
|
|
226
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
227
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
228
|
+
}
|
|
229
|
+
const { mbMap } = this.mapboxLayer;
|
|
230
|
+
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
231
|
+
if (!mbMap.isStyleLoaded()) {
|
|
232
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
233
|
+
}
|
|
234
|
+
// We query features only on style layers used by this layer.
|
|
235
|
+
let layers = this.styleLayers || [];
|
|
236
|
+
if (this.styleLayersFilter) {
|
|
237
|
+
// @ts-ignore
|
|
238
|
+
layers = mbMap.getStyle().layers.filter(this.styleLayersFilter);
|
|
239
|
+
}
|
|
240
|
+
if (this.queryRenderedLayersFilter) {
|
|
241
|
+
// @ts-ignore
|
|
242
|
+
layers = mbMap.getStyle().layers.filter(this.queryRenderedLayersFilter);
|
|
243
|
+
}
|
|
244
|
+
return this.mapboxLayer
|
|
245
|
+
.getFeatureInfoAtCoordinate(coordinate, {
|
|
246
|
+
layers: layers.map((layer) => layer && layer.id),
|
|
247
|
+
validate: false,
|
|
248
|
+
})
|
|
249
|
+
.then((featureInfo) => {
|
|
250
|
+
const features = featureInfo.features.filter((feature) => {
|
|
251
|
+
var _a;
|
|
252
|
+
// @ts-ignore
|
|
253
|
+
return this.featureInfoFilter(feature, (_a = this.map) === null || _a === void 0 ? void 0 : _a.getView().getResolution());
|
|
254
|
+
});
|
|
255
|
+
this.highlight(features);
|
|
256
|
+
return Object.assign(Object.assign({}, featureInfo), { features, layer: this });
|
|
257
|
+
});
|
|
105
258
|
}
|
|
106
|
-
|
|
107
|
-
|
|
259
|
+
/**
|
|
260
|
+
* Set filter that determines which features should be rendered in a style layer.
|
|
261
|
+
* @param {mapboxgl.filter} filter Determines which features should be rendered in a style layer.
|
|
262
|
+
*/
|
|
263
|
+
setFilter(filter) {
|
|
264
|
+
var _a;
|
|
265
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const { mbMap } = this.mapboxLayer;
|
|
269
|
+
this.styleLayers.forEach(({ id }) => {
|
|
270
|
+
if (id && filter && mbMap.getLayer(id)) {
|
|
271
|
+
// @ts-ignore
|
|
272
|
+
mbMap.setFilter(id, filter);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
108
275
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
276
|
+
/**
|
|
277
|
+
* Set if features are hovered or not.
|
|
278
|
+
* @param {Array<ol/Feature~Feature>} features
|
|
279
|
+
* @param {boolean} state Is the feature hovered
|
|
280
|
+
* @private
|
|
281
|
+
*/
|
|
282
|
+
setHoverState(features, state) {
|
|
283
|
+
var _a;
|
|
284
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
const { mbMap } = this.mapboxLayer;
|
|
288
|
+
if (!features || !mbMap) {
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
features.forEach((feature) => {
|
|
292
|
+
const { source, sourceLayer } = feature.get('mapboxFeature') || {};
|
|
293
|
+
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
294
|
+
if (!feature.getId()) {
|
|
295
|
+
// eslint-disable-next-line no-console
|
|
296
|
+
console.warn("No feature's id found. To use the feature state functionnality, tiles must be generated with --generate-ids. See https://github.com/mapbox/tippecanoe#adding-calculated-attributes.", feature.getId(), feature.getProperties());
|
|
297
|
+
}
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
mbMap.setFeatureState({
|
|
301
|
+
id: feature.getId(),
|
|
302
|
+
source,
|
|
303
|
+
sourceLayer,
|
|
304
|
+
}, { hover: state });
|
|
305
|
+
});
|
|
122
306
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
return;
|
|
307
|
+
/**
|
|
308
|
+
* Select a list of features.
|
|
309
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
310
|
+
* @private
|
|
311
|
+
*/
|
|
312
|
+
select(features = []) {
|
|
313
|
+
this.setHoverState(this.selectedFeatures || [], false);
|
|
314
|
+
this.selectedFeatures = features;
|
|
315
|
+
this.setHoverState(this.selectedFeatures || [], true);
|
|
133
316
|
}
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
this.setHoverState(this.selectedFeatures, false);
|
|
151
|
-
this.selectedFeatures = features;
|
|
152
|
-
this.setHoverState(this.selectedFeatures, true);
|
|
153
|
-
}
|
|
154
|
-
highlight(features = []) {
|
|
155
|
-
const filtered = this.highlightedFeatures.filter((feature) => !this.selectedFeatures.map((feat) => feat.getId()).includes(feature.getId()));
|
|
156
|
-
this.setHoverState(filtered, false);
|
|
157
|
-
this.highlightedFeatures = features;
|
|
158
|
-
this.setHoverState(this.highlightedFeatures, true);
|
|
159
|
-
}
|
|
160
|
-
applyLayoutVisibility(evt) {
|
|
161
|
-
const { visible } = this;
|
|
162
|
-
const { mbMap } = this.mapboxLayer;
|
|
163
|
-
const filterFunc = this.styleLayersFilter;
|
|
164
|
-
if (!mbMap) {
|
|
165
|
-
return;
|
|
317
|
+
/**
|
|
318
|
+
* Highlight a list of features.
|
|
319
|
+
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
320
|
+
* @private
|
|
321
|
+
*/
|
|
322
|
+
highlight(features = []) {
|
|
323
|
+
var _a;
|
|
324
|
+
// Filter out selected features
|
|
325
|
+
const filtered = ((_a = this.highlightedFeatures) === null || _a === void 0 ? void 0 : _a.filter((feature) => !(this.selectedFeatures || [])
|
|
326
|
+
.map((feat) => feat.getId())
|
|
327
|
+
.includes(feature.getId()))) || [];
|
|
328
|
+
// Remove previous highlight
|
|
329
|
+
this.setHoverState(filtered, false);
|
|
330
|
+
this.highlightedFeatures = features;
|
|
331
|
+
// Add highlight
|
|
332
|
+
this.setHoverState(this.highlightedFeatures, true);
|
|
166
333
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
334
|
+
/**
|
|
335
|
+
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
336
|
+
* @param {Event} evt Layer's event that has called the function.
|
|
337
|
+
* @private
|
|
338
|
+
*/
|
|
339
|
+
// eslint-disable-next-line no-unused-vars, @typescript-eslint/no-unused-vars
|
|
340
|
+
applyLayoutVisibility(evt) {
|
|
341
|
+
var _a;
|
|
342
|
+
const { visible } = this;
|
|
343
|
+
const filterFunc = this.styleLayersFilter;
|
|
344
|
+
if (!((_a = this.mapboxLayer) === null || _a === void 0 ? void 0 : _a.mbMap)) {
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
const { mbMap } = this.mapboxLayer;
|
|
348
|
+
const style = mbMap.getStyle();
|
|
349
|
+
if (!style) {
|
|
350
|
+
return;
|
|
351
|
+
}
|
|
352
|
+
if (filterFunc) {
|
|
353
|
+
const visibilityValue = visible ? 'visible' : 'none';
|
|
354
|
+
const layers = style.layers || [];
|
|
355
|
+
for (let i = 0; i < layers.length; i += 1) {
|
|
356
|
+
const styleLayer = layers[i];
|
|
357
|
+
if (filterFunc(styleLayer)) {
|
|
358
|
+
if (mbMap.getLayer(styleLayer.id)) {
|
|
359
|
+
mbMap.setLayoutProperty(styleLayer.id, 'visibility', visibilityValue);
|
|
360
|
+
if (this.get('minZoom') || this.get('maxZoom')) {
|
|
361
|
+
mbMap.setLayerZoomRange(styleLayer.id, this.get('minZoom') ? this.get('minZoom') - 1 : 0, // mapbox zoom = ol zoom - 1
|
|
362
|
+
this.get('maxZoom') ? this.get('maxZoom') - 1 : 24);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
170
368
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
}
|
|
369
|
+
/**
|
|
370
|
+
* Create a copy of the MapboxStyleLayer.
|
|
371
|
+
* @param {Object} newOptions Options to override.
|
|
372
|
+
* @return {MapboxStyleLayer} A MapboxStyleLayer.
|
|
373
|
+
*/
|
|
374
|
+
clone(newOptions) {
|
|
375
|
+
return new MapboxStyleLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
181
376
|
}
|
|
182
|
-
}
|
|
183
|
-
clone(newOptions) {
|
|
184
|
-
return new MapboxStyleLayer({ ...this.options, ...newOptions });
|
|
185
|
-
}
|
|
186
377
|
}
|
|
187
378
|
export default MapboxStyleLayer;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Map } from 'maplibre-gl';
|
|
2
|
+
import MapGlLayer, { MapGlLayerOptions } from './MapGlLayer';
|
|
3
|
+
/**
|
|
4
|
+
* A class representing MaplibreLayer to display on BasicMap
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* import { MaplibreLayer } from 'mobility-toolbox-js/ol';
|
|
8
|
+
*
|
|
9
|
+
* const layer = new MaplibreLayer({
|
|
10
|
+
* url: 'https://maps.geops.io/styles/travic_v2/style.json',
|
|
11
|
+
* apikey: 'yourApiKey',
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
15
|
+
* @extends {Layer}
|
|
16
|
+
*/
|
|
17
|
+
export default class MaplibreLayer extends MapGlLayer {
|
|
18
|
+
mbMap?: maplibregl.Map;
|
|
19
|
+
getOlLayerRender(): import("ol/layer/Layer").RenderFunction;
|
|
20
|
+
getMapboxMapClass(): typeof Map;
|
|
21
|
+
/**
|
|
22
|
+
* Create a copy of the MapboxLayer.
|
|
23
|
+
* @param {Object} newOptions Options to override
|
|
24
|
+
* @return {MapboxLayer} A MapboxLayer
|
|
25
|
+
*/
|
|
26
|
+
clone(newOptions: MapGlLayerOptions): MaplibreLayer;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=MaplibreLayer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MaplibreLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MaplibreLayer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAElC,OAAO,UAAU,EAAE,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAE7D;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,UAAU;IACnD,KAAK,CAAC,EAAE,UAAU,CAAC,GAAG,CAAC;IAEvB,gBAAgB;IAKhB,iBAAiB;IAIjB;;;;OAIG;IACH,KAAK,CAAC,UAAU,EAAE,iBAAiB;CAGpC"}
|