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,32 +1,14 @@
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
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.UserInteractionsLayerInterface = void 0;
19
1
  /* eslint-disable no-empty-function,@typescript-eslint/no-empty-function */
20
2
  /* eslint-disable no-useless-constructor,@typescript-eslint/no-useless-constructor */
21
3
  /* eslint-disable no-unused-vars,@typescript-eslint/no-unused-vars */
22
4
  /* eslint-disable class-methods-use-this */
23
5
  /* eslint-disable max-classes-per-file */
24
- var proj_1 = require("ol/proj");
25
- var Observable_1 = require("ol/Observable");
6
+ import { fromLonLat } from 'ol/proj';
7
+ import { unByKey } from 'ol/Observable';
26
8
  /**
27
9
  * UserInteractionsLayerInterface.
28
10
  */
29
- var UserInteractionsLayerInterface = /** @class */ (function () {
11
+ export class UserInteractionsLayerInterface {
30
12
  /*
31
13
  * Constructor
32
14
 
@@ -36,38 +18,34 @@ var UserInteractionsLayerInterface = /** @class */ (function () {
36
18
  * @param {string} options.userHoverInteractions If true, it listens for user mouse over event.
37
19
  * @param {string} options.defaultUserInteractions If true, it adds default listeners for user mouse hover and click event.
38
20
  */
39
- function UserInteractionsLayerInterface(options) {
40
- if (options === void 0) { options = {}; }
41
- }
21
+ constructor(options = {}) { }
42
22
  /**
43
23
  * Initialize the layer adding user interactions.
44
24
  *
45
25
  * @param {ol/Map~Map} map
46
26
  */
47
- UserInteractionsLayerInterface.prototype.attachToMap = function (map) { };
27
+ attachToMap(map) { }
48
28
  /**
49
29
  * Terminate the layer unsubscribing user interactions.
50
30
  */
51
- UserInteractionsLayerInterface.prototype.detachFromMap = function () { };
31
+ detachFromMap() { }
52
32
  /**
53
33
  * Activate map listeners events.
54
34
  */
55
- UserInteractionsLayerInterface.prototype.activateUserInteractions = function () { };
35
+ activateUserInteractions() { }
56
36
  /**
57
37
  * Deactivaet map listeners events.
58
38
  */
59
- UserInteractionsLayerInterface.prototype.deactivateUserInteractions = function () { };
39
+ deactivateUserInteractions() { }
60
40
  /**
61
41
  * Terminate the layer unsubscribing user interactions.
62
42
  */
63
- UserInteractionsLayerInterface.prototype.onClick = function (callback) { };
43
+ onClick(callback) { }
64
44
  /**
65
45
  * Terminate the layer unsubscribing user interactions.
66
46
  */
67
- UserInteractionsLayerInterface.prototype.onHover = function (callback) { };
68
- return UserInteractionsLayerInterface;
69
- }());
70
- exports.UserInteractionsLayerInterface = UserInteractionsLayerInterface;
47
+ onHover(callback) { }
48
+ }
71
49
  /**
72
50
  * Mixin for UserInteractionsLayerInterface. It provide onClick and onHover functions.
73
51
  *
@@ -75,151 +53,140 @@ exports.UserInteractionsLayerInterface = UserInteractionsLayerInterface;
75
53
  * @return {Class} A class that implements {UserInteractionsLayerInterface} class and extends Base;
76
54
  * @private
77
55
  */
78
- var UserInteractionsLayerMixin = function (Base) {
79
- return /** @class */ (function (_super) {
80
- __extends(class_1, _super);
81
- function class_1(options) {
82
- if (options === void 0) { options = {}; }
83
- var _this = _super.call(this, options) || this;
84
- var _a = options.userInteractions, userInteractions = _a === void 0 ? true : _a, _b = options.userClickInteractions, userClickInteractions = _b === void 0 ? true : _b, _c = options.userHoverInteractions, userHoverInteractions = _c === void 0 ? true : _c, _d = options.defaultUserInteractions, defaultUserInteractions = _d === void 0 ? true : _d;
85
- _this.userInteractions = userInteractions;
86
- _this.userClickInteractions = userClickInteractions;
87
- _this.userHoverInteractions = userHoverInteractions;
88
- _this.defaultUserInteractions = defaultUserInteractions;
89
- _this.userClickCallbacks = [];
90
- _this.userHoverCallbacks = [];
91
- _this.userClickEventsKeys = [];
92
- _this.userHoverEventsKeys = [];
93
- _this.onUserClickCallback = _this.onUserClickCallback.bind(_this);
94
- _this.onUserMoveCallback = _this.onUserMoveCallback.bind(_this);
95
- // Add mouse event callbacks
96
- var onClick = options.onClick, onHover = options.onHover;
97
- if (_this.userInteractions && _this.userClickInteractions && onClick) {
98
- _this.onClick(onClick);
99
- }
100
- if (_this.userInteractions && _this.userHoverInteractions && onHover) {
101
- _this.onHover(onHover);
102
- }
103
- return _this;
56
+ const UserInteractionsLayerMixin = (Base) => class extends Base {
57
+ constructor(options = {}) {
58
+ super(options);
59
+ const { userInteractions = true, userClickInteractions = true, userHoverInteractions = true, defaultUserInteractions = true, } = options;
60
+ this.userInteractions = userInteractions;
61
+ this.userClickInteractions = userClickInteractions;
62
+ this.userHoverInteractions = userHoverInteractions;
63
+ this.defaultUserInteractions = defaultUserInteractions;
64
+ this.userClickCallbacks = [];
65
+ this.userHoverCallbacks = [];
66
+ this.userClickEventsKeys = [];
67
+ this.userHoverEventsKeys = [];
68
+ this.onUserClickCallback = this.onUserClickCallback.bind(this);
69
+ this.onUserMoveCallback = this.onUserMoveCallback.bind(this);
70
+ // Add mouse event callbacks
71
+ const { onClick, onHover } = options;
72
+ if (this.userInteractions && this.userClickInteractions && onClick) {
73
+ this.onClick(onClick);
74
+ }
75
+ if (this.userInteractions && this.userHoverInteractions && onHover) {
76
+ this.onHover(onHover);
77
+ }
78
+ }
79
+ attachToMap(map, options) {
80
+ super.attachToMap(map, options);
81
+ if (this.userInteractions &&
82
+ this.defaultUserInteractions &&
83
+ this.userClickInteractions &&
84
+ this.onFeatureClick) {
85
+ this.onClick(this.onFeatureClick);
104
86
  }
105
- class_1.prototype.attachToMap = function (map, options) {
106
- _super.prototype.attachToMap.call(this, map, options);
107
- if (this.userInteractions &&
108
- this.defaultUserInteractions &&
109
- this.userClickInteractions &&
110
- this.onFeatureClick) {
111
- this.onClick(this.onFeatureClick);
112
- }
113
- if (this.userInteractions &&
114
- this.defaultUserInteractions &&
115
- this.userHoverInteractions &&
116
- this.onFeatureHover) {
117
- this.onHover(this.onFeatureHover);
118
- }
87
+ if (this.userInteractions &&
88
+ this.defaultUserInteractions &&
89
+ this.userHoverInteractions &&
90
+ this.onFeatureHover) {
91
+ this.onHover(this.onFeatureHover);
92
+ }
93
+ this.listenEvents();
94
+ }
95
+ detachFromMap() {
96
+ this.unlistenEvents();
97
+ super.detachFromMap();
98
+ }
99
+ listenEvents() {
100
+ this.unlistenEvents();
101
+ this.userClickCallbacks.forEach((callback) => {
102
+ this.userClickEventsKeys.push(this.on('user:click', ({ target: { features, layer, coordinate } }) => {
103
+ callback(features, layer, coordinate);
104
+ }));
105
+ });
106
+ this.userHoverCallbacks.forEach((callback) => {
107
+ this.userHoverEventsKeys.push(this.on('user:hover', ({ target: { features, layer, coordinate, event } }) => {
108
+ callback(features, layer, coordinate, event);
109
+ }));
110
+ });
111
+ }
112
+ unlistenEvents() {
113
+ unByKey(this.userClickEventsKeys);
114
+ unByKey(this.userHoverEventsKeys);
115
+ this.userClickEventsKeys = [];
116
+ this.userHoverEventsKeys = [];
117
+ }
118
+ /**
119
+ * Listens to click events on the layer.
120
+ * @param {function} callback Callback function, called with the clicked
121
+ * features,
122
+ * the layer instance and the click event.
123
+ */
124
+ onClick(callback) {
125
+ this.userClickCallbacks.push(callback);
126
+ this.activateUserInteractions();
127
+ if (this.map) {
128
+ // If the layer is already attached to the map we reload the events
119
129
  this.listenEvents();
130
+ }
131
+ }
132
+ /**
133
+ * Listens to hover events on the layer.
134
+ * @param {function} callback Callback function, called with the clicked
135
+ * features, the layer instance and the click event.
136
+ */
137
+ onHover(callback) {
138
+ this.userHoverCallbacks.push(callback);
139
+ this.activateUserInteractions();
140
+ if (this.map) {
141
+ // If the layer is already attached to the map we reload the events
142
+ this.listenEvents();
143
+ }
144
+ }
145
+ /**
146
+ * Function triggered when the user click the map.
147
+ * @private
148
+ */
149
+ onUserClickCallback(evt) {
150
+ const coordinate = evt.coordinate || fromLonLat(evt.lngLat.toArray());
151
+ const emptyFeatureInfo = {
152
+ features: [],
153
+ layer: this,
154
+ coordinate,
155
+ event: evt,
120
156
  };
121
- class_1.prototype.detachFromMap = function () {
122
- this.unlistenEvents();
123
- _super.prototype.detachFromMap.call(this);
124
- };
125
- class_1.prototype.listenEvents = function () {
126
- var _this = this;
127
- this.unlistenEvents();
128
- this.userClickCallbacks.forEach(function (callback) {
129
- _this.userClickEventsKeys.push(_this.on('user:click', function (_a) {
130
- var _b = _a.target, features = _b.features, layer = _b.layer, coordinate = _b.coordinate;
131
- callback(features, layer, coordinate);
132
- }));
133
- });
134
- this.userHoverCallbacks.forEach(function (callback) {
135
- _this.userHoverEventsKeys.push(_this.on('user:hover', function (_a) {
136
- var _b = _a.target, features = _b.features, layer = _b.layer, coordinate = _b.coordinate, event = _b.event;
137
- callback(features, layer, coordinate, event);
138
- }));
157
+ return this.getFeatureInfoAtCoordinate(coordinate)
158
+ .then((featureInfo) => {
159
+ this.dispatchEvent({
160
+ type: 'user:click',
161
+ target: featureInfo,
139
162
  });
163
+ return featureInfo;
164
+ })
165
+ .catch(() => emptyFeatureInfo);
166
+ }
167
+ /**
168
+ * Function triggered when the user move the cursor.
169
+ * @private
170
+ */
171
+ onUserMoveCallback(evt) {
172
+ const coordinate = evt.coordinate || fromLonLat(evt.lngLat.toArray());
173
+ const emptyFeatureInfo = {
174
+ features: [],
175
+ layer: this,
176
+ coordinate,
177
+ event: evt,
140
178
  };
141
- class_1.prototype.unlistenEvents = function () {
142
- (0, Observable_1.unByKey)(this.userClickEventsKeys);
143
- (0, Observable_1.unByKey)(this.userHoverEventsKeys);
144
- this.userClickEventsKeys = [];
145
- this.userHoverEventsKeys = [];
146
- };
147
- /**
148
- * Listens to click events on the layer.
149
- * @param {function} callback Callback function, called with the clicked
150
- * features,
151
- * the layer instance and the click event.
152
- */
153
- class_1.prototype.onClick = function (callback) {
154
- this.userClickCallbacks.push(callback);
155
- this.activateUserInteractions();
156
- if (this.map) {
157
- // If the layer is already attached to the map we reload the events
158
- this.listenEvents();
159
- }
160
- };
161
- /**
162
- * Listens to hover events on the layer.
163
- * @param {function} callback Callback function, called with the clicked
164
- * features, the layer instance and the click event.
165
- */
166
- class_1.prototype.onHover = function (callback) {
167
- this.userHoverCallbacks.push(callback);
168
- this.activateUserInteractions();
169
- if (this.map) {
170
- // If the layer is already attached to the map we reload the events
171
- this.listenEvents();
172
- }
173
- };
174
- /**
175
- * Function triggered when the user click the map.
176
- * @private
177
- */
178
- class_1.prototype.onUserClickCallback = function (evt) {
179
- var _this = this;
180
- var coordinate = evt.coordinate || (0, proj_1.fromLonLat)(evt.lngLat.toArray());
181
- var emptyFeatureInfo = {
182
- features: [],
183
- layer: this,
184
- coordinate: coordinate,
185
- event: evt,
186
- };
187
- return this.getFeatureInfoAtCoordinate(coordinate)
188
- .then(function (featureInfo) {
189
- _this.dispatchEvent({
190
- type: 'user:click',
191
- target: featureInfo,
192
- });
193
- return featureInfo;
194
- })
195
- .catch(function () { return emptyFeatureInfo; });
196
- };
197
- /**
198
- * Function triggered when the user move the cursor.
199
- * @private
200
- */
201
- class_1.prototype.onUserMoveCallback = function (evt) {
202
- var _this = this;
203
- var coordinate = evt.coordinate || (0, proj_1.fromLonLat)(evt.lngLat.toArray());
204
- var emptyFeatureInfo = {
205
- features: [],
206
- layer: this,
207
- coordinate: coordinate,
208
- event: evt,
209
- };
210
- return this.getFeatureInfoAtCoordinate(coordinate)
211
- .then(function (featureInfo) {
212
- _this.dispatchEvent({
213
- type: 'user:hover',
214
- target: featureInfo,
215
- });
216
- return featureInfo;
217
- })
218
- .catch(function () { return emptyFeatureInfo; });
219
- };
220
- class_1.prototype.activateUserInteractions = function () { };
221
- class_1.prototype.deactivateUserInteractions = function () { };
222
- return class_1;
223
- }(Base));
179
+ return this.getFeatureInfoAtCoordinate(coordinate)
180
+ .then((featureInfo) => {
181
+ this.dispatchEvent({
182
+ type: 'user:hover',
183
+ target: featureInfo,
184
+ });
185
+ return featureInfo;
186
+ })
187
+ .catch(() => emptyFeatureInfo);
188
+ }
189
+ activateUserInteractions() { }
190
+ deactivateUserInteractions() { }
224
191
  };
225
- exports.default = UserInteractionsLayerMixin;
192
+ export default UserInteractionsLayerMixin;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=UserInteractionsLayerMixin.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"UserInteractionsLayerMixin.test.d.ts","sourceRoot":"","sources":["../../../src/common/mixins/UserInteractionsLayerMixin.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,214 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import VectorLayer from 'ol/layer/Vector';
11
+ import VectorSource from 'ol/source/Vector';
12
+ import BaseLayer from '../layers/Layer';
13
+ import mixin from './UserInteractionsLayerMixin';
14
+ const olLayer = new VectorLayer({ source: new VectorSource() });
15
+ const Layer = mixin(BaseLayer);
16
+ describe('Layer', () => {
17
+ test('should initialize.', () => {
18
+ const layer = new Layer();
19
+ expect(layer).toBeInstanceOf(Layer);
20
+ });
21
+ test('should define default properties.', () => {
22
+ const layer = new Layer();
23
+ expect(layer).toBeInstanceOf(Layer);
24
+ expect(layer.userInteractions).toEqual(true);
25
+ expect(layer.userClickInteractions).toEqual(true);
26
+ expect(layer.userHoverInteractions).toEqual(true);
27
+ expect(layer.defaultUserInteractions).toBe(true);
28
+ expect(layer.userClickCallbacks).toEqual([]);
29
+ expect(layer.userHoverCallbacks).toEqual([]);
30
+ expect(layer.userClickEventsKeys).toEqual([]);
31
+ expect(layer.userHoverEventsKeys).toEqual([]);
32
+ });
33
+ test('should set userInteractionsXXX to false.', () => {
34
+ const options = {
35
+ userInteractions: false,
36
+ userClickInteractions: false,
37
+ userHoverInteractions: false,
38
+ defaultUserInteractions: false,
39
+ };
40
+ const layer = new Layer(options);
41
+ expect(layer).toBeInstanceOf(Layer);
42
+ expect(layer.userInteractions).toBe(false);
43
+ expect(layer.userClickInteractions).toBe(false);
44
+ expect(layer.userHoverInteractions).toBe(false);
45
+ expect(layer.defaultUserInteractions).toBe(false);
46
+ });
47
+ test('should set onClick using constructor', () => {
48
+ const fn = () => { };
49
+ const layer = new Layer({
50
+ onClick: fn,
51
+ onHover: fn,
52
+ });
53
+ expect(layer.userClickCallbacks[0]).toBe(fn);
54
+ expect(layer.userHoverCallbacks[0]).toBe(fn);
55
+ expect(layer.userClickEventsKeys.length).toBe(0);
56
+ expect(layer.userHoverEventsKeys.length).toBe(0);
57
+ });
58
+ describe('#attachToMap()', () => {
59
+ test('should not add events if no callbacks', () => {
60
+ const layer = new Layer({
61
+ olLayer,
62
+ });
63
+ expect(layer.map).toBe(undefined);
64
+ const obj = {};
65
+ layer.attachToMap(obj);
66
+ expect(layer.userClickEventsKeys.length).toBe(0);
67
+ expect(layer.userHoverEventsKeys.length).toBe(0);
68
+ });
69
+ test('should add events', () => {
70
+ const fn = () => { };
71
+ const layer = new Layer({
72
+ olLayer,
73
+ onClick: fn,
74
+ onHover: fn,
75
+ });
76
+ expect(layer.map).toBe(undefined);
77
+ const obj = {};
78
+ layer.attachToMap(obj);
79
+ expect(layer.userClickEventsKeys.length).toBe(1);
80
+ expect(layer.userHoverEventsKeys.length).toBe(1);
81
+ });
82
+ });
83
+ describe('#onClick()', () => {
84
+ test('adds function to callback array', () => {
85
+ const layer = new Layer();
86
+ const fn = jest.fn();
87
+ const fn2 = jest.fn();
88
+ layer.onClick(fn);
89
+ expect(layer.userClickCallbacks).toEqual([fn]);
90
+ layer.onClick(fn2);
91
+ expect(layer.userClickCallbacks).toEqual([fn, fn2]);
92
+ expect(layer.userClickEventsKeys.length).toBe(0);
93
+ layer.attachToMap({});
94
+ expect(layer.userClickEventsKeys.length).toBe(2);
95
+ });
96
+ });
97
+ describe('#onHover()', () => {
98
+ test('adds function to callback array', () => {
99
+ const layer = new Layer();
100
+ const fn = jest.fn();
101
+ const fn2 = jest.fn();
102
+ layer.onHover(fn);
103
+ expect(layer.userHoverCallbacks).toEqual([fn]);
104
+ layer.onHover(fn2);
105
+ expect(layer.userHoverCallbacks).toEqual([fn, fn2]);
106
+ expect(layer.userHoverEventsKeys.length).toBe(0);
107
+ layer.attachToMap({});
108
+ expect(layer.userHoverEventsKeys.length).toBe(2);
109
+ });
110
+ });
111
+ describe('#onUserClickCallback()', () => {
112
+ const evt = { type: 'signleclick', coordinate: [0, 0] };
113
+ const getFeatureInfo = (layer, features = []) => ({
114
+ features,
115
+ layer,
116
+ coordinate: evt.coordinate,
117
+ event: evt,
118
+ });
119
+ test('calls click callback functions', (done) => __awaiter(void 0, void 0, void 0, function* () {
120
+ const layer = new Layer();
121
+ const goodFeatureInfo = getFeatureInfo(layer, [{ name: 'test' }]);
122
+ const fn = jest.fn();
123
+ const fn2 = jest.fn();
124
+ const spy = jest
125
+ .spyOn(layer, 'getFeatureInfoAtCoordinate')
126
+ .mockResolvedValue(goodFeatureInfo);
127
+ layer.onClick(fn);
128
+ layer.onClick(fn2);
129
+ layer.attachToMap({});
130
+ layer.onUserClickCallback(evt).then((featureInfo) => {
131
+ expect(spy).toHaveBeenCalledTimes(1);
132
+ expect(spy).toHaveBeenCalledWith(evt.coordinate);
133
+ expect(featureInfo).toBe(goodFeatureInfo);
134
+ expect(fn).toHaveBeenCalledTimes(1);
135
+ expect(fn.mock.calls[0][0]).toBe(goodFeatureInfo.features);
136
+ expect(fn.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
137
+ expect(fn.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
138
+ expect(fn2).toHaveBeenCalledTimes(1);
139
+ expect(fn2.mock.calls[0][0]).toBe(goodFeatureInfo.features);
140
+ expect(fn2.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
141
+ expect(fn2.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
142
+ done();
143
+ });
144
+ }));
145
+ describe('returns empty feature info', () => {
146
+ test('if an error is thrown in click callback', (done) => {
147
+ const layer = new Layer();
148
+ layer.onClick(() => {
149
+ throw new Error('foo');
150
+ });
151
+ const goodFeatureInfo = getFeatureInfo(layer, [{ name: 'test' }]);
152
+ jest
153
+ .spyOn(layer, 'getFeatureInfoAtCoordinate')
154
+ .mockResolvedValue(goodFeatureInfo);
155
+ layer.attachToMap({});
156
+ layer.onUserClickCallback(evt).then((featureInfo) => {
157
+ expect(featureInfo).toEqual(getFeatureInfo(layer));
158
+ done();
159
+ });
160
+ });
161
+ });
162
+ });
163
+ describe('#onUserMoveCallback()', () => {
164
+ const evt = { type: 'pointermove', coordinate: [0, 0] };
165
+ const getFeatureInfo = (layer, features = []) => ({
166
+ features,
167
+ layer,
168
+ coordinate: evt.coordinate,
169
+ event: evt,
170
+ });
171
+ test('calls hover callback functions', (done) => {
172
+ const layer = new Layer();
173
+ const goodFeatureInfo = getFeatureInfo(layer, [{ name: 'test' }]);
174
+ const fn = jest.fn();
175
+ const fn2 = jest.fn();
176
+ const spy = jest
177
+ .spyOn(layer, 'getFeatureInfoAtCoordinate')
178
+ .mockResolvedValue(goodFeatureInfo);
179
+ layer.onHover(fn);
180
+ layer.onHover(fn2);
181
+ layer.attachToMap({});
182
+ layer.onUserMoveCallback(evt).then((featureInfo) => {
183
+ expect(spy).toHaveBeenCalledTimes(1);
184
+ expect(spy).toHaveBeenCalledWith(evt.coordinate);
185
+ expect(featureInfo).toBe(goodFeatureInfo);
186
+ expect(fn).toHaveBeenCalledTimes(1);
187
+ expect(fn.mock.calls[0][0]).toBe(goodFeatureInfo.features);
188
+ expect(fn.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
189
+ expect(fn.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
190
+ expect(fn2).toHaveBeenCalledTimes(1);
191
+ expect(fn2.mock.calls[0][0]).toBe(goodFeatureInfo.features);
192
+ expect(fn2.mock.calls[0][1]).toBe(goodFeatureInfo.layer);
193
+ expect(fn2.mock.calls[0][2]).toBe(goodFeatureInfo.coordinate);
194
+ done();
195
+ });
196
+ });
197
+ describe('returns empty feature info', () => {
198
+ test('if an error is thrown in hover callback', (done) => {
199
+ const layer = new Layer();
200
+ layer.onHover(() => {
201
+ throw new Error('foo');
202
+ });
203
+ jest
204
+ .spyOn(layer, 'getFeatureInfoAtCoordinate')
205
+ .mockResolvedValue(getFeatureInfo(layer, [{ name: 'test' }]));
206
+ layer.attachToMap({});
207
+ layer.onUserMoveCallback(evt).then((featureInfo) => {
208
+ expect(featureInfo).toEqual(getFeatureInfo(layer));
209
+ done();
210
+ });
211
+ });
212
+ });
213
+ });
214
+ });
@@ -1,24 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.realtimeSimpleStyle = exports.realtimeDelayStyle = exports.realtimeDefaultStyle = void 0;
18
- var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
19
- Object.defineProperty(exports, "realtimeDefaultStyle", { enumerable: true, get: function () { return realtimeDefaultStyle_1.default; } });
20
- var realtimeDelayStyle_1 = require("./realtimeDelayStyle");
21
- Object.defineProperty(exports, "realtimeDelayStyle", { enumerable: true, get: function () { return realtimeDelayStyle_1.default; } });
22
- var realtimeSimpleStyle_1 = require("./realtimeSimpleStyle");
23
- Object.defineProperty(exports, "realtimeSimpleStyle", { enumerable: true, get: function () { return realtimeSimpleStyle_1.default; } });
24
- __exportStar(require("./realtimeDefaultStyle"), exports);
1
+ export { default as realtimeDefaultStyle } from './realtimeDefaultStyle';
2
+ export { default as realtimeDelayStyle } from './realtimeDelayStyle';
3
+ export { default as realtimeSimpleStyle } from './realtimeSimpleStyle';
4
+ export * from './realtimeDefaultStyle';
@@ -1 +1 @@
1
- {"version":3,"file":"realtimeDefaultStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDefaultStyle.js"],"names":[],"mappings":"AAUO,4EAeN;AAUM,2JA2BN;AAUM,0HAoCN;AAUM,6IAuCN;;AAKD;;;;;;;GAOG;AACH,0FAgMC"}
1
+ {"version":3,"file":"realtimeDefaultStyle.d.ts","sourceRoot":"","sources":["../../../src/common/styles/realtimeDefaultStyle.js"],"names":[],"mappings":"AAUO,4EAeN;AAUM,2JA2BN;AAUM,0HAoCN;AAUM,6IAuCN;;AAKD;;;;;;;GAOG;AACH,0FA8LC"}