mobility-toolbox-js 2.0.0-beta.30 → 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 (225) hide show
  1. package/api/RealtimeAPI.d.ts +268 -0
  2. package/api/RealtimeAPI.d.ts.map +1 -0
  3. package/api/RealtimeAPI.js +626 -343
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/RoutingAPI.js +65 -15
  7. package/api/StopsAPI.d.ts +36 -0
  8. package/api/StopsAPI.d.ts.map +1 -0
  9. package/api/StopsAPI.js +70 -12
  10. package/api/index.d.ts +5 -0
  11. package/api/index.d.ts.map +1 -0
  12. package/api/index.js +10 -3
  13. package/api/typedefs.d.ts +105 -0
  14. package/api/typedefs.d.ts.map +1 -0
  15. package/api/typedefs.js +72 -0
  16. package/common/api/HttpAPI.d.ts +31 -0
  17. package/common/api/HttpAPI.d.ts.map +1 -0
  18. package/common/api/HttpAPI.js +82 -30
  19. package/common/api/WebSocketAPI.d.ts +95 -0
  20. package/common/api/WebSocketAPI.d.ts.map +1 -0
  21. package/common/api/WebSocketAPI.js +313 -168
  22. package/common/controls/Control.d.ts +74 -0
  23. package/common/controls/Control.d.ts.map +1 -0
  24. package/common/controls/Control.js +167 -78
  25. package/common/index.d.ts +3 -0
  26. package/common/index.d.ts.map +1 -0
  27. package/common/index.js +18 -2
  28. package/common/layers/Layer.d.ts +80 -0
  29. package/common/layers/Layer.d.ts.map +1 -0
  30. package/common/layers/Layer.js +251 -134
  31. package/common/mixins/CopyrightMixin.d.ts +22 -0
  32. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  33. package/common/mixins/CopyrightMixin.js +70 -22
  34. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  35. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  36. package/common/mixins/MapboxLayerMixin.js +240 -0
  37. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  38. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  39. package/common/mixins/RealtimeLayerMixin.js +698 -429
  40. package/common/mixins/StopFinderMixin.d.ts +40 -0
  41. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  42. package/common/mixins/StopFinderMixin.js +195 -107
  43. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  44. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  45. package/common/mixins/UserInteractionsLayerMixin.js +222 -121
  46. package/common/styles/index.d.ts +5 -0
  47. package/common/styles/index.d.ts.map +1 -0
  48. package/common/styles/index.js +24 -4
  49. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  50. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  51. package/common/styles/realtimeDefaultStyle.js +236 -190
  52. package/common/styles/realtimeDelayStyle.d.ts +11 -0
  53. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  54. package/common/styles/realtimeDelayStyle.js +25 -7
  55. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  56. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  57. package/common/styles/realtimeSimpleStyle.js +23 -17
  58. package/common/typedefs.d.ts +50 -0
  59. package/common/typedefs.d.ts.map +1 -0
  60. package/common/typedefs.js +21 -0
  61. package/common/utils/cleanStopTime.d.ts +7 -0
  62. package/common/utils/cleanStopTime.d.ts.map +1 -0
  63. package/common/utils/cleanStopTime.js +28 -17
  64. package/common/utils/compareDepartures.d.ts +9 -0
  65. package/common/utils/compareDepartures.d.ts.map +1 -0
  66. package/common/utils/compareDepartures.js +34 -22
  67. package/common/utils/createCanvas.d.ts +9 -0
  68. package/common/utils/createCanvas.d.ts.map +1 -0
  69. package/common/utils/createCanvas.js +28 -16
  70. package/common/utils/createTrackerFilters.d.ts +12 -0
  71. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  72. package/common/utils/createTrackerFilters.js +75 -54
  73. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  74. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  75. package/common/utils/getLayersAsFlatArray.js +15 -13
  76. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  77. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  78. package/common/utils/getMapboxMapCopyrights.js +24 -17
  79. package/common/utils/getMapboxRender.d.ts +5 -0
  80. package/common/utils/getMapboxRender.d.ts.map +1 -0
  81. package/common/utils/getMapboxRender.js +77 -0
  82. package/common/utils/getMaplibreRender.d.ts +5 -0
  83. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  84. package/common/utils/getMaplibreRender.js +38 -0
  85. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  86. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  87. package/common/utils/getRealtimeModeSuffix.js +11 -2
  88. package/common/utils/getUrlWithParams.d.ts +9 -0
  89. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  90. package/common/utils/getUrlWithParams.js +20 -10
  91. package/common/utils/getVehiclePosition.d.ts +14 -0
  92. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  93. package/common/utils/getVehiclePosition.js +63 -39
  94. package/common/utils/index.d.ts +12 -0
  95. package/common/utils/index.d.ts.map +1 -0
  96. package/common/utils/index.js +37 -9
  97. package/common/utils/removeDuplicate.d.ts +10 -0
  98. package/common/utils/removeDuplicate.d.ts.map +1 -0
  99. package/common/utils/removeDuplicate.js +29 -7
  100. package/common/utils/renderTrajectories.d.ts +20 -0
  101. package/common/utils/renderTrajectories.d.ts.map +1 -0
  102. package/common/utils/renderTrajectories.js +111 -78
  103. package/common/utils/sortByDelay.d.ts +3 -0
  104. package/common/utils/sortByDelay.d.ts.map +1 -0
  105. package/common/utils/sortByDelay.js +21 -17
  106. package/common/utils/timeUtils.d.ts +5 -0
  107. package/common/utils/timeUtils.d.ts.map +1 -0
  108. package/common/utils/timeUtils.js +47 -18
  109. package/common/utils/trackerConfig.d.ts +24 -0
  110. package/common/utils/trackerConfig.d.ts.map +1 -0
  111. package/common/utils/trackerConfig.js +171 -118
  112. package/iife.d.ts +3 -0
  113. package/iife.d.ts.map +1 -0
  114. package/iife.js +7 -0
  115. package/index.d.ts +6 -0
  116. package/index.d.ts.map +1 -0
  117. package/index.js +10 -7
  118. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  119. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  120. package/mapbox/controls/CopyrightControl.js +72 -28
  121. package/mapbox/controls/index.d.ts +2 -0
  122. package/mapbox/controls/index.d.ts.map +1 -0
  123. package/mapbox/controls/index.js +6 -1
  124. package/mapbox/index.d.ts +5 -0
  125. package/mapbox/index.d.ts.map +1 -0
  126. package/mapbox/index.js +20 -4
  127. package/mapbox/layers/Layer.d.ts +47 -0
  128. package/mapbox/layers/Layer.d.ts.map +1 -0
  129. package/mapbox/layers/Layer.js +137 -54
  130. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  131. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  132. package/mapbox/layers/RealtimeLayer.js +310 -183
  133. package/mapbox/layers/index.d.ts +3 -0
  134. package/mapbox/layers/index.d.ts.map +1 -0
  135. package/mapbox/layers/index.js +7 -2
  136. package/mapbox/utils.d.ts +8 -0
  137. package/mapbox/utils.d.ts.map +1 -0
  138. package/mapbox/utils.js +54 -29
  139. package/mbt.js +2052 -2109
  140. package/mbt.js.map +3 -3
  141. package/mbt.min.js +18 -18
  142. package/mbt.min.js.map +3 -3
  143. package/ol/controls/CopyrightControl.d.ts +31 -0
  144. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  145. package/ol/controls/CopyrightControl.js +89 -41
  146. package/ol/controls/RoutingControl.d.ts +180 -0
  147. package/ol/controls/RoutingControl.d.ts.map +1 -0
  148. package/ol/controls/RoutingControl.js +666 -371
  149. package/ol/controls/StopFinderControl.d.ts +32 -0
  150. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  151. package/ol/controls/StopFinderControl.js +59 -10
  152. package/ol/controls/index.d.ts +4 -0
  153. package/ol/controls/index.d.ts.map +1 -0
  154. package/ol/controls/index.js +9 -3
  155. package/ol/index.d.ts +6 -0
  156. package/ol/index.d.ts.map +1 -0
  157. package/ol/index.js +21 -5
  158. package/ol/layers/Layer.d.ts +49 -0
  159. package/ol/layers/Layer.d.ts.map +1 -0
  160. package/ol/layers/Layer.js +178 -81
  161. package/ol/layers/MapboxLayer.d.ts +42 -0
  162. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  163. package/ol/layers/MapboxLayer.js +131 -198
  164. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  165. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  166. package/ol/layers/MapboxStyleLayer.js +382 -186
  167. package/ol/layers/MaplibreLayer.d.ts +27 -0
  168. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  169. package/ol/layers/MaplibreLayer.js +67 -138
  170. package/ol/layers/RealtimeLayer.d.ts +119 -0
  171. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  172. package/ol/layers/RealtimeLayer.js +327 -184
  173. package/ol/layers/RoutingLayer.d.ts +24 -0
  174. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  175. package/ol/layers/RoutingLayer.js +111 -56
  176. package/ol/layers/VectorLayer.d.ts +23 -0
  177. package/ol/layers/VectorLayer.d.ts.map +1 -0
  178. package/ol/layers/VectorLayer.js +71 -21
  179. package/ol/layers/WMSLayer.d.ts +38 -0
  180. package/ol/layers/WMSLayer.d.ts.map +1 -0
  181. package/ol/layers/WMSLayer.js +105 -37
  182. package/ol/layers/index.d.ts +9 -0
  183. package/ol/layers/index.d.ts.map +1 -0
  184. package/ol/layers/index.js +19 -8
  185. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  186. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  187. package/ol/styles/fullTrajectoryDelayStyle.js +32 -28
  188. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  189. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  190. package/ol/styles/fullTrajectoryStyle.js +44 -40
  191. package/ol/styles/index.d.ts +3 -0
  192. package/ol/styles/index.d.ts.map +1 -0
  193. package/ol/styles/index.js +7 -2
  194. package/package.json +14 -36
  195. package/setupTests.d.ts +2 -0
  196. package/setupTests.d.ts.map +1 -0
  197. package/setupTests.js +15 -0
  198. package/types/index.d.ts +7 -6
  199. package/types/routing.d.ts +25 -25
  200. package/types/stops.d.ts +19 -19
  201. package/api/RealtimeAPI.test.js +0 -67
  202. package/api/RoutingAPI.test.js +0 -25
  203. package/api/StopsAPI.test.js +0 -22
  204. package/common/api/HttpAPI.test.js +0 -50
  205. package/common/api/WebSocketAPI.test.js +0 -311
  206. package/common/controls/Control.test.js +0 -87
  207. package/common/layers/Layer.test.js +0 -134
  208. package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
  209. package/common/utils/createTrackerFilters.test.js +0 -79
  210. package/common/utils/getMapboxMapCopyrights.test.js +0 -40
  211. package/common/utils/removeDuplicate.test.js +0 -19
  212. package/common/utils/timeUtils.test.js +0 -10
  213. package/common/utils/trackerConfig.test.js +0 -23
  214. package/mapbox/layers/Layer.test.js +0 -182
  215. package/mapbox/layers/RealtimeLayer.test.js +0 -10
  216. package/ol/controls/CopyrightControl.test.js +0 -165
  217. package/ol/controls/RoutingControl.test.js +0 -146
  218. package/ol/controls/StopFinderControl.test.js +0 -48
  219. package/ol/layers/Layer.test.js +0 -175
  220. package/ol/layers/MapboxLayer.test.js +0 -160
  221. package/ol/layers/MapboxStyleLayer.test.js +0 -226
  222. package/ol/layers/RealtimeLayer.test.js +0 -67
  223. package/ol/layers/RoutingLayer.test.js +0 -39
  224. package/ol/layers/VectorLayer.test.js +0 -76
  225. package/ol/layers/WMSLayer.test.js +0 -57
