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
@@ -0,0 +1,196 @@
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 Map from 'ol/Map';
13
+ import Group from 'ol/layer/Group';
14
+ import Layer from './Layer';
15
+ let olLayer;
16
+ let map;
17
+ describe('Layer', () => {
18
+ beforeEach(() => {
19
+ map = new Map({});
20
+ olLayer = new VectorLayer({ source: new VectorSource() });
21
+ });
22
+ test('should initialize.', () => {
23
+ const layer = new Layer({ name: 'Layer', olLayer });
24
+ expect(layer).toBeInstanceOf(Layer);
25
+ });
26
+ test('should be visible by default.', () => {
27
+ const layer = new Layer({ name: 'Layer', olLayer });
28
+ expect(layer.visible).toBe(true);
29
+ });
30
+ test('should be invisible if defined.', () => {
31
+ const layer = new Layer({ name: 'Layer', visible: false, olLayer });
32
+ expect(layer.visible).toBe(false);
33
+ });
34
+ test('should be invisible if set.', () => {
35
+ const layer = new Layer({ name: 'Layer', olLayer });
36
+ layer.visible = false;
37
+ expect(layer.visible).toBe(false);
38
+ });
39
+ test('should visibility stay unchanged', () => {
40
+ const layer = new Layer({ name: 'Layer', visible: false, olLayer });
41
+ layer.visible = false;
42
+ expect(layer.visible).toBe(false);
43
+ });
44
+ test('should return its name.', () => {
45
+ const layer = new Layer({ name: 'Layer', visible: false, olLayer });
46
+ expect(layer.name).toEqual('Layer');
47
+ });
48
+ test('should call terminate on initialization.', () => {
49
+ const layer = new Layer({ name: 'Layer', olLayer });
50
+ const spy = jest.spyOn(layer, 'detachFromMap');
51
+ layer.attachToMap();
52
+ expect(spy).toHaveBeenCalledTimes(1);
53
+ });
54
+ test('should remove the layer when we call terminate.', () => {
55
+ const layer = new Layer({ name: 'Layer', olLayer });
56
+ const spy = jest.spyOn(layer, 'detachFromMap');
57
+ layer.attachToMap(map);
58
+ expect(spy).toHaveBeenCalledTimes(1);
59
+ layer.detachFromMap(map);
60
+ expect(spy).toHaveBeenCalledTimes(2);
61
+ });
62
+ test('should manage copyrights as string.', () => {
63
+ const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
64
+ const layer = new Layer({ name: 'Layer', copyrights: 'foo', olLayer });
65
+ layer.attachToMap(map);
66
+ expect(spy).toHaveBeenCalledWith(['foo']);
67
+ });
68
+ test('should manage copyrights as array.', () => {
69
+ const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
70
+ const layer = new Layer({ name: 'Layer', copyrights: ['bar'], olLayer });
71
+ layer.attachToMap(map);
72
+ expect(spy).toHaveBeenCalledWith(['bar']);
73
+ });
74
+ test('should set attributions for Group.', () => {
75
+ const spy = jest.spyOn(VectorSource.prototype, 'setAttributions');
76
+ const layer = new Layer({
77
+ name: 'Layer',
78
+ copyrights: ['bar'],
79
+ olLayer: new Group({ layers: [olLayer] }),
80
+ });
81
+ layer.attachToMap(map);
82
+ expect(spy).toHaveBeenCalledWith(['bar']);
83
+ });
84
+ test('should listen for click/hover events when layer is visible by default then should not when hidden.', () => __awaiter(void 0, void 0, void 0, function* () {
85
+ global.console.error = jest.fn();
86
+ const layer = new Layer({ name: 'Layer', olLayer });
87
+ expect(layer.visible).toBe(true);
88
+ const spy = jest.fn();
89
+ const spy2 = jest.fn();
90
+ layer.onHover(spy);
91
+ layer.onClick(spy2);
92
+ layer.attachToMap(map);
93
+ expect(spy).toHaveBeenCalledTimes(0);
94
+ expect(spy2).toHaveBeenCalledTimes(0);
95
+ yield map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
96
+ yield map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
97
+ expect(spy).toHaveBeenCalledTimes(1);
98
+ expect(spy2).toHaveBeenCalledTimes(1);
99
+ spy.mockReset();
100
+ spy2.mockReset();
101
+ layer.visible = false;
102
+ yield map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
103
+ yield map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
104
+ expect(spy).toHaveBeenCalledTimes(0);
105
+ expect(spy2).toHaveBeenCalledTimes(0);
106
+ global.console.error.mockRestore();
107
+ }));
108
+ test('should not listen for click/hover events when layer is not visible by default then should not when visible.', () => __awaiter(void 0, void 0, void 0, function* () {
109
+ global.console.error = jest.fn();
110
+ const layer = new Layer({ name: 'Layer', olLayer, visible: false });
111
+ expect(layer.visible).toBe(false);
112
+ const spy = jest.fn();
113
+ const spy2 = jest.fn();
114
+ layer.onHover(spy);
115
+ layer.onClick(spy2);
116
+ layer.attachToMap(map);
117
+ expect(spy).toHaveBeenCalledTimes(0);
118
+ expect(spy2).toHaveBeenCalledTimes(0);
119
+ yield map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
120
+ yield map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
121
+ expect(spy).toHaveBeenCalledTimes(0);
122
+ expect(spy2).toHaveBeenCalledTimes(0);
123
+ spy.mockReset();
124
+ spy2.mockReset();
125
+ layer.visible = true;
126
+ yield map.dispatchEvent({ type: 'pointermove', map, coordinate: [0, 0] });
127
+ yield map.dispatchEvent({ type: 'singleclick', map, coordinate: [0, 0] });
128
+ expect(spy).toHaveBeenCalledTimes(1);
129
+ expect(spy2).toHaveBeenCalledTimes(1);
130
+ global.console.error.mockRestore();
131
+ }));
132
+ test('should not listen for click/hover events after layer.detachFromMap()', () => __awaiter(void 0, void 0, void 0, function* () {
133
+ global.console.error = jest.fn();
134
+ const layer = new Layer({ name: 'Layer', olLayer, visible: true });
135
+ expect(layer.visible).toBe(true);
136
+ const spy = jest.fn();
137
+ const spy2 = jest.fn();
138
+ const spy3 = jest.fn();
139
+ const spy4 = jest.fn();
140
+ layer.onHover(spy);
141
+ layer.onClick(spy2);
142
+ layer.attachToMap(map);
143
+ // Test event after attached to map
144
+ layer.onHover(spy3);
145
+ layer.onClick(spy4);
146
+ expect(spy).toHaveBeenCalledTimes(0);
147
+ expect(spy2).toHaveBeenCalledTimes(0);
148
+ expect(spy3).toHaveBeenCalledTimes(0);
149
+ expect(spy4).toHaveBeenCalledTimes(0);
150
+ yield map.dispatchEvent({
151
+ type: 'pointermove',
152
+ map,
153
+ coordinate: [0, 0],
154
+ });
155
+ yield map.dispatchEvent({
156
+ type: 'singleclick',
157
+ map,
158
+ coordinate: [0, 0],
159
+ });
160
+ expect(spy).toHaveBeenCalledTimes(1);
161
+ expect(spy2).toHaveBeenCalledTimes(1);
162
+ expect(spy3).toHaveBeenCalledTimes(1);
163
+ expect(spy4).toHaveBeenCalledTimes(1);
164
+ spy.mockReset();
165
+ spy2.mockReset();
166
+ spy3.mockReset();
167
+ spy4.mockReset();
168
+ layer.detachFromMap(map);
169
+ yield map.dispatchEvent({
170
+ type: 'pointermove',
171
+ map,
172
+ coordinate: [0, 0],
173
+ });
174
+ yield map.dispatchEvent({
175
+ type: 'singleclick',
176
+ map,
177
+ coordinate: [0, 0],
178
+ });
179
+ expect(spy).toHaveBeenCalledTimes(0);
180
+ expect(spy2).toHaveBeenCalledTimes(0);
181
+ expect(spy3).toHaveBeenCalledTimes(0);
182
+ expect(spy4).toHaveBeenCalledTimes(0);
183
+ global.console.error.mockRestore();
184
+ }));
185
+ test('should clone', () => {
186
+ const layer = new Layer({
187
+ name: 'Layer',
188
+ copyrights: ['bar'],
189
+ olLayer: new Group({ layers: [olLayer] }),
190
+ });
191
+ const clone = layer.clone({ name: 'clone' });
192
+ expect(clone).not.toBe(layer);
193
+ expect(clone.name).toBe('clone');
194
+ expect(clone).toBeInstanceOf(Layer);
195
+ });
196
+ });
@@ -21,14 +21,14 @@ export default class MapboxLayer extends Layer {
21
21
  /** @ignore */
22
22
  renderState: {
23
23
  center: any[];
24
- zoom: any;
25
- rotation: any;
26
- visible: any;
27
- opacity: any;
24
+ zoom: null;
25
+ rotation: null;
26
+ visible: null;
27
+ opacity: null;
28
28
  size: number[];
29
- };
29
+ } | undefined;
30
30
  /** @ignore */
