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.
Files changed (195) hide show
  1. package/README.md +14 -8
  2. package/api/RealtimeAPI.d.ts +6 -6
  3. package/api/RealtimeAPI.d.ts.map +1 -1
  4. package/api/RealtimeAPI.js +170 -197
  5. package/api/RealtimeAPI.test.d.ts +2 -0
  6. package/api/RealtimeAPI.test.d.ts.map +1 -0
  7. package/api/RealtimeAPI.test.js +67 -0
  8. package/api/RoutingAPI.d.ts +6 -2
  9. package/api/RoutingAPI.d.ts.map +1 -1
  10. package/api/RoutingAPI.js +8 -38
  11. package/api/RoutingAPI.test.d.ts +2 -0
  12. package/api/RoutingAPI.test.d.ts.map +1 -0
  13. package/api/RoutingAPI.test.js +29 -0
  14. package/api/StopsAPI.d.ts +1 -1
  15. package/api/StopsAPI.d.ts.map +1 -1
  16. package/api/StopsAPI.js +8 -40
  17. package/api/StopsAPI.test.d.ts +2 -0
  18. package/api/StopsAPI.test.d.ts.map +1 -0
  19. package/api/StopsAPI.test.js +26 -0
  20. package/api/index.d.ts +3 -4
  21. package/api/index.d.ts.map +1 -1
  22. package/api/index.js +3 -10
  23. package/api/typedefs.js +1 -0
  24. package/common/api/HttpAPI.d.ts +2 -2
  25. package/common/api/HttpAPI.d.ts.map +1 -1
  26. package/common/api/HttpAPI.js +21 -48
  27. package/common/api/HttpAPI.test.d.ts +2 -0
  28. package/common/api/HttpAPI.test.d.ts.map +1 -0
  29. package/common/api/HttpAPI.test.js +54 -0
  30. package/common/api/WebSocketAPI.d.ts +8 -4
  31. package/common/api/WebSocketAPI.d.ts.map +1 -1
  32. package/common/api/WebSocketAPI.js +125 -129
  33. package/common/api/WebSocketAPI.test.d.ts +2 -0
  34. package/common/api/WebSocketAPI.test.d.ts.map +1 -0
  35. package/common/api/WebSocketAPI.test.js +380 -0
  36. package/common/controls/Control.d.ts +5 -5
  37. package/common/controls/Control.d.ts.map +1 -1
  38. package/common/controls/Control.js +44 -77
  39. package/common/controls/Control.test.d.ts +2 -0
  40. package/common/controls/Control.test.d.ts.map +1 -0
  41. package/common/controls/Control.test.js +89 -0
  42. package/common/index.js +2 -18
  43. package/common/layers/Layer.d.ts +11 -11
  44. package/common/layers/Layer.d.ts.map +1 -1
  45. package/common/layers/Layer.js +70 -104
  46. package/common/layers/Layer.test.d.ts +2 -0
  47. package/common/layers/Layer.test.d.ts.map +1 -0
  48. package/common/layers/Layer.test.js +137 -0
  49. package/common/mixins/CopyrightMixin.js +23 -52
  50. package/common/mixins/MapboxLayerMixin.js +162 -204
  51. package/common/mixins/RealtimeLayerMixin.js +580 -635
  52. package/common/mixins/StopFinderMixin.d.ts +3 -3
  53. package/common/mixins/StopFinderMixin.d.ts.map +1 -1
  54. package/common/mixins/StopFinderMixin.js +115 -157
  55. package/common/mixins/UserInteractionsLayerMixin.js +142 -175
  56. package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
  57. package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
  58. package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
  59. package/common/styles/index.js +4 -24
  60. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
  61. package/common/styles/realtimeDefaultStyle.js +67 -78
  62. package/common/styles/realtimeDelayStyle.js +4 -17
  63. package/common/styles/realtimeSimpleStyle.js +5 -7
  64. package/common/typedefs.js +1 -0
  65. package/common/utils/cleanStopTime.js +3 -5
  66. package/common/utils/compareDepartures.d.ts +1 -1
  67. package/common/utils/compareDepartures.d.ts.map +1 -1
  68. package/common/utils/compareDepartures.js +8 -11
  69. package/common/utils/createCanvas.js +3 -5
  70. package/common/utils/createTrackerFilters.d.ts +1 -1
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -1
  72. package/common/utils/createTrackerFilters.js +22 -32
  73. package/common/utils/createTrackerFilters.test.d.ts +2 -0
  74. package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
  75. package/common/utils/createTrackerFilters.test.js +79 -0
  76. package/common/utils/getLayersAsFlatArray.js +6 -8
  77. package/common/utils/getMapboxMapCopyrights.js +9 -11
  78. package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
  79. package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
  80. package/common/utils/getMapboxMapCopyrights.test.js +40 -0
  81. package/common/utils/getMapboxRender.js +12 -15
  82. package/common/utils/getMaplibreRender.js +10 -13
  83. package/common/utils/getRealtimeModeSuffix.js +2 -6
  84. package/common/utils/getUrlWithParams.js +5 -8
  85. package/common/utils/getVehiclePosition.js +20 -23
  86. package/common/utils/index.js +12 -37
  87. package/common/utils/removeDuplicate.d.ts +1 -1
  88. package/common/utils/removeDuplicate.d.ts.map +1 -1
  89. package/common/utils/removeDuplicate.js +6 -21
  90. package/common/utils/removeDuplicate.test.d.ts +2 -0
  91. package/common/utils/removeDuplicate.test.d.ts.map +1 -0
  92. package/common/utils/removeDuplicate.test.js +19 -0
  93. package/common/utils/renderTrajectories.js +31 -43
  94. package/common/utils/sortByDelay.js +4 -6
  95. package/common/utils/timeUtils.js +14 -24
  96. package/common/utils/timeUtils.test.d.ts +2 -0
  97. package/common/utils/timeUtils.test.d.ts.map +1 -0
  98. package/common/utils/timeUtils.test.js +10 -0
  99. package/common/utils/trackerConfig.js +27 -39
  100. package/common/utils/trackerConfig.test.d.ts +2 -0
  101. package/common/utils/trackerConfig.test.d.ts.map +1 -0
  102. package/common/utils/trackerConfig.test.js +23 -0
  103. package/iife.js +3 -5
  104. package/index.d.ts +4 -0
  105. package/index.js +9 -10
  106. package/mapbox/controls/CopyrightControl.d.ts +0 -1
  107. package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
  108. package/mapbox/controls/CopyrightControl.js +18 -38
  109. package/mapbox/controls/index.js +1 -5
  110. package/mapbox/index.js +4 -20
  111. package/mapbox/layers/Layer.d.ts +1 -1
  112. package/mapbox/layers/Layer.d.ts.map +1 -1
  113. package/mapbox/layers/Layer.js +29 -71
  114. package/mapbox/layers/Layer.test.d.ts +2 -0
  115. package/mapbox/layers/Layer.test.d.ts.map +1 -0
  116. package/mapbox/layers/Layer.test.js +204 -0
  117. package/mapbox/layers/RealtimeLayer.d.ts +4 -4
  118. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
  119. package/mapbox/layers/RealtimeLayer.js +83 -125
  120. package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
  121. package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
  122. package/mapbox/layers/RealtimeLayer.test.js +10 -0
  123. package/mapbox/layers/index.js +2 -7
  124. package/mapbox/utils.js +19 -33
  125. package/mbt.js +59 -37
  126. package/mbt.js.map +2 -2
  127. package/mbt.min.js +10 -10
  128. package/mbt.min.js.map +2 -2
  129. package/ol/controls/CopyrightControl.js +26 -47
  130. package/ol/controls/CopyrightControl.test.d.ts +2 -0
  131. package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
  132. package/ol/controls/CopyrightControl.test.js +177 -0
  133. package/ol/controls/RoutingControl.d.ts +6 -5
  134. package/ol/controls/RoutingControl.d.ts.map +1 -1
  135. package/ol/controls/RoutingControl.js +209 -270
  136. package/ol/controls/RoutingControl.test.d.ts +2 -0
  137. package/ol/controls/RoutingControl.test.d.ts.map +1 -0
  138. package/ol/controls/RoutingControl.test.js +150 -0
  139. package/ol/controls/StopFinderControl.js +9 -32
  140. package/ol/controls/StopFinderControl.test.d.ts +2 -0
  141. package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
  142. package/ol/controls/StopFinderControl.test.js +49 -0
  143. package/ol/controls/index.js +3 -9
  144. package/ol/index.js +5 -21
  145. package/ol/layers/Layer.d.ts +1 -1
  146. package/ol/layers/Layer.d.ts.map +1 -1
  147. package/ol/layers/Layer.js +40 -72
  148. package/ol/layers/Layer.test.d.ts +2 -0
  149. package/ol/layers/Layer.test.d.ts.map +1 -0
  150. package/ol/layers/Layer.test.js +196 -0
  151. package/ol/layers/MapboxLayer.d.ts +7 -7
  152. package/ol/layers/MapboxLayer.d.ts.map +1 -1
  153. package/ol/layers/MapboxLayer.js +30 -66
  154. package/ol/layers/MapboxLayer.test.d.ts +2 -0
  155. package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
  156. package/ol/layers/MapboxLayer.test.js +164 -0
  157. package/ol/layers/MapboxStyleLayer.d.ts +3 -3
  158. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
  159. package/ol/layers/MapboxStyleLayer.js +92 -135
  160. package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
  161. package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
  162. package/ol/layers/MapboxStyleLayer.test.js +232 -0
  163. package/ol/layers/MaplibreLayer.d.ts +1 -1
  164. package/ol/layers/MaplibreLayer.d.ts.map +1 -1
  165. package/ol/layers/MaplibreLayer.js +14 -48
  166. package/ol/layers/RealtimeLayer.d.ts +2 -2
  167. package/ol/layers/RealtimeLayer.d.ts.map +1 -1
  168. package/ol/layers/RealtimeLayer.js +111 -147
  169. package/ol/layers/RealtimeLayer.test.d.ts +2 -0
  170. package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
  171. package/ol/layers/RealtimeLayer.test.js +71 -0
  172. package/ol/layers/RoutingLayer.d.ts +2 -2
  173. package/ol/layers/RoutingLayer.d.ts.map +1 -1
  174. package/ol/layers/RoutingLayer.js +29 -61
  175. package/ol/layers/RoutingLayer.test.d.ts +2 -0
  176. package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
  177. package/ol/layers/RoutingLayer.test.js +39 -0
  178. package/ol/layers/VectorLayer.d.ts +1 -1
  179. package/ol/layers/VectorLayer.d.ts.map +1 -1
  180. package/ol/layers/VectorLayer.js +14 -48
  181. package/ol/layers/VectorLayer.test.d.ts +2 -0
  182. package/ol/layers/VectorLayer.test.d.ts.map +1 -0
  183. package/ol/layers/VectorLayer.test.js +87 -0
  184. package/ol/layers/WMSLayer.d.ts +1 -1
  185. package/ol/layers/WMSLayer.d.ts.map +1 -1
  186. package/ol/layers/WMSLayer.js +34 -68
  187. package/ol/layers/WMSLayer.test.d.ts +2 -0
  188. package/ol/layers/WMSLayer.test.d.ts.map +1 -0
  189. package/ol/layers/WMSLayer.test.js +66 -0
  190. package/ol/layers/index.js +8 -19
  191. package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
  192. package/ol/styles/fullTrajectoryStyle.js +16 -18
  193. package/ol/styles/index.js +2 -7
  194. package/package.json +5 -2
  195. 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
