mobility-toolbox-js 2.0.0-beta.33 → 2.0.0-beta.34

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 (69) hide show
  1. package/api/RealtimeAPI.js +640 -0
  2. package/api/RoutingAPI.js +65 -0
  3. package/api/StopsAPI.js +70 -0
  4. package/api/index.js +10 -0
  5. package/api/typedefs.js +72 -0
  6. package/common/api/HttpAPI.d.ts +2 -2
  7. package/common/api/HttpAPI.d.ts.map +1 -1
  8. package/common/api/HttpAPI.js +84 -0
  9. package/common/api/WebSocketAPI.js +320 -0
  10. package/common/controls/Control.js +170 -0
  11. package/common/index.js +18 -0
  12. package/common/layers/Layer.js +257 -0
  13. package/common/mixins/CopyrightMixin.js +72 -0
  14. package/common/mixins/MapboxLayerMixin.js +240 -0
  15. package/common/mixins/RealtimeLayerMixin.js +705 -0
  16. package/common/mixins/StopFinderMixin.js +198 -0
  17. package/common/mixins/UserInteractionsLayerMixin.js +225 -0
  18. package/common/styles/index.js +24 -0
  19. package/common/styles/realtimeDefaultStyle.js +248 -0
  20. package/common/styles/realtimeDelayStyle.js +26 -0
  21. package/common/styles/realtimeSimpleStyle.js +24 -0
  22. package/common/typedefs.js +21 -0
  23. package/common/utils/cleanStopTime.js +30 -0
  24. package/common/utils/compareDepartures.js +37 -0
  25. package/common/utils/createCanvas.js +29 -0
  26. package/common/utils/createTrackerFilters.js +77 -0
  27. package/common/utils/getLayersAsFlatArray.js +16 -0
  28. package/common/utils/getMapboxMapCopyrights.js +26 -0
  29. package/common/utils/getMapboxRender.js +77 -0
  30. package/common/utils/getMaplibreRender.js +38 -0
  31. package/common/utils/getRealtimeModeSuffix.js +11 -0
  32. package/common/utils/getUrlWithParams.js +21 -0
  33. package/common/utils/getVehiclePosition.js +66 -0
  34. package/common/utils/index.js +37 -0
  35. package/common/utils/removeDuplicate.js +30 -0
  36. package/common/utils/renderTrajectories.js +119 -0
  37. package/common/utils/sortByDelay.js +22 -0
  38. package/common/utils/timeUtils.js +49 -0
  39. package/common/utils/trackerConfig.js +182 -0
  40. package/iife.js +7 -0
  41. package/index.js +11 -0
  42. package/mapbox/controls/CopyrightControl.js +73 -0
  43. package/mapbox/controls/index.js +6 -0
  44. package/mapbox/index.js +20 -0
  45. package/mapbox/layers/Layer.js +139 -0
  46. package/mapbox/layers/RealtimeLayer.js +312 -0
  47. package/mapbox/layers/index.js +7 -0
  48. package/mapbox/utils.js +57 -0
  49. package/mbt.js.map +2 -2
  50. package/mbt.min.js.map +2 -2
  51. package/ol/controls/CopyrightControl.js +90 -0
  52. package/ol/controls/RoutingControl.js +683 -0
  53. package/ol/controls/StopFinderControl.js +59 -0
  54. package/ol/controls/index.js +9 -0
  55. package/ol/index.js +21 -0
  56. package/ol/layers/Layer.js +180 -0
  57. package/ol/layers/MapboxLayer.js +137 -0
  58. package/ol/layers/MapboxStyleLayer.js +383 -0
  59. package/ol/layers/MaplibreLayer.js +69 -0
  60. package/ol/layers/RealtimeLayer.js +330 -0
  61. package/ol/layers/RoutingLayer.js +116 -0
  62. package/ol/layers/VectorLayer.js +72 -0
  63. package/ol/layers/WMSLayer.js +106 -0
  64. package/ol/layers/index.js +19 -0
  65. package/ol/styles/fullTrajectoryDelayStyle.js +35 -0
  66. package/ol/styles/fullTrajectoryStyle.js +46 -0
  67. package/ol/styles/index.js +7 -0
  68. package/package.json +1 -1
  69. package/setupTests.js +15 -0
