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,41 +1,13 @@
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");
1
+ import GeoJSON from 'ol/format/GeoJSON';
2
+ import { Layer as OLLayer, Group, Vector as VectorLayer } from 'ol/layer';
3
+ import Source from 'ol/source/Source';
4
+ import { composeCssTransform } from 'ol/transform';
5
+ import { Vector as VectorSource } from 'ol/source';
6
+ import Layer from './Layer';
7
+ import mixin from '../../common/mixins/RealtimeLayerMixin';
8
+ import { fullTrajectoryStyle } from '../styles';
37
9
  /** @private */
38
- var format = new GeoJSON_1.default();
10
+ const format = new GeoJSON();
39
11
  /**
40
12
  * Responsible for loading and display data from a Realtime service.
41
13
  *
@@ -54,128 +26,123 @@ var format = new GeoJSON_1.default();
54
26
  * @implements {UserInteractionsLayerInterface}
55
27
  * @implements {RealtimeLayerInterface}
56
28
  */
57
- var RealtimeLayer = /** @class */ (function (_super) {
58
- __extends(RealtimeLayer, _super);
29
+ class RealtimeLayer extends mixin(Layer) {
59
30
  /**
60
31
  * Constructor.
61
32
  *
62
33
  * @param {Object} options
63
34
  * @private
64
35
  */
65
- function RealtimeLayer(options) {
66
- if (options === void 0) { options = {}; }
67
- var _this =
36
+ constructor(options = {}) {
68
37
  // We use a group to be able to add custom vector layer in extended class.
69
38
  // For example TrajservLayer use a vectorLayer to display the complete trajectory.
70
- _super.call(this, __assign({}, options)) || this;
39
+ super(Object.assign({}, options));
71
40
  /** @ignore */
72
- _this.olLayer =
41
+ this.olLayer =
73
42
  options.olLayer ||
74
- new layer_1.Group({
43
+ new Group({
75
44
  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);
45
+ new VectorLayer({
46
+ source: new VectorSource({ features: [] }),
47
+ style: (feature, resolution) => {
48
+ return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
80
49
  },
81
50
  }),
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);
51
+ new OLLayer({
52
+ source: new Source({}),
53
+ render: (frameState) => {
54
+ if (!this.container) {
55
+ this.container = document.createElement('div');
56
+ this.container.style.position = 'absolute';
57
+ this.container.style.width = '100%';
58
+ this.container.style.height = '100%';
59
+ this.transformContainer = document.createElement('div');
60
+ this.transformContainer.style.position = 'absolute';
61
+ this.transformContainer.style.width = '100%';
62
+ this.transformContainer.style.height = '100%';
63
+ this.container.appendChild(this.transformContainer);
64
+ this.canvas.style.position = 'absolute';
65
+ this.canvas.style.top = '0';
66
+ this.canvas.style.left = '0';
67
+ this.canvas.style.transformOrigin = 'top left';
68
+ this.transformContainer.appendChild(this.canvas);
100
69
  }
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;
70
+ if (this.renderedViewState) {
71
+ const { center, resolution, rotation } = frameState.viewState;
72
+ const { center: renderedCenter, resolution: renderedResolution, rotation: renderedRotation, } = this.renderedViewState;
104
73
  if (renderedResolution / resolution >= 3) {
105
74
  // 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);
75
+ const context = this.canvas.getContext('2d');
76
+ context.clearRect(0, 0, this.canvas.width, this.canvas.height);
108
77
  }
109
78
  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);
79
+ const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
80
+ const pixelCenter = this.map.getPixelFromCoordinate(center);
81
+ this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
113
82
  }
114
83
  }
115
- return _this.container;
84
+ return this.container;
116
85
  },
117
86
  }),
118
87
  ],
119
88
  });
120
89
  // We store the layer used to highlight the full Trajectory
121
- _this.vectorLayer = _this.olLayer.getLayers().item(0);
90
+ this.vectorLayer = this.olLayer.getLayers().item(0);
122
91
  // Options the last render run did happen. If something changes
123
92
  // we have to render again
124
93
  /** @ignore */
125
- _this.renderState = {
94
+ this.renderState = {
126
95
  center: [0, 0],
127
96
  zoom: null,
128
97
  rotation: 0,
129
98
  };
130
- return _this;
131
99
  }
132
- RealtimeLayer.prototype.attachToMap = function (map) {
133
- var _this = this;
134
- _super.prototype.attachToMap.call(this, map);
100
+ attachToMap(map) {
101
+ super.attachToMap(map);
135
102
  if (this.map) {
136
- this.olListenersKeys.push(this.map.on(['moveend', 'change:target'], function (evt) {
137
- var view = _this.map.getView();
103
+ this.olListenersKeys.push(this.map.on(['moveend', 'change:target'], (evt) => {
104
+ const view = this.map.getView();
138
105
  if (view.getAnimating() || view.getInteracting()) {
139
106
  return;
140
107
  }
141
- var zoom = view.getZoom();
108
+ const zoom = view.getZoom();
142
109
  // Update the interval between render updates
143
- if (_this.currentZoom !== zoom) {
144
- _this.onZoomEnd(evt);
110
+ if (this.currentZoom !== zoom) {
111
+ this.onZoomEnd(evt);
145
112
  }
146
- _this.currentZoom = zoom;
147
- _this.onMoveEnd(evt);
113
+ this.currentZoom = zoom;
114
+ this.onMoveEnd(evt);
148
115
  }));
149
116
  }
150
- };
117
+ }
151
118
  /**
152
119
  * Destroy the container of the tracker.
153
120
  */
154
- RealtimeLayer.prototype.detachFromMap = function () {
155
- _super.prototype.detachFromMap.call(this);
121
+ detachFromMap() {
122
+ super.detachFromMap();
156
123
  this.container = null;
157
- };
124
+ }
158
125
  /**
159
126
  * Detect in the canvas if there is data to query at a specific coordinate.
160
127
  * @param {ol/coordinate~Coordinate} coordinate The coordinate to test
161
128
  * @returns
162
129
  */
163
- RealtimeLayer.prototype.hasFeatureInfoAtCoordinate = function (coordinate) {
130
+ hasFeatureInfoAtCoordinate(coordinate) {
164
131
  if (this.map && this.canvas) {
165
- var context = this.canvas.getContext('2d');
166
- var pixel = this.map.getPixelFromCoordinate(coordinate);
132
+ const context = this.canvas.getContext('2d');
133
+ const pixel = this.map.getPixelFromCoordinate(coordinate);
167
134
  return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
168
135
  }
169
136
  return false;
170
- };
137
+ }
171
138
  /**
172
139
  * Render the trajectories using current map's size, resolution and rotation.
173
140
  * @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
174
141
  * @overrides
175
142
  */
176
- RealtimeLayer.prototype.renderTrajectories = function (noInterpolate) {
177
- var view = this.map.getView();
178
- _super.prototype.renderTrajectories.call(this, {
143
+ renderTrajectories(noInterpolate) {
144
+ const view = this.map.getView();
145
+ super.renderTrajectories({
179
146
  size: this.map.getSize(),
180
147
  center: this.map.getView().getCenter(),
181
148
  extent: view.calculateExtent(),
@@ -184,49 +151,48 @@ var RealtimeLayer = /** @class */ (function (_super) {
184
151
  zoom: view.getZoom(),
185
152
  pixelRatio: this.pixelRatio,
186
153
  }, noInterpolate);
187
- };
154
+ }
188
155
  /**
189
156
  * Launch renderTrajectories. it avoids duplicating code in renderTrajectories methhod.
190
157
  * @private
191
158
  * @override
192
159
  */
193
- RealtimeLayer.prototype.renderTrajectoriesInternal = function (viewState, noInterpolate) {
160
+ renderTrajectoriesInternal(viewState, noInterpolate) {
194
161
  if (!this.map) {
195
162
  return false;
196
163
  }
197
- var isRendered = false;
198
- var blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
164
+ let isRendered = false;
165
+ const blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
199
166
  // Don't render the map when the map is animating or interacting.
200
167
  isRendered = blockRendering
201
168
  ? false
202
- : _super.prototype.renderTrajectoriesInternal.call(this, viewState, noInterpolate);
169
+ : super.renderTrajectoriesInternal(viewState, noInterpolate);
203
170
  // We update the current render state.
204
171
  if (isRendered) {
205
- this.renderedViewState = __assign({}, viewState);
172
+ this.renderedViewState = Object.assign({}, viewState);
206
173
  if (this.transformContainer) {
207
174
  this.transformContainer.style.transform = '';
208
175
  }
209
176
  }
210
177
  return isRendered;
211
- };
178
+ }
212
179
  /**
213
180
  * Return the delay in ms before the next rendering.
214
181
  */
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
- };
182
+ getRefreshTimeInMs() {
183
+ return super.getRefreshTimeInMs(this.map.getView().getZoom());
184
+ }
185
+ getFeatureInfoAtCoordinate(coordinate, options = {}) {
186
+ const resolution = this.map.getView().getResolution();
187
+ return super.getFeatureInfoAtCoordinate(coordinate, Object.assign({ resolution }, options));
188
+ }
223
189
  /**
224
190
  * On move end we update the websocket with the new bbox.
225
191
  *
226
192
  * @private
227
193
  * @override
228
194
  */
229
- RealtimeLayer.prototype.onMoveEnd = function () {
195
+ onMoveEnd() {
230
196
  if (this.visible && this.isUpdateBboxOnMoveEnd) {
231
197
  this.setBbox();
232
198
  }
@@ -236,7 +202,7 @@ var RealtimeLayer = /** @class */ (function (_super) {
236
202
  this.selectedVehicleId) {
237
203
  this.highlightTrajectory(this.selectedVehicleId);
238
204
  }
239
- };
205
+ }
240
206
  /**
241
207
  * Function called on moveend event only when the zoom has changed.
242
208
  *
@@ -245,86 +211,84 @@ var RealtimeLayer = /** @class */ (function (_super) {
245
211
  * @override
246
212
  */
247
213
  // eslint-disable-next-line no-unused-vars
248
- RealtimeLayer.prototype.onZoomEnd = function (evt) {
249
- _super.prototype.onZoomEnd.call(this, evt);
250
- };
214
+ onZoomEnd(evt) {
215
+ super.onZoomEnd(evt);
216
+ }
251
217
  /**
252
218
  * Update the cursor style when hovering a vehicle.
253
219
  *
254
220
  * @private
255
221
  * @override
256
222
  */
257
- RealtimeLayer.prototype.onFeatureHover = function (features, layer, coordinate) {
258
- _super.prototype.onFeatureHover.call(this, features, layer, coordinate);
223
+ onFeatureHover(features, layer, coordinate) {
224
+ super.onFeatureHover(features, layer, coordinate);
259
225
  this.map.getTargetElement().style.cursor = features.length
260
226
  ? 'pointer'
261
227
  : 'auto';
262
- };
228
+ }
263
229
  /**
264
230
  * Display the complete trajectory of the vehicle.
265
231
  *
266
232
  * @private
267
233
  * @override
268
234
  */
269
- RealtimeLayer.prototype.onFeatureClick = function (features, layer, coordinate) {
270
- _super.prototype.onFeatureClick.call(this, features, layer, coordinate);
235
+ onFeatureClick(features, layer, coordinate) {
236
+ super.onFeatureClick(features, layer, coordinate);
271
237
  if (!features.length && this.vectorLayer) {
272
238
  this.vectorLayer.getSource().clear();
273
239
  }
274
240
  if (this.selectedVehicleId) {
275
241
  this.highlightTrajectory(this.selectedVehicleId);
276
242
  }
277
- };
243
+ }
278
244
  /**
279
245
  * Remove the trajectory form the list if necessary.
280
246
  *
281
247
  * @private
282
248
  */
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
- };
249
+ purgeTrajectory(trajectory, extent, zoom) {
250
+ return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
251
+ }
286
252
  /**
287
253
  * Send the current bbox to the websocket
288
254
  *
289
255
  * @private
290
256
  */
291
- RealtimeLayer.prototype.setBbox = function (extent, zoom) {
292
- var newExtent = extent;
293
- var newZoom = zoom;
257
+ setBbox(extent, zoom) {
258
+ let newExtent = extent;
259
+ let newZoom = zoom;
294
260
  if (!newExtent && this.isUpdateBboxOnMoveEnd) {
295
261
  newExtent = extent || this.map.getView().calculateExtent();
296
262
  newZoom = Math.floor(this.map.getView().getZoom());
297
263
  }
298
- _super.prototype.setBbox.call(this, newExtent, newZoom);
299
- };
264
+ super.setBbox(newExtent, newZoom);
265
+ }
300
266
  /**
301
267
  * Highlight the trajectory of journey.
302
268
  * @private
303
269
  */
304
- RealtimeLayer.prototype.highlightTrajectory = function (id) {
305
- var _this = this;
270
+ highlightTrajectory(id) {
306
271
  this.api
307
272
  .getFullTrajectory(id, this.mode, this.generalizationLevel)
308
- .then(function (fullTrajectory) {
309
- var vectorSource = _this.vectorLayer.getSource();
273
+ .then((fullTrajectory) => {
274
+ const vectorSource = this.vectorLayer.getSource();
310
275
  vectorSource.clear();
311
276
  if (!fullTrajectory ||
312
277
  !fullTrajectory.features ||
313
278
  !fullTrajectory.features.length) {
314
279
  return;
315
280
  }
316
- var features = format.readFeatures(fullTrajectory);
317
- _this.vectorLayer.getSource().addFeatures(features);
281
+ const features = format.readFeatures(fullTrajectory);
282
+ this.vectorLayer.getSource().addFeatures(features);
318
283
  });
319
- };
284
+ }
320
285
  /**
321
286
  * Create a copy of the RealtimeLayer.
322
287
  * @param {Object} newOptions Options to override
323
288
  * @return {RealtimeLayer} A RealtimeLayer
324
289
  */
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;
290
+ clone(newOptions) {
291
+ return new RealtimeLayer(Object.assign(Object.assign({}, this.options), newOptions));
292
+ }
293
+ }
294
+ export default RealtimeLayer;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=RealtimeLayer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RealtimeLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RealtimeLayer.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,71 @@
1
+ import fetch from 'jest-fetch-mock';
2
+ import Map from 'ol/Map';
3
+ import View from 'ol/View';
4
+ import WS from 'jest-websocket-mock';
5
+ import RealtimeLayer from './RealtimeLayer';
6
+ // create a WS instance, listening on port 1234 on localhost
7
+ let layer;
8
+ let onClick;
9
+ let olMap;
10
+ let server;
11
+ describe('RealtimeLayer', () => {
12
+ beforeEach(() => {
13
+ server = new WS('ws://localhost:1234');
14
+ global.fetch = fetch;
15
+ fetch.resetMocks();
16
+ onClick = jest.fn();
17
+ layer = new RealtimeLayer({
18
+ url: 'ws://localhost:1234',
19
+ apiKey: 'apiKey',
20
+ onClick,
21
+ });
22
+ olMap = new Map({
23
+ view: new View({
24
+ center: [831634, 5933959],
25
+ zoom: 9,
26
+ }),
27
+ });
28
+ });
29
+ afterEach(() => {
30
+ // ...or gracefully close the connection
31
+ server.close();
32
+ // The WS class also has a static "clean" method to gracefully close all open connections,
33
+ // particularly useful to reset the environment between test runs.
34
+ WS.clean();
35
+ });
36
+ test('should be instanced.', () => {
37
+ expect(layer).toBeInstanceOf(RealtimeLayer);
38
+ });
39
+ test('should called terminate on initalization.', () => {
40
+ const spy = jest.spyOn(layer, 'detachFromMap');
41
+ fetch.mockResponseOnce(JSON.stringify(global.fetchTrajectoriesResponse));
42
+ layer.attachToMap(olMap);
43
+ expect(spy).toHaveBeenCalledTimes(1);
44
+ });
45
+ test('should clone', () => {
46
+ const clone = layer.clone({ name: 'clone' });
47
+ expect(clone).not.toBe(layer);
48
+ expect(clone.name).toBe('clone');
49
+ expect(clone).toBeInstanceOf(RealtimeLayer);
50
+ });
51
+ test('should use the sort function.', () => {
52
+ const fn = () => true;
53
+ const laye = new RealtimeLayer({
54
+ url: 'ws://localhost:1234',
55
+ apiKey: 'apiKey',
56
+ sort: fn,
57
+ });
58
+ expect(laye).toBeInstanceOf(RealtimeLayer);
59
+ expect(laye.sort).toBe(fn);
60
+ });
61
+ test('should use filter function.', () => {
62
+ const fn = () => true;
63
+ const laye = new RealtimeLayer({
64
+ url: 'ws://localhost:1234',
65
+ apiKey: 'apiKey',
66
+ filter: fn, // reverse the array
67
+ });
68
+ expect(laye).toBeInstanceOf(RealtimeLayer);
69
+ expect(laye.filter).toBe(fn);
70
+ });
71
+ });
@@ -11,14 +11,14 @@ declare class RoutingLayer extends Layer {
11
11
  * @param {Object} [options]
12
12
  * @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
13
13
  */
14
- constructor(options?: any);
14
+ constructor(options?: Object | undefined);
15
15
  olLayer: any;
16
16
  /**
17
17
  * Create a copy of the RoutingLayer.
18
18
  * @param {Object} newOptions Options to override
19
19
  * @return {RoutingLayer} A RoutingLayer
20
20
  */
21
- clone(newOptions: any): RoutingLayer;
21
+ clone(newOptions: Object): RoutingLayer;
22
22
  }
23
23
  import Layer from "./Layer";
24
24
  //# sourceMappingURL=RoutingLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.js"],"names":[],"mappings":";AA8DA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,2BASC;IANC,aAKI;IAGN;;;;OAIG;IACH,wBAFY,YAAY,CAIvB;CACF"}
1
+ {"version":3,"file":"RoutingLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/RoutingLayer.js"],"names":[],"mappings":";AA8DA;;;;;GAKG;AACH;IACE;;;;OAIG;IACH,0CASC;IANC,aAKI;IAGN;;;;OAIG;IACH,kBAHW,MAAM,GACL,YAAY,CAIvB;CACF"}