mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/api/RealtimeAPI.d.ts +6 -6
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +170 -197
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.js +8 -38
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.d.ts +1 -1
- package/api/StopsAPI.d.ts.map +1 -1
- package/api/StopsAPI.js +8 -40
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/api/index.d.ts +3 -4
- package/api/index.d.ts.map +1 -1
- package/api/index.js +3 -10
- package/api/typedefs.js +1 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +21 -48
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +8 -4
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +125 -129
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.d.ts +5 -5
- package/common/controls/Control.d.ts.map +1 -1
- package/common/controls/Control.js +44 -77
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/index.js +2 -18
- package/common/layers/Layer.d.ts +11 -11
- package/common/layers/Layer.d.ts.map +1 -1
- package/common/layers/Layer.js +70 -104
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/CopyrightMixin.js +23 -52
- package/common/mixins/MapboxLayerMixin.js +162 -204
- package/common/mixins/RealtimeLayerMixin.js +580 -635
- package/common/mixins/StopFinderMixin.d.ts +3 -3
- package/common/mixins/StopFinderMixin.d.ts.map +1 -1
- package/common/mixins/StopFinderMixin.js +115 -157
- package/common/mixins/UserInteractionsLayerMixin.js +142 -175
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/index.js +4 -24
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +67 -78
- package/common/styles/realtimeDelayStyle.js +4 -17
- package/common/styles/realtimeSimpleStyle.js +5 -7
- package/common/typedefs.js +1 -0
- package/common/utils/cleanStopTime.js +3 -5
- package/common/utils/compareDepartures.d.ts +1 -1
- package/common/utils/compareDepartures.d.ts.map +1 -1
- package/common/utils/compareDepartures.js +8 -11
- package/common/utils/createCanvas.js +3 -5
- package/common/utils/createTrackerFilters.d.ts +1 -1
- package/common/utils/createTrackerFilters.d.ts.map +1 -1
- package/common/utils/createTrackerFilters.js +22 -32
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getLayersAsFlatArray.js +6 -8
- package/common/utils/getMapboxMapCopyrights.js +9 -11
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/getMapboxRender.js +12 -15
- package/common/utils/getMaplibreRender.js +10 -13
- package/common/utils/getRealtimeModeSuffix.js +2 -6
- package/common/utils/getUrlWithParams.js +5 -8
- package/common/utils/getVehiclePosition.js +20 -23
- package/common/utils/index.js +12 -37
- package/common/utils/removeDuplicate.d.ts +1 -1
- package/common/utils/removeDuplicate.d.ts.map +1 -1
- package/common/utils/removeDuplicate.js +6 -21
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/renderTrajectories.js +31 -43
- package/common/utils/sortByDelay.js +4 -6
- package/common/utils/timeUtils.js +14 -24
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.js +27 -39
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/iife.js +3 -5
- package/index.d.ts +4 -0
- package/index.js +9 -10
- package/mapbox/controls/CopyrightControl.d.ts +0 -1
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
- package/mapbox/controls/CopyrightControl.js +18 -38
- package/mapbox/controls/index.js +1 -5
- package/mapbox/index.js +4 -20
- package/mapbox/layers/Layer.d.ts +1 -1
- package/mapbox/layers/Layer.d.ts.map +1 -1
- package/mapbox/layers/Layer.js +29 -71
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.d.ts +4 -4
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mapbox/layers/RealtimeLayer.js +83 -125
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +2 -7
- package/mapbox/utils.js +19 -33
- package/mbt.js +59 -37
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +26 -47
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +6 -5
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.js +209 -270
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.js +9 -32
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/controls/index.js +3 -9
- package/ol/index.js +5 -21
- package/ol/layers/Layer.d.ts +1 -1
- package/ol/layers/Layer.d.ts.map +1 -1
- package/ol/layers/Layer.js +40 -72
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts +7 -7
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +30 -66
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.d.ts +3 -3
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
- package/ol/layers/MapboxStyleLayer.js +92 -135
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/MaplibreLayer.d.ts +1 -1
- package/ol/layers/MaplibreLayer.d.ts.map +1 -1
- package/ol/layers/MaplibreLayer.js +14 -48
- package/ol/layers/RealtimeLayer.d.ts +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +111 -147
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.d.ts +2 -2
- package/ol/layers/RoutingLayer.d.ts.map +1 -1
- package/ol/layers/RoutingLayer.js +29 -61
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.d.ts +1 -1
- package/ol/layers/VectorLayer.d.ts.map +1 -1
- package/ol/layers/VectorLayer.js +14 -48
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.d.ts +1 -1
- package/ol/layers/WMSLayer.d.ts.map +1 -1
- package/ol/layers/WMSLayer.js +34 -68
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/ol/layers/index.js +8 -19
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
- package/ol/styles/fullTrajectoryStyle.js +16 -18
- package/ol/styles/index.js +2 -7
- package/package.json +5 -2
- package/setupTests.js +12 -14
|
@@ -1,33 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
1
|
/* eslint-disable no-param-reassign */
|
|
30
|
-
|
|
2
|
+
import Layer from './Layer';
|
|
31
3
|
/**
|
|
32
4
|
* Layer for visualizing a specific set of layer from a MapboxLayer.
|
|
33
5
|
*
|
|
@@ -46,8 +18,7 @@ var Layer_1 = require("./Layer");
|
|
|
46
18
|
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
47
19
|
* @extends {Layer}
|
|
48
20
|
*/
|
|
49
|
-
|
|
50
|
-
__extends(MapboxStyleLayer, _super);
|
|
21
|
+
class MapboxStyleLayer extends Layer {
|
|
51
22
|
/**
|
|
52
23
|
* Constructor.
|
|
53
24
|
*
|
|
@@ -55,106 +26,103 @@ var MapboxStyleLayer = /** @class */ (function (_super) {
|
|
|
55
26
|
* @param {MapboxLayer} [options.mapboxLayer] The MapboxLayer to use.
|
|
56
27
|
* @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
|
|
57
28
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
var _this = _super.call(this, options) || this;
|
|
29
|
+
constructor(options = {}) {
|
|
30
|
+
super(options);
|
|
61
31
|
/**
|
|
62
32
|
* MapboxLayer provided for the style Layer.
|
|
63
33
|
* @type {MapboxLayer}
|
|
64
34
|
* @private
|
|
65
35
|
*/
|
|
66
|
-
|
|
36
|
+
this.mapboxLayer = options.mapboxLayer;
|
|
67
37
|
/**
|
|
68
38
|
* Define if the layer has data to display in the current mapbox layer.
|
|
69
39
|
*/
|
|
70
|
-
|
|
40
|
+
this.disabled = false;
|
|
71
41
|
/**
|
|
72
42
|
* Function to filter features to be displayed.
|
|
73
43
|
* @type {function}
|
|
74
44
|
* @private
|
|
75
45
|
*/
|
|
76
|
-
|
|
46
|
+
this.styleLayersFilter = options.styleLayersFilter;
|
|
77
47
|
/**
|
|
78
48
|
* Mapbox style layer id where to add the style layers.
|
|
79
49
|
* See [mapbox.map.addLayer](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#addlayer) documentation.
|
|
80
50
|
* @type {String}
|
|
81
51
|
* @private
|
|
82
52
|
*/
|
|
83
|
-
|
|
53
|
+
this.beforeId = options.beforeId;
|
|
84
54
|
/**
|
|
85
55
|
* Function to filter features for getFeatureInfoAtCoordinate method.
|
|
86
56
|
* @type {function}
|
|
87
57
|
* @private
|
|
88
58
|
*/
|
|
89
|
-
|
|
59
|
+
this.featureInfoFilter = options.featureInfoFilter || ((obj) => obj);
|
|
90
60
|
/**
|
|
91
61
|
* Function to query the rendered features.
|
|
92
62
|
* @type {function}
|
|
93
63
|
* @private
|
|
94
64
|
*/
|
|
95
|
-
|
|
65
|
+
this.queryRenderedLayersFilter = options.queryRenderedLayersFilter;
|
|
96
66
|
/**
|
|
97
67
|
* Array of features to highlight.
|
|
98
68
|
* @type {Array<ol/Feature~Feature>}
|
|
99
69
|
* @private
|
|
100
70
|
*/
|
|
101
|
-
|
|
71
|
+
this.highlightedFeatures = [];
|
|
102
72
|
/**
|
|
103
73
|
* Array of selected features.
|
|
104
74
|
* @type {Array<ol/Feature~Feature>}
|
|
105
75
|
* @private
|
|
106
76
|
*/
|
|
107
|
-
|
|
77
|
+
this.selectedFeatures = [];
|
|
108
78
|
/**
|
|
109
79
|
* Array of mapbox style layers to add.
|
|
110
80
|
* @type {Array<mapboxgl.styleLayer>}
|
|
111
81
|
* @private
|
|
112
82
|
*/
|
|
113
|
-
|
|
83
|
+
this.styleLayers =
|
|
114
84
|
(options.styleLayer ? [options.styleLayer] : options.styleLayers) || [];
|
|
115
85
|
/**
|
|
116
86
|
* @private
|
|
117
87
|
*/
|
|
118
|
-
|
|
88
|
+
this.addStyleLayers = this.addStyleLayers.bind(this);
|
|
119
89
|
/**
|
|
120
90
|
* @private
|
|
121
91
|
*/
|
|
122
|
-
|
|
92
|
+
this.onLoad = this.onLoad.bind(this);
|
|
123
93
|
if (options.filters) {
|
|
124
94
|
/** @private */
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
? options.filters(
|
|
95
|
+
this.addDynamicFilters = () => {
|
|
96
|
+
this.setFilter(typeof options.filters === 'function'
|
|
97
|
+
? options.filters(this)
|
|
128
98
|
: options.filters);
|
|
129
99
|
};
|
|
130
100
|
}
|
|
131
|
-
if (!
|
|
132
|
-
|
|
133
|
-
|
|
101
|
+
if (!this.styleLayersFilter && this.styleLayers) {
|
|
102
|
+
const ids = this.styleLayers.map((s) => s.id);
|
|
103
|
+
this.styleLayersFilter = (styleLayer) => ids.includes(styleLayer.id);
|
|
134
104
|
}
|
|
135
|
-
return _this;
|
|
136
105
|
}
|
|
137
106
|
/**
|
|
138
107
|
* Initialize the layer.
|
|
139
108
|
* @param {mapboxgl.Map} map the mapbox map.
|
|
140
109
|
* @override
|
|
141
110
|
*/
|
|
142
|
-
|
|
143
|
-
var _this = this;
|
|
111
|
+
attachToMap(map) {
|
|
144
112
|
if (!this.mapboxLayer.map) {
|
|
145
113
|
this.mapboxLayer.attachToMap(map);
|
|
146
114
|
}
|
|
147
|
-
|
|
115
|
+
super.attachToMap(map);
|
|
148
116
|
if (!this.map) {
|
|
149
117
|
return;
|
|
150
118
|
}
|
|
151
119
|
// Apply the initial visibiltity.
|
|
152
|
-
|
|
120
|
+
const { mbMap } = this.mapboxLayer;
|
|
153
121
|
if (!mbMap) {
|
|
154
122
|
// If the mbMap is not yet created because the map has no target yet, we
|
|
155
123
|
// relaunch the initialisation when it's the case.
|
|
156
|
-
this.olListenersKeys.push(this.map.on('change:target',
|
|
157
|
-
|
|
124
|
+
this.olListenersKeys.push(this.map.on('change:target', () => {
|
|
125
|
+
this.attachToMap(map);
|
|
158
126
|
}));
|
|
159
127
|
return;
|
|
160
128
|
}
|
|
@@ -169,85 +137,83 @@ var MapboxStyleLayer = /** @class */ (function (_super) {
|
|
|
169
137
|
mbMap.once('load', this.onLoad);
|
|
170
138
|
}
|
|
171
139
|
// Apply the visibiltity when layer's visibility change.
|
|
172
|
-
this.olListenersKeys.push(this.on('change:visible',
|
|
140
|
+
this.olListenersKeys.push(this.on('change:visible', (evt) => {
|
|
173
141
|
// Once the map is loaded we can apply vsiiblity without waiting
|
|
174
142
|
// the style. Mapbox take care of the application of style changes.
|
|
175
|
-
|
|
143
|
+
this.applyLayoutVisibility(evt);
|
|
176
144
|
}));
|
|
177
|
-
this.olListenersKeys.push(this.mapboxLayer.on('load',
|
|
178
|
-
|
|
145
|
+
this.olListenersKeys.push(this.mapboxLayer.on('load', () => {
|
|
146
|
+
this.onLoad();
|
|
179
147
|
}));
|
|
180
|
-
}
|
|
148
|
+
}
|
|
181
149
|
/**
|
|
182
150
|
* Terminate the layer.
|
|
183
151
|
* @param {mapboxgl.Map} map the mapbox map.
|
|
184
152
|
* @override
|
|
185
153
|
*/
|
|
186
|
-
|
|
187
|
-
|
|
154
|
+
detachFromMap(map) {
|
|
155
|
+
const { mbMap } = this.mapboxLayer;
|
|
188
156
|
if (mbMap) {
|
|
189
157
|
mbMap.off('load', this.onLoad);
|
|
190
158
|
this.removeStyleLayers();
|
|
191
159
|
}
|
|
192
|
-
|
|
193
|
-
}
|
|
160
|
+
super.detachFromMap(map);
|
|
161
|
+
}
|
|
194
162
|
/** @ignore */
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
var mbMap = this.mapboxLayer.mbMap;
|
|
163
|
+
addStyleLayers() {
|
|
164
|
+
const { mbMap } = this.mapboxLayer;
|
|
198
165
|
if (!mbMap) {
|
|
199
166
|
return;
|
|
200
167
|
}
|
|
201
|
-
this.styleLayers.forEach(
|
|
202
|
-
|
|
168
|
+
this.styleLayers.forEach((styleLayer) => {
|
|
169
|
+
const { id, source } = styleLayer;
|
|
203
170
|
if (mbMap.getSource(source) && !mbMap.getLayer(id)) {
|
|
204
|
-
mbMap.addLayer(styleLayer,
|
|
171
|
+
mbMap.addLayer(styleLayer, this.beforeId);
|
|
205
172
|
}
|
|
206
173
|
});
|
|
207
174
|
this.applyLayoutVisibility();
|
|
208
|
-
}
|
|
175
|
+
}
|
|
209
176
|
/** @ignore */
|
|
210
|
-
|
|
211
|
-
|
|
177
|
+
removeStyleLayers() {
|
|
178
|
+
const { mbMap } = this.mapboxLayer;
|
|
212
179
|
if (!mbMap) {
|
|
213
180
|
return;
|
|
214
181
|
}
|
|
215
|
-
this.styleLayers.forEach(
|
|
182
|
+
this.styleLayers.forEach((styleLayer) => {
|
|
216
183
|
if (mbMap.getLayer(styleLayer.id)) {
|
|
217
184
|
mbMap.removeLayer(styleLayer.id);
|
|
218
185
|
}
|
|
219
186
|
});
|
|
220
|
-
}
|
|
187
|
+
}
|
|
221
188
|
/**
|
|
222
189
|
* On Mapbox map load callback function. Add style layers and dynaimc filters.
|
|
223
190
|
* @ignore
|
|
224
191
|
*/
|
|
225
|
-
|
|
192
|
+
onLoad() {
|
|
226
193
|
this.addStyleLayers();
|
|
227
194
|
if (this.addDynamicFilters) {
|
|
228
195
|
this.addDynamicFilters();
|
|
229
196
|
}
|
|
230
|
-
|
|
231
|
-
|
|
197
|
+
const { mbMap } = this.mapboxLayer;
|
|
198
|
+
const style = mbMap.getStyle();
|
|
232
199
|
if (style && this.styleLayersFilter) {
|
|
233
|
-
|
|
200
|
+
const styles = style.layers.filter(this.styleLayersFilter);
|
|
234
201
|
this.disabled = !styles.length;
|
|
235
202
|
}
|
|
236
|
-
}
|
|
203
|
+
}
|
|
237
204
|
/**
|
|
238
205
|
* Request feature information for a given coordinate.
|
|
239
206
|
* @param {ol/coordinate~Coordinate} coordinate Coordinate to request the information at.
|
|
240
207
|
* @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
|
|
241
208
|
*/
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
var mbMap = this.mapboxLayer.mbMap;
|
|
209
|
+
getFeatureInfoAtCoordinate(coordinate) {
|
|
210
|
+
const { mbMap } = this.mapboxLayer;
|
|
245
211
|
// Ignore the getFeatureInfo until the mapbox map is loaded
|
|
246
212
|
if (!mbMap || !mbMap.isStyleLoaded()) {
|
|
247
|
-
return Promise.resolve({ coordinate
|
|
213
|
+
return Promise.resolve({ coordinate, features: [], layer: this });
|
|
248
214
|
}
|
|
249
215
|
// We query features only on style layers used by this layer.
|
|
250
|
-
|
|
216
|
+
let layers = this.styleLayers || [];
|
|
251
217
|
if (this.styleLayersFilter) {
|
|
252
218
|
layers = mbMap.getStyle().layers.filter(this.styleLayersFilter);
|
|
253
219
|
}
|
|
@@ -256,46 +222,43 @@ var MapboxStyleLayer = /** @class */ (function (_super) {
|
|
|
256
222
|
}
|
|
257
223
|
return this.mapboxLayer
|
|
258
224
|
.getFeatureInfoAtCoordinate(coordinate, {
|
|
259
|
-
layers: layers.map(
|
|
225
|
+
layers: layers.map((layer) => layer && layer.id),
|
|
260
226
|
validate: false,
|
|
261
227
|
})
|
|
262
|
-
.then(
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
});
|
|
266
|
-
_this.highlight(features);
|
|
267
|
-
return __assign(__assign({}, featureInfo), { features: features, layer: _this });
|
|
228
|
+
.then((featureInfo) => {
|
|
229
|
+
const features = featureInfo.features.filter((feature) => this.featureInfoFilter(feature, this.map.getView().getResolution()));
|
|
230
|
+
this.highlight(features);
|
|
231
|
+
return Object.assign(Object.assign({}, featureInfo), { features, layer: this });
|
|
268
232
|
});
|
|
269
|
-
}
|
|
233
|
+
}
|
|
270
234
|
/**
|
|
271
235
|
* Set filter that determines which features should be rendered in a style layer.
|
|
272
236
|
* @param {mapboxgl.filter} filter Determines which features should be rendered in a style layer.
|
|
273
237
|
*/
|
|
274
|
-
|
|
275
|
-
|
|
238
|
+
setFilter(filter) {
|
|
239
|
+
const { mbMap } = this.mapboxLayer;
|
|
276
240
|
if (!mbMap) {
|
|
277
241
|
return;
|
|
278
242
|
}
|
|
279
|
-
this.styleLayers.forEach(
|
|
280
|
-
var id = _a.id;
|
|
243
|
+
this.styleLayers.forEach(({ id }) => {
|
|
281
244
|
if (mbMap.getLayer(id)) {
|
|
282
245
|
mbMap.setFilter(id, filter);
|
|
283
246
|
}
|
|
284
247
|
});
|
|
285
|
-
}
|
|
248
|
+
}
|
|
286
249
|
/**
|
|
287
250
|
* Set if features are hovered or not.
|
|
288
251
|
* @param {Array<ol/Feature~Feature>} features
|
|
289
252
|
* @param {boolean} state Is the feature hovered
|
|
290
253
|
* @private
|
|
291
254
|
*/
|
|
292
|
-
|
|
293
|
-
|
|
255
|
+
setHoverState(features, state) {
|
|
256
|
+
const { mbMap } = this.mapboxLayer;
|
|
294
257
|
if (!features || !mbMap) {
|
|
295
258
|
return;
|
|
296
259
|
}
|
|
297
|
-
features.forEach(
|
|
298
|
-
|
|
260
|
+
features.forEach((feature) => {
|
|
261
|
+
const { source, sourceLayer } = feature.get('mapboxFeature') || {};
|
|
299
262
|
if ((!source && !sourceLayer) || !feature.getId()) {
|
|
300
263
|
if (!feature.getId()) {
|
|
301
264
|
// eslint-disable-next-line no-console
|
|
@@ -305,63 +268,58 @@ var MapboxStyleLayer = /** @class */ (function (_super) {
|
|
|
305
268
|
}
|
|
306
269
|
mbMap.setFeatureState({
|
|
307
270
|
id: feature.getId(),
|
|
308
|
-
source
|
|
309
|
-
sourceLayer
|
|
271
|
+
source,
|
|
272
|
+
sourceLayer,
|
|
310
273
|
}, { hover: state });
|
|
311
274
|
});
|
|
312
|
-
}
|
|
275
|
+
}
|
|
313
276
|
/**
|
|
314
277
|
* Select a list of features.
|
|
315
278
|
* @param {Array<ol/Feature~Feature>} [features=[]] Features to select.
|
|
316
279
|
* @private
|
|
317
280
|
*/
|
|
318
|
-
|
|
319
|
-
if (features === void 0) { features = []; }
|
|
281
|
+
select(features = []) {
|
|
320
282
|
this.setHoverState(this.selectedFeatures, false);
|
|
321
283
|
this.selectedFeatures = features;
|
|
322
284
|
this.setHoverState(this.selectedFeatures, true);
|
|
323
|
-
}
|
|
285
|
+
}
|
|
324
286
|
/**
|
|
325
287
|
* Highlight a list of features.
|
|
326
288
|
* @param {Array<ol/Feature~Feature>} [features=[]] Features to highlight.
|
|
327
289
|
* @private
|
|
328
290
|
*/
|
|
329
|
-
|
|
330
|
-
var _this = this;
|
|
331
|
-
if (features === void 0) { features = []; }
|
|
291
|
+
highlight(features = []) {
|
|
332
292
|
// Filter out selected features
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
.includes(feature.getId());
|
|
337
|
-
});
|
|
293
|
+
const filtered = this.highlightedFeatures.filter((feature) => !this.selectedFeatures
|
|
294
|
+
.map((feat) => feat.getId())
|
|
295
|
+
.includes(feature.getId()));
|
|
338
296
|
// Remove previous highlight
|
|
339
297
|
this.setHoverState(filtered, false);
|
|
340
298
|
this.highlightedFeatures = features;
|
|
341
299
|
// Add highlight
|
|
342
300
|
this.setHoverState(this.highlightedFeatures, true);
|
|
343
|
-
}
|
|
301
|
+
}
|
|
344
302
|
/**
|
|
345
303
|
* Apply visibility to style layers that fits the styleLayersFilter function.
|
|
346
304
|
* @param {Event} evt Layer's event that has called the function.
|
|
347
305
|
* @private
|
|
348
306
|
*/
|
|
349
307
|
// eslint-disable-next-line no-unused-vars
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
308
|
+
applyLayoutVisibility(evt) {
|
|
309
|
+
const { visible } = this;
|
|
310
|
+
const { mbMap } = this.mapboxLayer;
|
|
311
|
+
const filterFunc = this.styleLayersFilter;
|
|
354
312
|
if (!mbMap) {
|
|
355
313
|
return;
|
|
356
314
|
}
|
|
357
|
-
|
|
315
|
+
const style = mbMap.getStyle();
|
|
358
316
|
if (!style) {
|
|
359
317
|
return;
|
|
360
318
|
}
|
|
361
319
|
if (filterFunc) {
|
|
362
|
-
|
|
363
|
-
for (
|
|
364
|
-
|
|
320
|
+
const visibilityValue = visible ? 'visible' : 'none';
|
|
321
|
+
for (let i = 0; i < style.layers.length; i += 1) {
|
|
322
|
+
const styleLayer = style.layers[i];
|
|
365
323
|
if (filterFunc(styleLayer)) {
|
|
366
324
|
if (mbMap.getLayer(styleLayer.id)) {
|
|
367
325
|
mbMap.setLayoutProperty(styleLayer.id, 'visibility', visibilityValue);
|
|
@@ -369,15 +327,14 @@ var MapboxStyleLayer = /** @class */ (function (_super) {
|
|
|
369
327
|
}
|
|
370
328
|
}
|
|
371
329
|
}
|
|
372
|
-
}
|
|
330
|
+
}
|
|
373
331
|
/**
|
|
374
332
|
* Create a copy of the MapboxStyleLayer.
|
|
375
333
|
* @param {Object} newOptions Options to override.
|
|
376
334
|
* @return {MapboxStyleLayer} A MapboxStyleLayer.
|
|
377
335
|
*/
|
|
378
|
-
|
|
379
|
-
return new MapboxStyleLayer(
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
exports.default = MapboxStyleLayer;
|
|
336
|
+
clone(newOptions) {
|
|
337
|
+
return new MapboxStyleLayer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
export default MapboxStyleLayer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapboxStyleLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxStyleLayer.test.js"],"names":[],"mappings":""}
|