- var Layer_1 = require("./Layer");
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
- var MapboxStyleLayer = /** @class */ (function (_super) {
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
- function MapboxStyleLayer(options) {
59
- if (options === void 0) { options = {}; }
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
- _this.mapboxLayer = options.mapboxLayer;
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
- _this.disabled = false;
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
- _this.styleLayersFilter = options.styleLayersFilter;
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
- _this.beforeId = options.beforeId;
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
- _this.featureInfoFilter = options.featureInfoFilter || (function (obj) { return obj; });
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
- _this.queryRenderedLayersFilter = options.queryRenderedLayersFilter;
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
- _this.highlightedFeatures = [];
71
+ this.highlightedFeatures = [];
102
72
  /**
103
73
  * Array of selected features.
104
74
  * @type {Array<ol/Feature~Feature>}
105
75
  * @private
106
76
  */
107
- _this.selectedFeatures = [];
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
- _this.styleLayers =
83
+ this.styleLayers =
114
84
  (options.styleLayer ? [options.styleLayer] : options.styleLayers) || [];
115
85
  /**
116
86
  * @private
117
87
  */
118
- _this.addStyleLayers = _this.addStyleLayers.bind(_this);
88
+ this.addStyleLayers = this.addStyleLayers.bind(this);
119
89
  /**
120
90
  * @private
121
91
  */
122
- _this.onLoad = _this.onLoad.bind(_this);
92
+ this.onLoad = this.onLoad.bind(this);
123
93
  if (options.filters) {
124
94
  /** @private */
125
- _this.addDynamicFilters = function () {
126
- _this.setFilter(typeof options.filters === 'function'
127
- ? options.filters(_this)
95
+ this.addDynamicFilters = () => {
96
+ this.setFilter(typeof options.filters === 'function'
97
+ ? options.filters(this)
128
98
  : options.filters);
129
99
  };
130
100
  }
131
- if (!_this.styleLayersFilter && _this.styleLayers) {
132
- var ids_1 = _this.styleLayers.map(function (s) { return s.id; });
133
- _this.styleLayersFilter = function (styleLayer) { return ids_1.includes(styleLayer.id); };
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
- MapboxStyleLayer.prototype.attachToMap = function (map) {
143
- var _this = this;
111
+ attachToMap(map) {
144
112
  if (!this.mapboxLayer.map) {
145
113
  this.mapboxLayer.attachToMap(map);
146
114
  }
147
- _super.prototype.attachToMap.call(this, map);
115
+ super.attachToMap(map);
148
116
  if (!this.map) {
149
117
  return;
150
118
  }
151
119
  // Apply the initial visibiltity.
152
- var mbMap = this.mapboxLayer.mbMap;
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', function () {
157
- _this.attachToMap(map);
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', function (evt) {
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
- _this.applyLayoutVisibility(evt);
143
+ this.applyLayoutVisibility(evt);
176
144
  }));
177
- this.olListenersKeys.push(this.mapboxLayer.on('load', function () {
178
- _this.onLoad();
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
- MapboxStyleLayer.prototype.detachFromMap = function (map) {
187
- var mbMap = this.mapboxLayer.mbMap;
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
- _super.prototype.detachFromMap.call(this, map);
193
- };
160
+ super.detachFromMap(map);
161
+ }
194
162
  /** @ignore */
195
- MapboxStyleLayer.prototype.addStyleLayers = function () {
196
- var _this = this;
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(function (styleLayer) {
202
- var id = styleLayer.id, source = styleLayer.source;
168
+ this.styleLayers.forEach((styleLayer) => {
169
+ const { id, source } = styleLayer;
203
170
  if (mbMap.getSource(source) && !mbMap.getLayer(id)) {
204
- mbMap.addLayer(styleLayer, _this.beforeId);
171
+ mbMap.addLayer(styleLayer, this.beforeId);
205
172
  }
206
173
  });
207
174
  this.applyLayoutVisibility();
208
- };
175
+ }
209
176
  /** @ignore */
210
- MapboxStyleLayer.prototype.removeStyleLayers = function () {
211
- var mbMap = this.mapboxLayer.mbMap;
177
+ removeStyleLayers() {
178
+ const { mbMap } = this.mapboxLayer;
212
179
  if (!mbMap) {
213
180
  return;
214
181
  }
215
- this.styleLayers.forEach(function (styleLayer) {
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
- MapboxStyleLayer.prototype.onLoad = function () {
192
+ onLoad() {
226
193
  this.addStyleLayers();
227
194
  if (this.addDynamicFilters) {
228
195
  this.addDynamicFilters();
229
196
  }
230
- var mbMap = this.mapboxLayer.mbMap;
231
- var style = mbMap.getStyle();
197
+ const { mbMap } = this.mapboxLayer;
198
+ const style = mbMap.getStyle();
232
199
  if (style && this.styleLayersFilter) {
233
- var styles = style.layers.filter(this.styleLayersFilter);
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
- MapboxStyleLayer.prototype.getFeatureInfoAtCoordinate = function (coordinate) {
243
- var _this = this;
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: coordinate, features: [], layer: this });
213
+ return Promise.resolve({ coordinate, features: [], layer: this });
248
214
  }
249
215
  // We query features only on style layers used by this layer.
250
- var layers = this.styleLayers || [];
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(function (layer) { return layer && layer.id; }),
225
+ layers: layers.map((layer) => layer && layer.id),
260
226
  validate: false,
261
227
  })
262
- .then(function (featureInfo) {
263
- var features = featureInfo.features.filter(function (feature) {
264
- return _this.featureInfoFilter(feature, _this.map.getView().getResolution());
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
- MapboxStyleLayer.prototype.setFilter = function (filter) {
275
- var mbMap = this.mapboxLayer.mbMap;
238
+ setFilter(filter) {
239
+ const { mbMap } = this.mapboxLayer;
276
240
  if (!mbMap) {
277
241
  return;
278
242
  }
279
- this.styleLayers.forEach(function (_a) {
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
- MapboxStyleLayer.prototype.setHoverState = function (features, state) {
293
- var mbMap = this.mapboxLayer.mbMap;
255
+ setHoverState(features, state) {
256
+ const { mbMap } = this.mapboxLayer;
294
257
  if (!features || !mbMap) {
295
258
  return;
296
259
  }
297
- features.forEach(function (feature) {
298
- var _a = feature.get('mapboxFeature') || {}, source = _a.source, sourceLayer = _a.sourceLayer;
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: source,
309
- sourceLayer: 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
- MapboxStyleLayer.prototype.select = function (features) {
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
- MapboxStyleLayer.prototype.highlight = function (features) {
330
- var _this = this;
331
- if (features === void 0) { features = []; }
291
+ highlight(features = []) {
332
292
  // Filter out selected features
333
- var filtered = this.highlightedFeatures.filter(function (feature) {
334
- return !_this.selectedFeatures
335
- .map(function (feat) { return feat.getId(); })
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
- MapboxStyleLayer.prototype.applyLayoutVisibility = function (evt) {
351
- var visible = this.visible;
352
- var mbMap = this.mapboxLayer.mbMap;
353
- var filterFunc = this.styleLayersFilter;
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
- var style = mbMap.getStyle();
315
+ const style = mbMap.getStyle();
358
316
  if (!style) {
359
317
  return;
360
318
  }
361
319
  if (filterFunc) {
362
- var visibilityValue = visible ? 'visible' : 'none';
363
- for (var i = 0; i < style.layers.length; i += 1) {
364
- var styleLayer = style.layers[i];
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
- MapboxStyleLayer.prototype.clone = function (newOptions) {
379
- return new MapboxStyleLayer(__assign(__assign({}, this.options), newOptions));
380
- };
381
- return MapboxStyleLayer;
382
- }(Layer_1.default));
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MapboxStyleLayer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxStyleLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxStyleLayer.test.js"],"names":[],"mappings":""}