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,165 +0,0 @@
1
- import View from "ol/View";
2
- import Tile from "ol/Tile";
3
- import TileLayer from "ol/layer/Tile";
4
- import TileSource from "ol/source/Tile";
5
- import { createXYZ } from "ol/tilegrid";
6
- import { Map } from "ol";
7
- import Layer from "../layers/Layer";
8
- import CopyrightControl from "./CopyrightControl";
9
- const tileLoadFunction = () => {
10
- const tile = new Tile([0, 0, -1], 2);
11
- tile.getImage = () => {
12
- const image = new Image();
13
- image.width = 256;
14
- image.height = 256;
15
- return image;
16
- };
17
- return tile;
18
- };
19
- const getOLTileLayer = () => {
20
- const layer = new TileLayer({
21
- source: new TileSource({
22
- projection: "EPSG:3857",
23
- tileGrid: createXYZ()
24
- })
25
- });
26
- layer.getSource().getTile = tileLoadFunction;
27
- return layer;
28
- };
29
- const getLayer = (copyrights, visible = true) => new Layer({
30
- visible,
31
- copyrights,
32
- olLayer: getOLTileLayer()
33
- });
34
- describe("CopyrightControl", () => {
35
- let map;
36
- beforeEach(() => {
37
- const target = document.createElement("div");
38
- document.body.appendChild(target);
39
- map = new Map({
40
- target,
41
- view: new View({
42
- center: [0, 0],
43
- zoom: 0
44
- })
45
- });
46
- getLayer(true, "bar").attachToMap(map);
47
- map.setSize([200, 200]);
48
- map.renderSync();
49
- });
50
- afterEach(() => {
51
- if (map) {
52
- map.setTarget(null);
53
- map = null;
54
- }
55
- });
56
- test("should be activate by default", () => {
57
- const control = new CopyrightControl();
58
- expect(control.active).toBe(true);
59
- });
60
- test("renders a string copyright", () => {
61
- const control = new CopyrightControl();
62
- control.attachToMap(map);
63
- expect(control.element.innerHTML).toBe("");
64
- getLayer("copyright").attachToMap(map);
65
- map.renderSync();
66
- expect(control.element.innerHTML).toBe("copyright");
67
- });
68
- test("renders an array of copyrights", () => {
69
- const control = new CopyrightControl();
70
- control.attachToMap(map);
71
- expect(control.element.innerHTML).toBe("");
72
- getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
73
- map.renderSync();
74
- expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
75
- });
76
- test("renders unique copyrights", () => {
77
- const control = new CopyrightControl();
78
- control.attachToMap(map);
79
- expect(control.element.innerHTML).toBe("");
80
- getLayer(["copyright 1", "copyright 2"]).attachToMap(map);
81
- getLayer("copyright 1").attachToMap(map);
82
- getLayer(["copyright 2"]).attachToMap(map);
83
- map.renderSync();
84
- expect(control.element.innerHTML).toBe("copyright 1 | copyright 2");
85
- });
86
- test("doesn't render copyright of an hidden layer", () => {
87
- const control = new CopyrightControl();
88
- control.attachToMap(map);
89
- expect(control.element.innerHTML).toBe("");
90
- const layer1 = getLayer("copyright hidden", false);
91
- layer1.attachToMap(map);
92
- const layer2 = getLayer("copyright", true);
93
- layer2.attachToMap(map);
94
- map.renderSync();
95
- expect(control.element.innerHTML).toBe("copyright");
96
- layer1.visible = true;
97
- map.renderSync();
98
- layer2.visible = false;
99
- map.renderSync();
100
- expect(control.element.innerHTML).toBe("copyright hidden");
101
- });
102
- test("should activate the control on construction then deactivate it", () => {
103
- getLayer("copyright 1").attachToMap(map);
104
- const control = new CopyrightControl({ active: true });
105
- control.attachToMap(map);
106
- map.renderSync();
107
- expect(control.element.parentNode).toBe(map.getTargetElement());
108
- expect(control.active).toBe(true);
109
- expect(control.element.innerHTML).toBe("copyright 1");
110
- control.active = false;
111
- map.renderSync();
112
- expect(control.element.innerHTML).toBe("");
113
- });
114
- test("should deactivate the control on constrcution then activate it", () => {
115
- getLayer("copyright 1").attachToMap(map);
116
- const control = new CopyrightControl({ active: false });
117
- control.attachToMap(map);
118
- map.renderSync();
119
- expect(control.element.parentNode).toBe(map.getTargetElement());
120
- expect(control.active).toBe(false);
121
- map.renderSync();
122
- expect(control.element.innerHTML).toBe("");
123
- control.active = true;
124
- map.renderSync();
125
- expect(control.element.innerHTML).toBe("copyright 1");
126
- });
127
- test("should add copyrights in the map container element then remove it.", () => {
128
- getLayer("copyright value").attachToMap(map);
129
- map.renderSync();
130
- const control = new CopyrightControl();
131
- control.attachToMap(map);
132
- expect(control.element.parentNode).toBe(map.getTargetElement());
133
- control.detachFromMap();
134
- expect(control.element.parentNode).toBe(null);
135
- });
136
- test("should add copyrights in the target element then remove it.", () => {
137
- getLayer(["copyright value"]).attachToMap(map);
138
- map.renderSync();
139
- const target = document.createElement("div");
140
- target.setAttribute("id", "copyright");
141
- document.body.appendChild(target);
142
- const control = new CopyrightControl({
143
- target: document.getElementById("copyright")
144
- });
145
- control.attachToMap(map);
146
- expect(control.element.parentNode).toBe(target);
147
- control.detachFromMap();
148
- expect(control.element.parentNode).toBe(null);
149
- });
150
- test("renders custom copyrights with the render method ", () => {
151
- const control = new CopyrightControl({
152
- active: true,
153
- render() {
154
- if (!this.element) {
155
- return;
156
- }
157
- this.element.innerHTML = this.active ? this.getCopyrights().join(", ") : "";
158
- }
159
- });
160
- control.attachToMap(map);
161
- getLayer(["copyright 1", "copyright 2", "copyright 3"]).attachToMap(map);
162
- map.renderSync();
163
- expect(control.element.innerHTML).toBe("copyright 1, copyright 2, copyright 3");
164
- });
165
- });
@@ -1,146 +0,0 @@
1
- import fetch from "jest-fetch-mock";
2
- import View from "ol/View";
3
- import Map from "ol/Map";
4
- import RoutingControl from "./RoutingControl";
5
- import RoutingControlStation1 from "./snapshots/RoutingControlStation1.json";
6
- import RoutingControlStation2 from "./snapshots/RoutingControlStation2.json";
7
- import RoutingControlRouteGen5 from "./snapshots/RoutingControlRouteGen5.json";
8
- import RoutingControlRouteGen10 from "./snapshots/RoutingControlRouteGen10.json";
9
- import RoutingControlRouteGen30 from "./snapshots/RoutingControlRouteGen30.json";
10
- import RoutingControlRouteGen100 from "./snapshots/RoutingControlRouteGen100.json";
11
- import RoutingControlRouteOSM from "./snapshots/RoutingControlRouteOSM.json";
12
- describe("RoutingControl", () => {
13
- let map;
14
- beforeEach(() => {
15
- const target = document.createElement("div");
16
- document.body.appendChild(target);
17
- map = new Map({
18
- target,
19
- view: new View({
20
- center: [0, 0],
21
- zoom: 0
22
- })
23
- });
24
- global.fetch = fetch;
25
- });
26
- afterEach(() => {
27
- if (map) {
28
- map.setTarget(null);
29
- map = null;
30
- }
31
- fetch.resetMocks();
32
- });
33
- test("should be activate by default", () => {
34
- const control = new RoutingControl();
35
- expect(control.active).toBe(true);
36
- expect(control.snapToClosestStation).toBe(false);
37
- expect(control.useRawViaPoints).toBe(false);
38
- });
39
- test("launch routing and add features", (done) => {
40
- fetch.mockResponseOnce(JSON.stringify(global.fetchRouteResponse));
41
- const control = new RoutingControl({
42
- url: "https://foo.ch",
43
- apiKey: "foo"
44
- });
45
- control.attachToMap(map);
46
- expect(map.getTargetElement().querySelector("#ol-toggle-routing")).toBeDefined();
47
- control.viaPoints = [
48
- [950476.4055933182, 6003322253698345e-9],
49
- [950389.0813034325, 6003656659274571e-9]
50
- ];
51
- control.drawRoute(control.viaPoints).then(() => {
52
- expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch/?key=foo&graph=osm&via=47.3739194713294%2C8.538274823394632%7C47.37595378493421%2C8.537490375951839&mot=bus&resolve-hops=false&elevation=false&coord-radius=100&coord-punish=1000");
53
- expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(3);
54
- done();
55
- });
56
- });
57
- test("launch routing and add features for multiple graphs", (done) => {
58
- fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(RoutingControlStation2), { status: 200 }], [JSON.stringify(RoutingControlRouteGen5), { status: 200 }], [JSON.stringify(RoutingControlRouteGen10), { status: 200 }], [JSON.stringify(RoutingControlRouteGen30), { status: 200 }], [JSON.stringify(RoutingControlRouteGen100), { status: 200 }], [JSON.stringify(RoutingControlRouteOSM), { status: 200 }]);
59
- const control = new RoutingControl({
60
- url: "https://foo.ch/",
61
- stopsApiUrl: "https://foo.ch/",
62
- apiKey: "foo",
63
- graphs: [
64
- ["gen5", 6, 7],
65
- ["gen10", 8],
66
- ["gen30", 9, 10],
67
- ["gen100", 11, 13],
68
- ["osm", 14, 99]
69
- ]
70
- });
71
- control.attachToMap(map);
72
- control.viaPoints = ["a4dca961d199ff76", "e3666f03cba06b2b"];
73
- control.drawRoute(control.viaPoints).then(() => {
74
- expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch/lookup/a4dca961d199ff76?key=foo");
75
- expect(fetch.mock.calls[1][0]).toEqual("https://foo.ch/lookup/e3666f03cba06b2b?key=foo");
76
- expect(fetch.mock.calls[2][0]).toEqual("https://foo.ch/?key=foo&graph=gen5&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b&mot=bus&resolve-hops=false&elevation=false&coord-radius=100&coord-punish=1000");
77
- expect(fetch.mock.calls[3][0]).toEqual("https://foo.ch/?key=foo&graph=gen10&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b&mot=bus&resolve-hops=false&elevation=false&coord-radius=100&coord-punish=1000");
78
- expect(fetch.mock.calls[4][0]).toEqual("https://foo.ch/?key=foo&graph=gen30&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b&mot=bus&resolve-hops=false&elevation=false&coord-radius=100&coord-punish=1000");
79
- expect(fetch.mock.calls[5][0]).toEqual("https://foo.ch/?key=foo&graph=gen100&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b&mot=bus&resolve-hops=false&elevation=false&coord-radius=100&coord-punish=1000");
80
- expect(fetch.mock.calls[6][0]).toEqual("https://foo.ch/?key=foo&graph=osm&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b&mot=bus&resolve-hops=false&elevation=false&coord-radius=100&coord-punish=1000");
81
- expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(7);
82
- done();
83
- });
84
- });
85
- test("ignores Abort Error and returns undefined", (done) => {
86
- const control = new RoutingControl({
87
- url: "https://foo.ch",
88
- apiKey: "foo"
89
- });
90
- control.attachToMap(map);
91
- control.viaPoints = [
92
- [950476.4055933182, 6003322253698345e-9],
93
- [950389.0813034325, 6003656659274571e-9]
94
- ];
95
- const error = new Error("Error");
96
- error.name = "AbortError";
97
- fetch.mockRejectOnce(error);
98
- return control.drawRoute().then((data) => {
99
- expect(data).toEqual([void 0]);
100
- done();
101
- });
102
- });
103
- test("calls routing api with @ before the coordinates when snapToClosestStation is true", (done) => {
104
- fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
105
- const control = new RoutingControl({
106
- apiKey: "foo",
107
- snapToClosestStation: true
108
- });
109
- control.attachToMap(map);
110
- expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
111
- control.viaPoints = [
112
- [950476.4055933182, 6003322253698345e-9],
113
- [950389.0813034325, 6003656659274571e-9],
114
- "e3666f03cba06b2b"
115
- ];
116
- control.drawRoute(control.viaPoints).then(() => {
117
- const { searchParams } = new URL(fetch.mock.calls[1][0]);
118
- expect(searchParams.get("via")).toBe("@47.3739194713294,8.538274823394632|@47.37595378493421,8.537490375951839|!e3666f03cba06b2b");
119
- done();
120
- });
121
- });
122
- test("calls routing api with raw via points", (done) => {
123
- fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(RoutingControlStation2), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
124
- const control = new RoutingControl({
125
- apiKey: "foo",
126
- useRawViaPoints: true
127
- });
128
- control.attachToMap(map);
129
- expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
130
- control.viaPoints = [
131
- "46.2,7.1",
132
- "@46.2,7.1",
133
- "@46.2,7$1",
134
- "station name$2",
135
- "station name@46.2,7",
136
- "stationname@46.2,7.7$3",
137
- "!stationid",
138
- [950389, 6003656]
139
- ];
140
- control.drawRoute(control.viaPoints).then(() => {
141
- const params = new URL(fetch.mock.calls[2][0]).searchParams;
142
- expect(params.get("via")).toBe("46.2,7.1|@46.2,7.1|@46.2,7$1|station name$2|station name@46.2,7|stationname@46.2,7.7$3|!stationid|47.375949774398805,8.537489645590679");
143
- done();
144
- });
145
- });
146
- });
@@ -1,48 +0,0 @@
1
- import fetch from "jest-fetch-mock";
2
- import View from "ol/View";
3
- import Map from "ol/Map";
4
- import StopFinderControl from "./StopFinderControl";
5
- describe("StopFinderControl", () => {
6
- let map;
7
- beforeEach(() => {
8
- const target = document.createElement("div");
9
- document.body.appendChild(target);
10
- map = new Map({
11
- target,
12
- view: new View({
13
- center: [0, 0],
14
- zoom: 0
15
- })
16
- });
17
- global.fetch = fetch;
18
- });
19
- afterEach(() => {
20
- if (map) {
21
- map.setTarget(null);
22
- map = null;
23
- }
24
- fetch.resetMocks();
25
- });
26
- test("should be activate by default", () => {
27
- const control = new StopFinderControl();
28
- expect(control.active).toBe(true);
29
- });
30
- test("launch a search and display results", (done) => {
31
- fetch.mockResponseOnce(JSON.stringify(global.stopsSearchResponse));
32
- const control = new StopFinderControl({
33
- url: "https://foo.ch",
34
- apiKey: "foo",
35
- apiParams: {
36
- limit: 10,
37
- foo: "bar"
38
- }
39
- });
40
- control.attachToMap(map);
41
- expect(control.element).toBeDefined();
42
- control.search("foo").then(() => {
43
- expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch/?key=foo&limit=10&foo=bar&q=foo");
44
- expect(control.element.querySelector("div").querySelector("div").innerHTML).toBe("Bern");
45
- done();
46
- });
47
- });
48
- });
@@ -1,175 +0,0 @@
1
- import VectorLayer from "ol/layer/Vector";
2
- import VectorSource from "ol/source/Vector";
3
- import Map from "ol/Map";
4
- import Group from "ol/layer/Group";
5
- import Layer from "./Layer";
6
- let olLayer;
7
- let map;
8
- describe("Layer", () => {
9
- beforeEach(() => {
10
- map = new Map({});
11
- olLayer = new VectorLayer({ source: new VectorSource() });
12
- });
13
- test("should initialize.", () => {
14
- const layer = new Layer({ name: "Layer", olLayer });
15
- expect(layer).toBeInstanceOf(Layer);
16
- });
17
- test("should be visible by default.", () => {
18
- const layer = new Layer({ name: "Layer", olLayer });
19
- expect(layer.visible).toBe(true);
20
- });
21
- test("should be invisible if defined.", () => {
22
- const layer = new Layer({ name: "Layer", visible: false, olLayer });
23
- expect(layer.visible).toBe(false);
24
- });
25
- test("should be invisible if set.", () => {
26
- const layer = new Layer({ name: "Layer", olLayer });
27
- layer.visible = false;
28
- expect(layer.visible).toBe(false);
29
- });
30
- test("should visibility stay unchanged", () => {
31
- const layer = new Layer({ name: "Layer", visible: false, olLayer });
32
- layer.visible = false;
33
- expect(layer.visible).toBe(false);
34
- });
35
- test("should return its name.", () => {
36
- const layer = new Layer({ name: "Layer", visible: false, olLayer });
37
- expect(layer.name).toEqual("Layer");
38
- });
39
- test("should call terminate on initialization.", () => {
40
- const layer = new Layer({ name: "Layer", olLayer });
41
- const spy = jest.spyOn(layer, "detachFromMap");
42
- layer.attachToMap();
43
- expect(spy).toHaveBeenCalledTimes(1);
44
- });
45
- test("should remove the layer when we call terminate.", () => {
46
- const layer = new Layer({ name: "Layer", olLayer });
47
- const spy = jest.spyOn(layer, "detachFromMap");
48
- layer.attachToMap(map);
49
- expect(spy).toHaveBeenCalledTimes(1);
50
- layer.detachFromMap(map);
51
- expect(spy).toHaveBeenCalledTimes(2);
52
- });
53
- test("should manage copyrights as string.", () => {
54
- const spy = jest.spyOn(VectorSource.prototype, "setAttributions");
55
- const layer = new Layer({ name: "Layer", copyrights: "foo", olLayer });
56
- layer.attachToMap(map);
57
- expect(spy).toHaveBeenCalledWith(["foo"]);
58
- });
59
- test("should manage copyrights as array.", () => {
60
- const spy = jest.spyOn(VectorSource.prototype, "setAttributions");
61
- const layer = new Layer({ name: "Layer", copyrights: ["bar"], olLayer });
62
- layer.attachToMap(map);
63
- expect(spy).toHaveBeenCalledWith(["bar"]);
64
- });
65
- test("should set attributions for Group.", () => {
66
- const spy = jest.spyOn(VectorSource.prototype, "setAttributions");
67
- const layer = new Layer({
68
- name: "Layer",
69
- copyrights: ["bar"],
70
- olLayer: new Group({ layers: [olLayer] })
71
- });
72
- layer.attachToMap(map);
73
- expect(spy).toHaveBeenCalledWith(["bar"]);
74
- });
75
- test("should listen for click/hover events when layer is visible by default then should not when hidden.", async () => {
76
- global.console.error = jest.fn();
77
- const layer = new Layer({ name: "Layer", olLayer });
78
- expect(layer.visible).toBe(true);
79
- const spy = jest.fn();
80
- const spy2 = jest.fn();
81
- layer.onHover(spy);
82
- layer.onClick(spy2);
83
- layer.attachToMap(map);
84
- expect(spy).toHaveBeenCalledTimes(0);
85
- expect(spy2).toHaveBeenCalledTimes(0);
86
- await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
87
- await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
88
- expect(spy).toHaveBeenCalledTimes(1);
89
- expect(spy2).toHaveBeenCalledTimes(1);
90
- spy.mockReset();
91
- spy2.mockReset();
92
- layer.visible = false;
93
- await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
94
- await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
95
- expect(spy).toHaveBeenCalledTimes(0);
96
- expect(spy2).toHaveBeenCalledTimes(0);
97
- global.console.error.mockRestore();
98
- });
99
- test("should not listen for click/hover events when layer is not visible by default then should not when visible.", async () => {
100
- global.console.error = jest.fn();
101
- const layer = new Layer({ name: "Layer", olLayer, visible: false });
102
- expect(layer.visible).toBe(false);
103
- const spy = jest.fn();
104
- const spy2 = jest.fn();
105
- layer.onHover(spy);
106
- layer.onClick(spy2);
107
- layer.attachToMap(map);
108
- expect(spy).toHaveBeenCalledTimes(0);
109
- expect(spy2).toHaveBeenCalledTimes(0);
110
- await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
111
- await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
112
- expect(spy).toHaveBeenCalledTimes(0);
113
- expect(spy2).toHaveBeenCalledTimes(0);
114
- spy.mockReset();
115
- spy2.mockReset();
116
- layer.visible = true;
117
- await map.dispatchEvent({ type: "pointermove", map, coordinate: [0, 0] });
118
- await map.dispatchEvent({ type: "singleclick", map, coordinate: [0, 0] });
119
- expect(spy).toHaveBeenCalledTimes(1);
120
- expect(spy2).toHaveBeenCalledTimes(1);
121
- global.console.error.mockRestore();
122
- });
123
- test("should not listen for click/hover events after layer.detachFromMap()", async () => {
124
- global.console.error = jest.fn();
125
- const layer = new Layer({ name: "Layer", olLayer, visible: true });
126
- expect(layer.visible).toBe(true);
127
- const spy = jest.fn();
128
- const spy2 = jest.fn();
129
- layer.attachToMap(map);
130
- layer.onHover(spy);
131
- layer.onClick(spy2);
132
- layer.attachToMap(map);
133
- expect(spy).toHaveBeenCalledTimes(0);
134
- expect(spy2).toHaveBeenCalledTimes(0);
135
- await map.dispatchEvent({
136
- type: "pointermove",
137
- map,
138
- coordinate: [0, 0]
139
- });
140
- await map.dispatchEvent({
141
- type: "singleclick",
142
- map,
143
- coordinate: [0, 0]
144
- });
145
- expect(spy).toHaveBeenCalledTimes(1);
146
- expect(spy2).toHaveBeenCalledTimes(1);
147
- spy.mockReset();
148
- spy2.mockReset();
149
- layer.detachFromMap(map);
150
- await map.dispatchEvent({
151
- type: "pointermove",
152
- map,
153
- coordinate: [0, 0]
154
- });
155
- await map.dispatchEvent({
156
- type: "singleclick",
157
- map,
158
- coordinate: [0, 0]
159
- });
160
- expect(spy).toHaveBeenCalledTimes(0);
161
- expect(spy2).toHaveBeenCalledTimes(0);
162
- global.console.error.mockRestore();
163
- });
164
- test("should clone", () => {
165
- const layer = new Layer({
166
- name: "Layer",
167
- copyrights: ["bar"],
168
- olLayer: new Group({ layers: [olLayer] })
169
- });
170
- const clone = layer.clone({ name: "clone" });
171
- expect(clone).not.toBe(layer);
172
- expect(clone.name).toBe("clone");
173
- expect(clone).toBeInstanceOf(Layer);
174
- });
175
- });
@@ -1,160 +0,0 @@
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
- consoleOutput = [];
13
- console.warn = (message) => consoleOutput.push(message);
14
- layer = new MapboxLayer({
15
- name: "Layer",
16
- url: styleUrl
17
- });
18
- map = new OlMap({
19
- target: document.createElement("div"),
20
- view: new View({ center: [0, 0] })
21
- });
22
- });
23
- test("should be instanced.", () => {
24
- expect(layer).toBeInstanceOf(MapboxLayer);
25
- expect(layer.styleUrl).toBe(styleUrl);
26
- });
27
- test("should not initalized mapbox map.", () => {
28
- layer.attachToMap();
29
- expect(layer.mbMap).toBe();
30
- });
31
- test("should initalized mapbox map and warn the user if there is no api key defined.", () => {
32
- layer.attachToMap(map);
33
- expect(layer.mbMap).toBeInstanceOf(gllib.Map);
34
- expect(consoleOutput[0]).toBe("No apiKey is defined for request to http://foo.com/styles");
35
- });
36
- test("should called terminate on initalization.", () => {
37
- const spy = jest.spyOn(layer, "detachFromMap");
38
- layer.attachToMap();
39
- expect(spy).toHaveBeenCalledTimes(1);
40
- });
41
- test("should clone", () => {
42
- const clone = layer.clone({ name: "clone" });
43
- expect(clone).not.toBe(layer);
44
- expect(clone.name).toBe("clone");
45
- expect(clone).toBeInstanceOf(MapboxLayer);
46
- });
47
- });
48
- describe("with apiKey", () => {
49
- beforeEach(() => {
50
- layer = new MapboxLayer({
51
- name: "Layer",
52
- url: styleUrl,
53
- apiKey: "apiKey"
54
- });
55
- map = new OlMap({
56
- target: document.createElement("div"),
57
- view: new View({ center: [0, 0] })
58
- });
59
- });
60
- test("should be instanced with apiKey.", () => {
61
- expect(layer).toBeInstanceOf(MapboxLayer);
62
- expect(layer.styleUrl).toBe(styleUrl);
63
- });
64
- test("should not initalized mapbox map.", () => {
65
- layer.attachToMap();
66
- expect(layer.mbMap).toBe();
67
- });
68
- test("should initalized mapbox map, with 'apiKey' prop", () => {
69
- const layer1 = new MapboxLayer({
70
- name: "Layer",
71
- url: styleUrl,
72
- apiKey: "apiKeyVal"
73
- });
74
- layer1.attachToMap(map);
75
- expect(layer1.mbMap.options.style).toBe("http://foo.com/styles?key=apiKeyVal");
76
- });
77
- test("should initalized mapbox map, with 'apiKeyName' prop", () => {
78
- const layer1 = new MapboxLayer({
79
- name: "Layer",
80
- url: styleUrl,
81
- apiKey: "test",
82
- apiKeyName: "apiKey"
83
- });
84
- layer1.attachToMap(map);
85
- expect(layer1.mbMap.options.style).toBe("http://foo.com/styles?apiKey=test");
86
- });
87
- });
88
- describe("#getFeatureInfoAtCoordinate()", () => {
89
- let layer1;
90
- beforeEach(() => {
91
- layer1 = new MapboxLayer({
92
- name: "Layer",
93
- url: styleUrl,
94
- apiKey: "test",
95
- apiKeyName: "apiKey"
96
- });
97
- layer1.attachToMap(map);
98
- layer1.mbMap.isStyleLoaded = jest.fn(() => true);
99
- layer1.mbMap.getSource = jest.fn(() => true);
100
- });
101
- afterEach(() => {
102
- layer1.mbMap.getSource.mockRestore();
103
- layer1.mbMap.isStyleLoaded.mockRestore();
104
- });
105
- test("should set the mapboxFeature as a property", (done) => {
106
- const mapboxFeature = {
107
- id: "2",
108
- type: "Feature",
109
- properties: {
110
- foo: "bar"
111
- },
112
- source: "barr",
113
- sourceLayer: "fooo"
114
- };
115
- layer1.mbMap.project = jest.fn((coord) => ({ x: coord[0], y: coord[1] }));
116
- layer1.mbMap.queryRenderedFeatures = jest.fn(() => [mapboxFeature]);
117
- layer1.getFeatureInfoAtCoordinate([0, 0], {}).then((featureInfo) => {
118
- expect(featureInfo.features[0].get("mapboxFeature")).toBe(mapboxFeature);
119
- done();
120
- });
121
- layer1.mbMap.project.mockRestore();
122
- layer1.mbMap.queryRenderedFeatures.mockRestore();
123
- });
124
- describe("should use hitTolerance property", () => {
125
- beforeEach(() => {
126
- layer1.mbMap.project = jest.fn((coord) => ({
127
- x: coord[0],
128
- y: coord[1]
129
- }));
130
- });
131
- afterEach(() => {
132
- layer1.mbMap.project.mockRestore();
133
- layer1.mbMap.queryRenderedFeatures.mockRestore();
134
- });
135
- test("when hitTolerance is not set", (done) => {
136
- layer1.mbMap.queryRenderedFeatures = jest.fn((pixelBounds) => {
137
- expect(pixelBounds).toEqual([
138
- { x: -5, y: -5 },
139
- { x: 5, y: 5 }
140
- ]);
141
- done();
142
- return [];
143
- });
144
- layer1.getFeatureInfoAtCoordinate([0, 0], {});
145
- });
146
- test("when hitTolerance is set to 10", (done) => {
147
- layer1.hitTolerance = 10;
148
- layer1.mbMap.queryRenderedFeatures = jest.fn((pixelBounds) => {
149
- expect(pixelBounds).toEqual([
150
- { x: -10, y: -10 },
151
- { x: 10, y: 10 }
152
- ]);
153
- done();
154
- return [];
155
- });
156
- layer1.getFeatureInfoAtCoordinate([0, 0], {});
157
- });
158
- });
159
- });
160
- });