@@ -1,187 +1,330 @@
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";
9
- const format = new GeoJSON();
10
- class RealtimeLayer extends mixin(Layer) {
11
- constructor(options = {}) {
12
- super({
13
- ...options
14
- });
15
- this.olLayer = options.olLayer || new Group({
16
- layers: [
17
- new VectorLayer({
18
- source: new VectorSource({ features: [] }),
19
- style: (feature, resolution) => {
20
- return (options.fullTrajectoryStyle || fullTrajectoryStyle)(feature, resolution, this.styleOptions);
21
- }
22
- }),
23
- new OLLayer({
24
- source: new Source({}),
25
- render: (frameState) => {
26
- if (!this.container) {
27
- this.container = document.createElement("div");
28
- this.container.style.position = "absolute";
29
- this.container.style.width = "100%";
30
- this.container.style.height = "100%";
31
- this.transformContainer = document.createElement("div");
32
- this.transformContainer.style.position = "absolute";
33
- this.transformContainer.style.width = "100%";
34
- this.transformContainer.style.height = "100%";
35
- this.container.appendChild(this.transformContainer);
36
- this.canvas.style.position = "absolute";
37
- this.canvas.style.top = "0";
38
- this.canvas.style.left = "0";
39
- this.canvas.style.transformOrigin = "top left";
40
- this.transformContainer.appendChild(this.canvas);
41
- }
42
- if (this.renderedViewState) {
43
- const { center, resolution, rotation } = frameState.viewState;
44
- const {
45
- center: renderedCenter,
46
- resolution: renderedResolution,
47
- rotation: renderedRotation
48
- } = this.renderedViewState;
49
- if (renderedResolution / resolution >= 3) {
50
- const context = this.canvas.getContext("2d");
51
- context.clearRect(0, 0, this.canvas.width, this.canvas.height);
52
- } else {
53
- const pixelCenterRendered = this.map.getPixelFromCoordinate(renderedCenter);
54
- const pixelCenter = this.map.getPixelFromCoordinate(center);
55
- this.transformContainer.style.transform = composeCssTransform(pixelCenterRendered[0] - pixelCenter[0], pixelCenterRendered[1] - pixelCenter[1], renderedResolution / resolution, renderedResolution / resolution, rotation - renderedRotation, 0, 0);
56
- }
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 = '';
57
208
  }
58
- return this.container;
59
- }
60
- })
61
- ]
62
- });
63
- this.vectorLayer = this.olLayer.getLayers().item(0);
64
- this.renderState = {
65
- center: [0, 0],
66
- zoom: null,
67
- rotation: 0
68
- };
69
- }
70
- attachToMap(map) {
71
- super.attachToMap(map);
72
- if (this.map) {
73
- this.olListenersKeys.push(this.map.on(["moveend", "change:target"], (evt) => {
74
- const view = this.map.getView();
75
- if (view.getAnimating() || view.getInteracting()) {
76
- return;
77
209
  }
78
- const zoom = view.getZoom();
79
- if (this.currentZoom !== zoom) {
80
- this.onZoomEnd(evt);
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();
81
232
  }
82
- this.currentZoom = zoom;
83
- this.onMoveEnd(evt);
84
- }));
85
- }
86
- }
87
- detachFromMap() {
88
- super.detachFromMap();
89
- this.container = null;
90
- }
91
- hasFeatureInfoAtCoordinate(coordinate) {
92
- if (this.map && this.canvas) {
93
- const context = this.canvas.getContext("2d");
94
- const pixel = this.map.getPixelFromCoordinate(coordinate);
95
- return !!context.getImageData(pixel[0] * this.pixelRatio, pixel[1] * this.pixelRatio, 1, 1).data[3];
96
- }
97
- return false;
98
- }
99
- renderTrajectories(noInterpolate) {
100
- const view = this.map.getView();
101
- super.renderTrajectories({
102
- size: this.map.getSize(),
103
- center: this.map.getView().getCenter(),
104
- extent: view.calculateExtent(),
105
- resolution: view.getResolution(),
106
- rotation: view.getRotation(),
107
- zoom: view.getZoom(),
108
- pixelRatio: this.pixelRatio
109
- }, noInterpolate);
110
- }
111
- renderTrajectoriesInternal(viewState, noInterpolate) {
112
- if (!this.map) {
113
- return false;
114
- }
115
- let isRendered = false;
116
- const blockRendering = this.map.getView().getAnimating() || this.map.getView().getInteracting();
117
- isRendered = blockRendering ? false : super.renderTrajectoriesInternal(viewState, noInterpolate);
118
- if (isRendered) {
119
- this.renderedViewState = { ...viewState };
120
- if (this.transformContainer) {
121
- this.transformContainer.style.transform = "";
122
- }
123
- }
124
- return isRendered;
125
- }
126
- getRefreshTimeInMs() {
127
- return super.getRefreshTimeInMs(this.map.getView().getZoom());
128
- }
129
- getFeatureInfoAtCoordinate(coordinate, options = {}) {
130
- const resolution = this.map.getView().getResolution();
131
- return super.getFeatureInfoAtCoordinate(coordinate, {
132
- resolution,
133
- ...options
134
- });
135
- }
136
- onMoveEnd() {
137
- if (this.visible && this.isUpdateBboxOnMoveEnd) {
138
- this.setBbox();
139
- }
140
- if (this.visible && this.isUpdateBboxOnMoveEnd && this.userClickInteractions && this.selectedVehicleId) {
141
- this.highlightTrajectory(this.selectedVehicleId);
142
- }
143
- }
144
- onZoomEnd(evt) {
145
- super.onZoomEnd(evt);
146
- }
147
- onFeatureHover(features, layer, coordinate) {
148
- super.onFeatureHover(features, layer, coordinate);
149
- this.map.getTargetElement().style.cursor = features.length ? "pointer" : "auto";
150
- }
151
- onFeatureClick(features, layer, coordinate) {
152
- super.onFeatureClick(features, layer, coordinate);
153
- if (!features.length && this.vectorLayer) {
154
- this.vectorLayer.getSource().clear();
155
- }
156
- if (this.selectedVehicleId) {
157
- this.highlightTrajectory(this.selectedVehicleId);
158
- }
159
- }
160
- purgeTrajectory(trajectory, extent, zoom) {
161
- return super.purgeTrajectory(trajectory, extent || this.map.getView().calculateExtent(), zoom || this.map.getView().getZoom());
162
- }
163
- setBbox(extent, zoom) {
164
- let newExtent = extent;
165
- let newZoom = zoom;
166
- if (!newExtent && this.isUpdateBboxOnMoveEnd) {
167
- newExtent = extent || this.map.getView().calculateExtent();
168
- newZoom = Math.floor(this.map.getView().getZoom());
169
- }
170
- super.setBbox(newExtent, newZoom);
171
- }
172
- highlightTrajectory(id) {
173
- this.api.getFullTrajectory(id, this.mode, this.generalizationLevel).then((fullTrajectory) => {
174
- const vectorSource = this.vectorLayer.getSource();
175
- vectorSource.clear();
176
- if (!fullTrajectory || !fullTrajectory.features || !fullTrajectory.features.length) {
177
- return;
178
- }
179
- const features = format.readFeatures(fullTrajectory);
180
- this.vectorLayer.getSource().addFeatures(features);
181
- });
182
- }
183
- clone(newOptions) {
184
- return new RealtimeLayer({ ...this.options, ...newOptions });
185
- }
186
- }
187
- export default RealtimeLayer;
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,24 @@
1
+ export default RoutingLayer;
2
+ /**
3
+ * A class use to display vector data.
4
+ *
5
+ * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
6
+ * @extends {Layer}
7
+ */
8
+ declare class RoutingLayer extends Layer {
9
+ /**
10
+ * Constructor.
11
+ * @param {Object} [options]
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
+ */
14
+ constructor(options?: any);
15
+ olLayer: any;
16
+ /**
17
+ * Create a copy of the RoutingLayer.
18
+ * @param {Object} newOptions Options to override
19
+ * @return {RoutingLayer} A RoutingLayer
20
+ */
21
+ clone(newOptions: any): RoutingLayer;
22
+ }
23
+ import Layer from "./Layer";
24
+ //# sourceMappingURL=RoutingLayer.d.ts.map
@@ -0,0 +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"}