@@ -0,0 +1,330 @@
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
+ var GeoJSON_1 = require("ol/format/GeoJSON");
30
+ var layer_1 = require("ol/layer");
31
+ var Source_1 = require("ol/source/Source");
32
+ var transform_1 = require("ol/transform");
33
+ var source_1 = require("ol/source");
34
+ var Layer_1 = require("./Layer");
35
+ var RealtimeLayerMixin_1 = require("../../common/mixins/RealtimeLayerMixin");
36
+ var styles_1 = require("../styles");
37
+ /** @private */
38
+ var format = new GeoJSON_1.default();
39
+ /**
40
+ * Responsible for loading and display data from a Realtime service.
41
+ *
42
+ * @example
43
+ * import { RealtimeLayer } from 'mobility-toolbox-js/ol';
44
+ *
45
+ * const layer = new RealtimeLayer({
46
+ * url: [yourUrl],
47
+ * apiKey: [yourApiKey],
48
+ * });
49
+ *
50
+ *
51
+ * @see <a href="/api/class/src/api/RealtimeAPI%20js~RealtimeAPI%20html">RealtimeAPI</a>
52
+ *
53
+ * @extends {Layer}
54
+ * @implements {UserInteractionsLayerInterface}
55
+ * @implements {RealtimeLayerInterface}
56
+ */
57
+ var RealtimeLayer = /** @class */ (function (_super) {
58
+ __extends(RealtimeLayer, _super);
59
+ /**
60
+ * Constructor.
61
+ *
62
+ * @param {Object} options
63
+ * @private
64
+ */
65
+ function RealtimeLayer(options) {
66
+ if (options === void 0) { options = {}; }
67
+ var _this =
68
+ // We use a group to be able to add custom vector layer in extended class.
69
+ // For example TrajservLayer use a vectorLayer to display the complete trajectory.
70
+ _super.call(this, __assign({}, options)) || this;
71
+ /** @ignore */
72
+ _this.olLayer =
73
+ options.olLayer ||
74
+ new layer_1.Group({
75
+ layers: [
76
+ new layer_1.Vector({
77
+ source: new source_1.Vector({ features: [] }),
78
+ style: function (feature, resolution) {
79
+ return (options.fullTrajectoryStyle || styles_1.fullTrajectoryStyle)(feature, resolution, _this.styleOptions);
80
+ },
81
+ }),
82
+ new layer_1.Layer({
83
+ source: new Source_1.default({}),
84
+ render: function (frameState) {
85
+ if (!_this.container) {
86
+ _this.container = document.createElement('div');
87
+ _this.container.style.position = 'absolute';
88
+ _this.container.style.width = '100%';
89
+ _this.container.style.height = '100%';
90
+ _this.transformContainer = document.createElement('div');
91
+ _this.transformContainer.style.position = 'absolute';
92
+ _this.transformContainer.style.width = '100%';
93
+ _this.transformContainer.style.height = '100%';
94
+ _this.container.appendChild(_this.transformContainer);
95
+ _this.canvas.style.position = 'absolute';
96
+ _this.canvas.style.top = '0';
97
+ _this.canvas.style.left = '0';
98
+ _this.canvas.style.transformOrigin = 'top left';
99
+ _this.transformContainer.appendChild(_this.canvas);
100
+ }
101
+ if (_this.renderedViewState) {
102
+ var _a = frameState.viewState, center = _a.center, resolution = _a.resolution, rotation = _a.rotation;
103
+ var _b = _this.renderedViewState, renderedCenter = _b.center, renderedResolution = _b.resolution, renderedRotation = _b.rotation;
104
+ if (renderedResolution / resolution >= 3) {
105
+ // Avoid having really big points when zooming fast.
106
+ var context = _this.canvas.getContext('2d');
107
+ context.clearRect(0, 0, _this.canvas.width, _this.canvas.height);
108
+ }
109
+ else {
110
+ var pixelCenterRendered = _this.map.getPixelFromCoordinate(renderedCenter);
111
+ var pixelCenter = _this.map.getPixelFromCoordinate(center);
112
+ _this.transformContainer.style.transform = (0, transform_1.composeCssTransform)(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
113
+ }
114
+ }
115
+ return _this.container;
116
+ },
117
+ }),
118
+ ],
119
+ });
120
+ // We store the layer used to highlight the full Trajectory
121
+ _this.vectorLayer = _this.olLayer.getLayers().item(0);
122
+ // Options the last render run did happen. If something changes
123
+ // we have to render again
124
+ /** @ignore */
125
+ _this.renderState = {
126
+ center: [0, 0],
127
+ zoom: null,
128
+ rotation: 0,
129
+ };
130
+ return _this;
131
+ }
132
+ RealtimeLayer.prototype.attachToMap = function (map) {
133
+ var _this = this;
134
+ _super.prototype.attachToMap.call(this, map);
135
+ if (this.map) {
136
+ this.olListenersKeys.push(this.map.on(['moveend', 'change:target'], function (evt) {
137
+ var view = _this.map.getView();
138
+ if (view.getAnimating() || view.getInteracting()) {
139
+ return;
140
+ }
141
+ var zoom = view.getZoom();
142
+ // Update the interval between render updates
143
+ if (_this.currentZoom !== zoom) {
144
+ _this.onZoomEnd(evt);
145
+ }
146
+ _this.currentZoom = zoom;
147
+ _this.onMoveEnd(evt);
148
+ }));
149
+ }
150
+ };
151
+ /**
152
+ * Destroy the container of the tracker.
153
+ */
154
+ RealtimeLayer.prototype.detachFromMap = function () {
155
+ _super.prototype.detachFromMap.call(this);
156
+ this.container = null;
157
+ };
158
+ /**
159
+ * Detect in the canvas if there is data to query at a specific coordinate.
160
+ * @param {ol/coordinate~Coordinate} coordinate The coordinate to test
161
+ * @returns
162
+ */
163
+ RealtimeLayer.prototype.hasFeatureInfoAtCoordinate = function (coordinate) {
164
+ if (this.map && this.canvas) {
165
+ var context = this.canvas.getContext('2d');
166
+ var pixel = this.map.getPixelFromCoordinate(coordinate);
167
+ return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
168
+ }
169
+ return false;
170
+ };
171
+ /**
172
+ * Render the trajectories using current map's size, resolution and rotation.
173
+ * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
174
+ * @overrides
175
+ */
176
+ RealtimeLayer.prototype.renderTrajectories = function (noInterpolate) {
177
+ var view = this.map.getView();
178
+ _super.prototype.renderTrajectories.call(this, {
179
+ size: this.map.getSize(),
180
+ center: this.map.getView().getCenter(),
181
+ extent: view.calculateExtent(),
182
+ resolution: view.getResolution(),
183
+ rotation: view.getRotation(),
184
+ zoom: view.getZoom(),
185
+ pixelRatio: this.pixelRatio,
186
+ }, noInterpolate);
187
+ };
188
+ /**
189
+ * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
190
+ * @private
191
+ * @override
192
+ */
193
+ RealtimeLayer.prototype.renderTrajectoriesInternal = function (viewState, noInterpolate) {
194
+ if (!this.map) {
195
+ return false;
196
+ }
197
+ var isRendered = false;
198
+ var blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
199
+ // Don't render the map when the map is animating or interacting.
200
+ isRendered = blockRendering
201
+ ? false
202
+ : _super.prototype.renderTrajectoriesInternal.call(this, viewState, noInterpolate);
203
+ // We update the current render state.
204
+ if (isRendered) {
205
+ this.renderedViewState = __assign({}, viewState);
206
+ if (this.transformContainer) {
207
+ this.transformContainer.style.transform = '';
208
+ }
209
+ }
210
+ return isRendered;
211
+ };
212
+ /**
213
+ * Return the delay in ms before the next rendering.
214
+ */
215
+ RealtimeLayer.prototype.getRefreshTimeInMs = function () {
216
+ return _super.prototype.getRefreshTimeInMs.call(this, this.map.getView().getZoom());
217
+ };
218
+ RealtimeLayer.prototype.getFeatureInfoAtCoordinate = function (coordinate, options) {
219
+ if (options === void 0) { options = {}; }
220
+ var resolution = this.map.getView().getResolution();
221
+ return _super.prototype.getFeatureInfoAtCoordinate.call(this, coordinate, __assign({ resolution: resolution }, options));
222
+ };
223
+ /**
224
+ * On move end we update the websocket with the new bbox.
225
+ *
226
+ * @private
227
+ * @override
228
+ */
229
+ RealtimeLayer.prototype.onMoveEnd = function () {
230
+ if (this.visible && this.isUpdateBboxOnMoveEnd) {
231
+ this.setBbox();
232
+ }
233
+ if (this.visible &&
234
+ this.isUpdateBboxOnMoveEnd &&
235
+ this.userClickInteractions &&
236
+ this.selectedVehicleId) {
237
+ this.highlightTrajectory(this.selectedVehicleId);
238
+ }
239
+ };
240
+ /**
241
+ * Function called on moveend event only when the zoom has changed.
242
+ *
243
+ * @param {ol/MapEvent~MapEvent} evt Moveend event.
244
+ * @private
245
+ * @override
246
+ */
247
+ // eslint-disable-next-line no-unused-vars
248
+ RealtimeLayer.prototype.onZoomEnd = function (evt) {
249
+ _super.prototype.onZoomEnd.call(this, evt);
250
+ };
251
+ /**
252
+ * Update the cursor style when hovering a vehicle.
253
+ *
254
+ * @private
255
+ * @override
256
+ */
257
+ RealtimeLayer.prototype.onFeatureHover = function (features, layer, coordinate) {
258
+ _super.prototype.onFeatureHover.call(this, features, layer, coordinate);
259
+ this.map.getTargetElement().style.cursor = features.length
260
+ ? 'pointer'
261
+ : 'auto';
262
+ };
263
+ /**
264
+ * Display the complete trajectory of the vehicle.
265
+ *
266
+ * @private
267
+ * @override
268
+ */
269
+ RealtimeLayer.prototype.onFeatureClick = function (features, layer, coordinate) {
270
+ _super.prototype.onFeatureClick.call(this, features, layer, coordinate);
271
+ if (!features.length && this.vectorLayer) {
272
+ this.vectorLayer.getSource().clear();
273
+ }
274
+ if (this.selectedVehicleId) {
275
+ this.highlightTrajectory(this.selectedVehicleId);
276
+ }
277
+ };
278
+ /**
279
+ * Remove the trajectory form the list if necessary.
280
+ *
281
+ * @private
282
+ */
283
+ RealtimeLayer.prototype.purgeTrajectory = function (trajectory, extent, zoom) {
284
+ return _super.prototype.purgeTrajectory.call(this, trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
285
+ };
286
+ /**
287
+ * Send the current bbox to the websocket
288
+ *
289
+ * @private
290
+ */
291
+ RealtimeLayer.prototype.setBbox = function (extent, zoom) {
292
+ var newExtent = extent;
293
+ var newZoom = zoom;
294
+ if (!newExtent && this.isUpdateBboxOnMoveEnd) {
295
+ newExtent = extent || this.map.getView().calculateExtent();
296
+ newZoom = Math.floor(this.map.getView().getZoom());
297
+ }
298
+ _super.prototype.setBbox.call(this, newExtent, newZoom);
299
+ };
300
+ /**
301
+ * Highlight the trajectory of journey.
302
+ * @private
303
+ */
304
+ RealtimeLayer.prototype.highlightTrajectory = function (id) {
305
+ var _this = this;
306
+ this.api
307
+ .getFullTrajectory(id, this.mode, this.generalizationLevel)
308
+ .then(function (fullTrajectory) {
309
+ var vectorSource = _this.vectorLayer.getSource();
310
+ vectorSource.clear();
311
+ if (!fullTrajectory ||
312
+ !fullTrajectory.features ||
313
+ !fullTrajectory.features.length) {
314
+ return;
315
+ }
316
+ var features = format.readFeatures(fullTrajectory);
317
+ _this.vectorLayer.getSource().addFeatures(features);
318
+ });
319
+ };
320
+ /**
321
+ * Create a copy of the RealtimeLayer.
322
+ * @param {Object} newOptions Options to override
323
+ * @return {RealtimeLayer} A RealtimeLayer
324
+ */
325
+ RealtimeLayer.prototype.clone = function (newOptions) {
326
+ return new RealtimeLayer(__assign(__assign({}, this.options), newOptions));
327
+ };
328
+ return RealtimeLayer;
329
+ }((0, RealtimeLayerMixin_1.default)(Layer_1.default)));
330
+ exports.default = RealtimeLayer;
@@ -0,0 +1,116 @@
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
+ var style_1 = require("ol/style");
30
+ var source_1 = require("ol/source");
31
+ var layer_1 = require("ol/layer");
32
+ var Layer_1 = require("./Layer");
33
+ /** @private */
34
+ var circleStyle = new style_1.Circle({
35
+ radius: 6,
36
+ fill: new style_1.Fill({
37
+ color: [255, 0, 0, 1],
38
+ }),
39
+ stroke: new style_1.Stroke({
40
+ color: [0, 0, 0, 1],
41
+ width: 1,
42
+ }),
43
+ });
44
+ /** @private */
45
+ var blackBorder = new style_1.Style({
46
+ stroke: new style_1.Stroke({
47
+ color: [0, 0, 0, 1],
48
+ width: 5,
49
+ }),
50
+ });
51
+ /** @private */
52
+ var redLine = new style_1.Style({
53
+ image: circleStyle,
54
+ stroke: new style_1.Stroke({
55
+ color: [255, 0, 0, 1],
56
+ width: 3,
57
+ }),
58
+ });
59
+ /** @private */
60
+ var dashedRedLine = new style_1.Style({
61
+ image: circleStyle,
62
+ stroke: new style_1.Stroke({
63
+ color: [255, 0, 0, 1],
64
+ width: 3,
65
+ lineDash: [1, 10],
66
+ }),
67
+ });
68
+ /** @private */
69
+ var defaultStyleFunction = function (feature, resolution) {
70
+ var minResolution = feature.get('minResolution');
71
+ var maxResolution = feature.get('maxResolution');
72
+ var inRange = resolution <= minResolution && resolution > maxResolution;
73
+ if (minResolution && maxResolution && !inRange) {
74
+ return null;
75
+ }
76
+ var mot = feature.get('mot');
77
+ if (mot !== 'foot') {
78
+ return [blackBorder, redLine];
79
+ }
80
+ return [dashedRedLine];
81
+ };
82
+ /**
83
+ * A class use to display vector data.
84
+ *
85
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
86
+ * @extends {Layer}
87
+ */
88
+ var RoutingLayer = /** @class */ (function (_super) {
89
+ __extends(RoutingLayer, _super);
90
+ /**
91
+ * Constructor.
92
+ * @param {Object} [options]
93
+ * @param {ol/style/Style~StyleLike} [options.style] Style to be used for routes, uses (ol/StyleLike) [https://openlayers.org/en/latest/apidoc/module-ol_style_Style.html#~StyleLike] instances
94
+ */
95
+ function RoutingLayer(options) {
96
+ if (options === void 0) { options = {}; }
97
+ var _this = _super.call(this, options) || this;
98
+ _this.olLayer =
99
+ options.olLayer ||
100
+ new layer_1.Vector({
101
+ source: new source_1.Vector(),
102
+ style: options.style || defaultStyleFunction,
103
+ });
104
+ return _this;
105
+ }
106
+ /**
107
+ * Create a copy of the RoutingLayer.
108
+ * @param {Object} newOptions Options to override
109
+ * @return {RoutingLayer} A RoutingLayer
110
+ */
111
+ RoutingLayer.prototype.clone = function (newOptions) {
112
+ return new RoutingLayer(__assign(__assign({}, this.options), newOptions));
113
+ };
114
+ return RoutingLayer;
115
+ }(Layer_1.default));
116
+ exports.default = RoutingLayer;
@@ -0,0 +1,72 @@
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
+ var Layer_1 = require("./Layer");
30
+ /**
31
+ * A class use to display vector data.
32
+ *
33
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
34
+ * @extends {Layer}
35
+ */
36
+ var VectorLayer = /** @class */ (function (_super) {
37
+ __extends(VectorLayer, _super);
38
+ function VectorLayer() {
39
+ return _super !== null && _super.apply(this, arguments) || this;
40
+ }
41
+ /**
42
+ * Request feature information for a given coordinate.
43
+ * @param {ol/coordinate~Coordinate} coordinate the coordinate to request the information at.
44
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
45
+ */
46
+ VectorLayer.prototype.getFeatureInfoAtCoordinate = function (coordinate) {
47
+ var _this = this;
48
+ var features = [];
49
+ if (this.map) {
50
+ var pixel = this.map.getPixelFromCoordinate(coordinate);
51
+ features = this.map.getFeaturesAtPixel(pixel, {
52
+ layerFilter: function (l) { return l === _this.olLayer; },
53
+ hitTolerance: this.hitTolerance,
54
+ });
55
+ }
56
+ return Promise.resolve({
57
+ features: features,
58
+ layer: this,
59
+ coordinate: coordinate,
60
+ });
61
+ };
62
+ /**
63
+ * Create a copy of the VectorLayer.
64
+ * @param {Object} newOptions Options to override
65
+ * @return {VectorLayer} A VectorLayer
66
+ */
67
+ VectorLayer.prototype.clone = function (newOptions) {
68
+ return new VectorLayer(__assign(__assign({}, this.options), newOptions));
69
+ };
70
+ return VectorLayer;
71
+ }(Layer_1.default));
72
+ exports.default = VectorLayer;
@@ -0,0 +1,106 @@
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
+ var GeoJSON_1 = require("ol/format/GeoJSON");
30
+ var Layer_1 = require("./Layer");
31
+ /**
32
+ * Class use to display a WMS layer.
33
+ *
34
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
35
+ * @extends {Layer}
36
+ */
37
+ var WMSLayer = /** @class */ (function (_super) {
38
+ __extends(WMSLayer, _super);
39
+ /**
40
+ * @override
41
+ */
42
+ function WMSLayer(options) {
43
+ if (options === void 0) { options = {}; }
44
+ var _this = _super.call(this, options) || this;
45
+ /** @ignore */
46
+ _this.abortController = new AbortController();
47
+ /** @ignore */
48
+ _this.format = new GeoJSON_1.default();
49
+ return _this;
50
+ }
51
+ /**
52
+ * Get features infos' Url.
53
+ * @param {ol/coordinate~Coordinate} coord
54
+ * @return {ol/layer/Layer~Layer}
55
+ */
56
+ WMSLayer.prototype.getFeatureInfoUrl = function (coord) {
57
+ var projection = this.map.getView().getProjection();
58
+ var resolution = this.map.getView().getResolution();
59
+ if (this.olLayer.getSource().getFeatureInfoUrl) {
60
+ return this.olLayer
61
+ .getSource()
62
+ .getFeatureInfoUrl(coord, resolution, projection, {
63
+ info_format: 'application/json',
64
+ query_layers: this.olLayer.getSource().getParams().layers,
65
+ });
66
+ }
67
+ return false;
68
+ };
69
+ /**
70
+ * Request feature information for a given coordinate.
71
+ * @param {ol/coordinate~Coordinate} coordinate to request the information at.
72
+ * @return {Promise<FeatureInfo>} Promise with features, layer and coordinate.
73
+ */
74
+ WMSLayer.prototype.getFeatureInfoAtCoordinate = function (coordinate) {
75
+ var _this = this;
76
+ this.abortController.abort();
77
+ this.abortController = new AbortController();
78
+ var signal = this.abortController.signal;
79
+ return fetch(this.getFeatureInfoUrl(coordinate), { signal: signal })
80
+ .then(function (resp) { return resp.json(); })
81
+ .then(function (r) { return r.features; })
82
+ .then(function (data) { return ({
83
+ layer: _this,
84
+ coordinate: coordinate,
85
+ features: data.map(function (d) { return _this.format.readFeature(d); }),
86
+ }); })
87
+ .catch(function () {
88
+ // resolve an empty feature array something fails
89
+ return Promise.resolve({
90
+ features: [],
91
+ coordinate: coordinate,
92
+ layer: _this,
93
+ });
94
+ });
95
+ };
96
+ /**
97
+ * Create a copy of the WMSLayer.
98
+ * @param {Object} newOptions Options to override
99
+ * @return {WMSLayer} A WMSLayer
100
+ */
101
+ WMSLayer.prototype.clone = function (newOptions) {
102
+ return new WMSLayer(__assign(__assign({}, this.options), newOptions));
103
+ };
104
+ return WMSLayer;
105
+ }(Layer_1.default));
106
+ exports.default = WMSLayer;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WMSLayer = exports.VectorLayer = exports.RealtimeLayer = exports.RoutingLayer = exports.MapboxStyleLayer = exports.MaplibreLayer = exports.MapboxLayer = exports.Layer = void 0;
4
+ var Layer_1 = require("./Layer");
5
+ Object.defineProperty(exports, "Layer", { enumerable: true, get: function () { return Layer_1.default; } });
6
+ var MapboxLayer_1 = require("./MapboxLayer");
7
+ Object.defineProperty(exports, "MapboxLayer", { enumerable: true, get: function () { return MapboxLayer_1.default; } });
8
+ var MaplibreLayer_1 = require("./MaplibreLayer");
9
+ Object.defineProperty(exports, "MaplibreLayer", { enumerable: true, get: function () { return MaplibreLayer_1.default; } });
10
+ var MapboxStyleLayer_1 = require("./MapboxStyleLayer");
11
+ Object.defineProperty(exports, "MapboxStyleLayer", { enumerable: true, get: function () { return MapboxStyleLayer_1.default; } });
12
+ var RoutingLayer_1 = require("./RoutingLayer");
13
+ Object.defineProperty(exports, "RoutingLayer", { enumerable: true, get: function () { return RoutingLayer_1.default; } });
14
+ var RealtimeLayer_1 = require("./RealtimeLayer");
15
+ Object.defineProperty(exports, "RealtimeLayer", { enumerable: true, get: function () { return RealtimeLayer_1.default; } });
16
+ var VectorLayer_1 = require("./VectorLayer");
17
+ Object.defineProperty(exports, "VectorLayer", { enumerable: true, get: function () { return VectorLayer_1.default; } });
18
+ var WMSLayer_1 = require("./WMSLayer");
19
+ Object.defineProperty(exports, "WMSLayer", { enumerable: true, get: function () { return WMSLayer_1.default; } });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var style_1 = require("ol/style");
4
+ /** @private */
5
+ var stroke = new style_1.Style({
6
+ zIndex: 2,
7
+ image: new style_1.Circle({
8
+ radius: 5,
9
+ fill: new style_1.Fill({
10
+ color: '#000000',
11
+ }),
12
+ }),
13
+ stroke: new style_1.Stroke({
14
+ color: '#000000',
15
+ width: 6,
16
+ }),
17
+ });
18
+ /** @private */
19
+ var fill = new style_1.Style({
20
+ zIndex: 3,
21
+ image: new style_1.Circle({
22
+ radius: 4,
23
+ fill: new style_1.Fill({
24
+ color: '#a0a0a0',
25
+ }),
26
+ }),
27
+ stroke: new style_1.Stroke({
28
+ color: '#a0a0a0',
29
+ width: 4,
30
+ }),
31
+ });
32
+ var fullTrajectoryDelaystyle = function () {
33
+ return [stroke, fill];
34
+ };
35
+ exports.default = fullTrajectoryDelaystyle;