31
- copyrights: any[];
31
+ copyrights: any[] | undefined;
32
32
  getOlLayerRender(): (frameState: any) => any;
33
33
  getMapboxMapClass(): any;
34
34
  /**
@@ -36,7 +36,7 @@ export default class MapboxLayer extends Layer {
36
36
  * @param {Object} newOptions Options to override
37
37
  * @return {MapboxLayer} A MapboxLayer
38
38
  */
39
- clone(newOptions: any): MapboxLayer;
39
+ clone(newOptions: Object): MapboxLayer;
40
40
  }
41
41
  import Layer from "./Layer";
42
42
  //# sourceMappingURL=MapboxLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxLayer.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH;IA2BE;;;OAGG;IACH,kBA0CC;IA/BC,cAAc;IACd;;;;;;;MAOC;IAOC,cAAc;IACd,kBAA0D;IAiB9D,6CAEC;IAGD,yBAEC;IAED;;;;OAIG;IACH,wBAFY,WAAW,CAItB;CACF"}
1
+ {"version":3,"file":"MapboxLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxLayer.js"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH;IA2BE;;;OAGG;IACH,kBA0CC;IA/BC,cAAc;IACd;;;;;;;kBAOC;IAOC,cAAc;IACd,8BAA0D;IAiB9D,6CAEC;IAGD,yBAEC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,WAAW,CAItB;CACF"}
@@ -1,36 +1,8 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
1
  /* eslint-disable no-underscore-dangle */
30
- var mapbox_gl_1 = require("mapbox-gl");
31
- var Layer_1 = require("./Layer");
32
- var MapboxLayerMixin_1 = require("../../common/mixins/MapboxLayerMixin");
33
- var utils_1 = require("../../common/utils");
2
+ import { Map } from 'mapbox-gl';
3
+ import Layer from './Layer';
4
+ import mixin from '../../common/mixins/MapboxLayerMixin';
5
+ import { getMapboxMapCopyrights, getMapboxRender } from '../../common/utils';
34
6
  /**
35
7
  * A class representing Mapboxlayer to display on BasicMap
36
8
  *
@@ -45,25 +17,20 @@ var utils_1 = require("../../common/utils");
45
17
  * @classproperty {ol/Map~Map} map - The map where the layer is displayed.
46
18
  * @extends {Layer}
47
19
  */
48
- var MapboxLayer = /** @class */ (function (_super) {
49
- __extends(MapboxLayer, _super);
50
- function MapboxLayer() {
51
- return _super !== null && _super.apply(this, arguments) || this;
52
- }
20
+ export default class MapboxLayer extends mixin(Layer) {
53
21
  /**
54
22
  * Initialize the layer and listen to feature clicks.
55
23
  * @param {ol/Map~Map} map
56
24
  */
57
- MapboxLayer.prototype.attachToMap = function (map) {
58
- var _this = this;
59
- _super.prototype.attachToMap.call(this, map);
25
+ attachToMap(map) {
26
+ super.attachToMap(map);
60
27
  if (!this.map || this.mbMap) {
61
28
  return;
62
29
  }
63
- this.olListenersKeys.push(this.map.on('change:size', function () {
30
+ this.olListenersKeys.push(this.map.on('change:size', () => {
64
31
  try {
65
- if (_this.mbMap) {
66
- _this.mbMap.resize();
32
+ if (this.mbMap) {
33
+ this.mbMap.resize();
67
34
  }
68
35
  }
69
36
  catch (err) {
@@ -72,16 +39,15 @@ var MapboxLayer = /** @class */ (function (_super) {
72
39
  console.warn(err);
73
40
  }
74
41
  }));
75
- };
42
+ }
76
43
  /**
77
44
  * Create the mapbox map.
78
45
  * @private
79
46
  */
80
- MapboxLayer.prototype.loadMbMap = function () {
81
- var _this = this;
47
+ loadMbMap() {
82
48
  // If the map hasn't been resized, the center could be [NaN,NaN].
83
49
  // We set default good value for the mapbox map, to avoid the app crashes.
84
- var _a = this.map.getView().getCenter(), x = _a[0], y = _a[1];
50
+ let [x, y] = this.map.getView().getCenter();
85
51
  if (!x || !y) {
86
52
  x = 0;
87
53
  y = 0;
@@ -97,15 +63,15 @@ var MapboxLayer = /** @class */ (function (_super) {
97
63
  opacity: null,
98
64
  size: [0, 0],
99
65
  };
100
- _super.prototype.loadMbMap.call(this);
101
- this.mbMap.once('load', function () {
66
+ super.loadMbMap();
67
+ this.mbMap.once('load', () => {
102
68
  var _a;
103
- _this.mbMap.resize();
69
+ this.mbMap.resize();
104
70
  /** @ignore */
105
- _this.copyrights = (0, utils_1.getMapboxMapCopyrights)(_this.mbMap) || [];
106
- (_a = _this.olLayer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(_this.copyrights);
71
+ this.copyrights = getMapboxMapCopyrights(this.mbMap) || [];
72
+ (_a = this.olLayer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(this.copyrights);
107
73
  });
108
- var mapboxCanvas = this.mbMap.getCanvas();
74
+ const mapboxCanvas = this.mbMap.getCanvas();
109
75
  if (mapboxCanvas) {
110
76
  if (this.options.tabIndex) {
111
77
  mapboxCanvas.setAttribute('tabindex', this.options.tabIndex);
@@ -116,22 +82,20 @@ var MapboxLayer = /** @class */ (function (_super) {
116
82
  mapboxCanvas.removeAttribute('tabindex');
117
83
  }
118
84
  }
119
- };
120
- MapboxLayer.prototype.getOlLayerRender = function () {
121
- return (0, utils_1.getMapboxRender)(this);
122
- };
85
+ }
86
+ getOlLayerRender() {
87
+ return getMapboxRender(this);
88
+ }
123
89
  // eslint-disable-next-line class-methods-use-this
124
- MapboxLayer.prototype.getMapboxMapClass = function () {
125
- return mapbox_gl_1.Map;
126
- };
90
+ getMapboxMapClass() {
91
+ return Map;
92
+ }
127
93
  /**
128
94
  * Create a copy of the MapboxLayer.
129
95
  * @param {Object} newOptions Options to override
130
96
  * @return {MapboxLayer} A MapboxLayer
131
97
  */
132
- MapboxLayer.prototype.clone = function (newOptions) {
133
- return new MapboxLayer(__assign(__assign({}, this.options), newOptions));
134
- };
135
- return MapboxLayer;
136
- }((0, MapboxLayerMixin_1.default)(Layer_1.default)));
137
- exports.default = MapboxLayer;
98
+ clone(newOptions) {
99
+ return new MapboxLayer(Object.assign(Object.assign({}, this.options), newOptions));
100
+ }
101
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=MapboxLayer.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MapboxLayer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxLayer.test.js"],"names":[],"mappings":""}
@@ -0,0 +1,164 @@
1
+ import OlMap from 'ol/Map';
2
+ import View from 'ol/View';
3
+ import gllib from 'mapbox-gl';
4
+ import MapboxLayer from './MapboxLayer';
5
+ let layer;
6
+ let map;
7
+ let consoleOutput;
8
+ const styleUrl = 'http://foo.com/styles';
9
+ describe('MapboxLayer', () => {
10
+ describe('without apiKey', () => {
11
+ beforeEach(() => {
12
+ // Mock console statement
13
+ consoleOutput = [];
14
+ // eslint-disable-next-line no-console
15
+ console.error = (message) => consoleOutput.push(message);
16
+ layer = new MapboxLayer({
17
+ name: 'Layer',
18
+ url: styleUrl,
19
+ });
20
+ map = new OlMap({
21
+ target: document.createElement('div'),
22
+ view: new View({ center: [0, 0] }),
23
+ });
24
+ });
25
+ test('should be instanced.', () => {
26
+ expect(layer).toBeInstanceOf(MapboxLayer);
27
+ expect(layer.styleUrl).toBe(styleUrl);
28
+ });
29
+ test('should not initalized mapbox map.', () => {
30
+ layer.attachToMap();
31
+ expect(layer.mbMap).toBe();
32
+ });
33
+ test('should initalized mapbox map and warn the user if there is no api key defined.', () => {
34
+ layer.attachToMap(map);
35
+ expect(layer.mbMap).toBeInstanceOf(gllib.Map);
36
+ expect(consoleOutput[0]).toBe('No apiKey defined for mapbox layer with style url to http://foo.com/styles');
37
+ });
38
+ test('should called terminate on initalization.', () => {
39
+ const spy = jest.spyOn(layer, 'detachFromMap');
40
+ layer.attachToMap();
41
+ expect(spy).toHaveBeenCalledTimes(1);
42
+ });
43
+ test('should clone', () => {
44
+ const clone = layer.clone({ name: 'clone' });
45
+ expect(clone).not.toBe(layer);
46
+ expect(clone.name).toBe('clone');
47
+ expect(clone).toBeInstanceOf(MapboxLayer);
48
+ });
49
+ });
50
+ describe('with apiKey', () => {
51
+ beforeEach(() => {
52
+ layer = new MapboxLayer({
53
+ name: 'Layer',
54
+ url: styleUrl,
55
+ apiKey: 'apiKey',
56
+ });
57
+ map = new OlMap({
58
+ target: document.createElement('div'),
59
+ view: new View({ center: [0, 0] }),
60
+ });
61
+ });
62
+ test('should be instanced with apiKey.', () => {
63
+ expect(layer).toBeInstanceOf(MapboxLayer);
64
+ expect(layer.styleUrl).toBe(styleUrl);
65
+ });
66
+ test('should not initalized mapbox map.', () => {
67
+ layer.attachToMap();
68
+ expect(layer.mbMap).toBe();
69
+ });
70
+ test("should initalized mapbox map, with 'apiKey' prop", () => {
71
+ const layer1 = new MapboxLayer({
72
+ name: 'Layer',
73
+ url: styleUrl,
74
+ apiKey: 'apiKeyVal',
75
+ });
76
+ layer1.attachToMap(map);
77
+ expect(layer1.mbMap.options.style).toBe('http://foo.com/styles?key=apiKeyVal');
78
+ });
79
+ test("should initalized mapbox map, with 'apiKeyName' prop", () => {
80
+ const layer1 = new MapboxLayer({
81
+ name: 'Layer',
82
+ url: styleUrl,
83
+ apiKey: 'test',
84
+ apiKeyName: 'apiKey',
85
+ });
86
+ layer1.attachToMap(map);
87
+ expect(layer1.mbMap.options.style).toBe('http://foo.com/styles?apiKey=test');
88
+ });
89
+ });
90
+ describe('#getFeatureInfoAtCoordinate()', () => {
91
+ let layer1;
92
+ beforeEach(() => {
93
+ layer1 = new MapboxLayer({
94
+ name: 'Layer',
95
+ url: styleUrl,
96
+ apiKey: 'test',
97
+ apiKeyName: 'apiKey',
98
+ });
99
+ layer1.attachToMap(map);
100
+ layer1.mbMap.isStyleLoaded = jest.fn(() => true);
101
+ layer1.mbMap.getSource = jest.fn(() => true);
102
+ });
103
+ afterEach(() => {
104
+ layer1.mbMap.getSource.mockRestore();
105
+ layer1.mbMap.isStyleLoaded.mockRestore();
106
+ });
107
+ test('should set the mapboxFeature as a property', (done) => {
108
+ const mapboxFeature = {
109
+ id: '2',
110
+ type: 'Feature',
111
+ properties: {
112
+ foo: 'bar',
113
+ },
114
+ source: 'barr',
115
+ sourceLayer: 'fooo',
116
+ };
117
+ layer1.mbMap.project = jest.fn((coord) => ({ x: coord[0], y: coord[1] }));
118
+ layer1.mbMap.queryRenderedFeatures = jest.fn(() => [mapboxFeature]);
119
+ layer1.getFeatureInfoAtCoordinate([0, 0], {}).then((featureInfo) => {
120
+ expect(featureInfo.features[0].get('mapboxFeature')).toBe(mapboxFeature);
121
+ done();
122
+ });
123
+ layer1.mbMap.project.mockRestore();
124
+ layer1.mbMap.queryRenderedFeatures.mockRestore();
125
+ });
126
+ describe('should use hitTolerance property', () => {
127
+ beforeEach(() => {
128
+ layer1.mbMap.project = jest.fn((coord) => ({
129
+ x: coord[0],
130
+ y: coord[1],
131
+ }));
132
+ });
133
+ afterEach(() => {
134
+ layer1.mbMap.project.mockRestore();
135
+ layer1.mbMap.queryRenderedFeatures.mockRestore();
136
+ });
137
+ test('when hitTolerance is not set', (done) => {
138
+ layer1.mbMap.queryRenderedFeatures = jest.fn((pixelBounds) => {
139
+ // Use default hoitTolerance
140
+ expect(pixelBounds).toEqual([
141
+ { x: -5, y: -5 },
142
+ { x: 5, y: 5 },
143
+ ]);
144
+ done();
145
+ return [];
146
+ });
147
+ layer1.getFeatureInfoAtCoordinate([0, 0], {});
148
+ });
149
+ test('when hitTolerance is set to 10', (done) => {
150
+ layer1.hitTolerance = 10;
151
+ layer1.mbMap.queryRenderedFeatures = jest.fn((pixelBounds) => {
152
+ // Use default hoitTolerance
153
+ expect(pixelBounds).toEqual([
154
+ { x: -10, y: -10 },
155
+ { x: 10, y: 10 },
156
+ ]);
157
+ done();
158
+ return [];
159
+ });
160
+ layer1.getFeatureInfoAtCoordinate([0, 0], {});
161
+ });
162
+ });
163
+ });
164
+ });
@@ -26,8 +26,8 @@ declare class MapboxStyleLayer extends Layer {
26
26
  * @param {Function} [options.styleLayersFilter] Filter function to decide which style layer to display.
27
27
  */
28
28
  constructor(options?: {
29
- mapboxLayer?: MapboxLayer;
30
- styleLayersFilter?: Function;
29
+ mapboxLayer?: any;
30
+ styleLayersFilter?: Function | undefined;
31
31
  });
32
32
  /**
33
33
  * MapboxLayer provided for the style Layer.
@@ -140,7 +140,7 @@ declare class MapboxStyleLayer extends Layer {
140
140
  * @param {Object} newOptions Options to override.
141
141
  * @return {MapboxStyleLayer} A MapboxStyleLayer.
142
142
  */
143
- clone(newOptions: any): MapboxStyleLayer;
143
+ clone(newOptions: Object): MapboxStyleLayer;
144
144
  }
145
145
  import Layer from "./Layer";
146
146
  //# sourceMappingURL=MapboxStyleLayer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"MapboxStyleLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxStyleLayer.js"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;;;;OAMG;IACH;QAHiC,WAAW;QACd,iBAAiB;OA4F9C;IAvFC;;;;OAIG;IACH,oBAAsC;IAEtC;;OAEG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,0BAAkD;IAElD;;;;;OAKG;IACH,iBAAgC;IAEhC;;;;OAIG;IACH,0BAAoE;IAEpE;;;;OAIG;IACH,kCAAkE;IAElE;;;;OAIG;IACH,4BAA6B;IAE7B;;;;OAIG;IACH,yBAA0B;IAE1B;;;;OAIG;IACH,oBACyE;IAiG3E,cAAc;IACd,uBAcC;IAiBD;;;OAGG;IACH,eAaC;IAtIG,eAAe;IACf,0BAMC;IAgEL;;;;OAIG;IACH,gDAOC;IAmBD,cAAc;IACd,0BAYC;IAqBD;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAiC/B;IAED;;;OAGG;IACH,yCAYC;IAED;;;;;OAKG;IACH,sBA8BC;IAED;;;;OAIG;IACH,eAIC;IAED;;;;OAIG;IACH,kBAeC;IAED;;;;OAIG;IAEH,8BA8BC;IAED;;;;OAIG;IACH,wBAFY,gBAAgB,CAI3B;CACF"}
1
+ {"version":3,"file":"MapboxStyleLayer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/MapboxStyleLayer.js"],"names":[],"mappings":";AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH;IACE;;;;;;OAMG;IACH;QAHiC,WAAW;QACd,iBAAiB;OA4F9C;IAvFC;;;;OAIG;IACH,oBAAsC;IAEtC;;OAEG;IACH,kBAAqB;IAErB;;;;OAIG;IACH,0BAAkD;IAElD;;;;;OAKG;IACH,iBAAgC;IAEhC;;;;OAIG;IACH,0BAAoE;IAEpE;;;;OAIG;IACH,kCAAkE;IAElE;;;;OAIG;IACH,4BAA6B;IAE7B;;;;OAIG;IACH,yBAA0B;IAE1B;;;;OAIG;IACH,oBACyE;IAiG3E,cAAc;IACd,uBAcC;IAiBD;;;OAGG;IACH,eAaC;IAtIG,eAAe;IACf,0BAMC;IAgEL;;;;OAIG;IACH,gDAOC;IAmBD,cAAc;IACd,0BAYC;IAqBD;;;;OAIG;IACH,6CAFY,QAAQ,WAAW,CAAC,CAiC/B;IAED;;;OAGG;IACH,yCAYC;IAED;;;;;OAKG;IACH,sBA8BC;IAED;;;;OAIG;IACH,eAIC;IAED;;;;OAIG;IACH,kBAeC;IAED;;;;OAIG;IAEH,8BA8BC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,gBAAgB,CAI3B;CACF"}