mobility-toolbox-js 2.0.0-beta.3 → 2.0.0-beta.33

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 (220) hide show
  1. package/README.md +4 -1
  2. package/api/RealtimeAPI.d.ts +268 -0
  3. package/api/RealtimeAPI.d.ts.map +1 -0
  4. package/api/RoutingAPI.d.ts +33 -0
  5. package/api/RoutingAPI.d.ts.map +1 -0
  6. package/api/StopsAPI.d.ts +36 -0
  7. package/api/StopsAPI.d.ts.map +1 -0
  8. package/api/index.d.ts +5 -0
  9. package/api/index.d.ts.map +1 -0
  10. package/api/typedefs.d.ts +105 -0
  11. package/api/typedefs.d.ts.map +1 -0
  12. package/common/api/HttpAPI.d.ts +31 -0
  13. package/common/api/HttpAPI.d.ts.map +1 -0
  14. package/common/api/WebSocketAPI.d.ts +95 -0
  15. package/common/api/WebSocketAPI.d.ts.map +1 -0
  16. package/common/controls/Control.d.ts +74 -0
  17. package/common/controls/Control.d.ts.map +1 -0
  18. package/common/index.d.ts +3 -0
  19. package/common/index.d.ts.map +1 -0
  20. package/common/layers/Layer.d.ts +80 -0
  21. package/common/layers/Layer.d.ts.map +1 -0
  22. package/common/mixins/CopyrightMixin.d.ts +22 -0
  23. package/common/mixins/CopyrightMixin.d.ts.map +1 -0
  24. package/common/mixins/MapboxLayerMixin.d.ts +27 -0
  25. package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
  26. package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
  27. package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
  28. package/common/mixins/StopFinderMixin.d.ts +40 -0
  29. package/common/mixins/StopFinderMixin.d.ts.map +1 -0
  30. package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
  31. package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
  32. package/common/styles/index.d.ts +5 -0
  33. package/common/styles/index.d.ts.map +1 -0
  34. package/common/styles/realtimeDefaultStyle.d.ts +15 -0
  35. package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
  36. package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +3 -9
  37. package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
  38. package/common/styles/realtimeSimpleStyle.d.ts +3 -0
  39. package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
  40. package/common/typedefs.d.ts +50 -0
  41. package/common/typedefs.d.ts.map +1 -0
  42. package/common/utils/cleanStopTime.d.ts +7 -0
  43. package/common/utils/cleanStopTime.d.ts.map +1 -0
  44. package/common/utils/compareDepartures.d.ts +9 -0
  45. package/common/utils/compareDepartures.d.ts.map +1 -0
  46. package/common/utils/createCanvas.d.ts +9 -0
  47. package/common/utils/createCanvas.d.ts.map +1 -0
  48. package/common/utils/createTrackerFilters.d.ts +12 -0
  49. package/common/utils/createTrackerFilters.d.ts.map +1 -0
  50. package/common/utils/getLayersAsFlatArray.d.ts +3 -0
  51. package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
  52. package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
  53. package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
  54. package/common/utils/getMapboxRender.d.ts +5 -0
  55. package/common/utils/getMapboxRender.d.ts.map +1 -0
  56. package/common/utils/getMaplibreRender.d.ts +5 -0
  57. package/common/utils/getMaplibreRender.d.ts.map +1 -0
  58. package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
  59. package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
  60. package/common/utils/getUrlWithParams.d.ts +9 -0
  61. package/common/utils/getUrlWithParams.d.ts.map +1 -0
  62. package/common/utils/getVehiclePosition.d.ts +14 -0
  63. package/common/utils/getVehiclePosition.d.ts.map +1 -0
  64. package/common/utils/index.d.ts +12 -0
  65. package/common/utils/index.d.ts.map +1 -0
  66. package/common/utils/removeDuplicate.d.ts +10 -0
  67. package/common/utils/removeDuplicate.d.ts.map +1 -0
  68. package/common/utils/renderTrajectories.d.ts +20 -0
  69. package/common/utils/renderTrajectories.d.ts.map +1 -0
  70. package/common/utils/sortByDelay.d.ts +3 -0
  71. package/common/utils/sortByDelay.d.ts.map +1 -0
  72. package/common/utils/timeUtils.d.ts +5 -0
  73. package/common/utils/timeUtils.d.ts.map +1 -0
  74. package/common/utils/trackerConfig.d.ts +24 -0
  75. package/common/utils/trackerConfig.d.ts.map +1 -0
  76. package/iife.d.ts +3 -0
  77. package/iife.d.ts.map +1 -0
  78. package/index.d.ts +6 -0
  79. package/index.d.ts.map +1 -0
  80. package/mapbox/controls/CopyrightControl.d.ts +32 -0
  81. package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
  82. package/mapbox/controls/index.d.ts +2 -0
  83. package/mapbox/controls/index.d.ts.map +1 -0
  84. package/mapbox/index.d.ts +5 -0
  85. package/mapbox/index.d.ts.map +1 -0
  86. package/mapbox/layers/Layer.d.ts +47 -0
  87. package/mapbox/layers/Layer.d.ts.map +1 -0
  88. package/mapbox/layers/RealtimeLayer.d.ts +118 -0
  89. package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
  90. package/mapbox/layers/index.d.ts +3 -0
  91. package/mapbox/layers/index.d.ts.map +1 -0
  92. package/mapbox/utils.d.ts +8 -0
  93. package/mapbox/utils.d.ts.map +1 -0
  94. package/mbt.js +50042 -0
  95. package/mbt.js.map +7 -0
  96. package/mbt.min.js +1008 -0
  97. package/mbt.min.js.map +7 -0
  98. package/ol/controls/CopyrightControl.d.ts +31 -0
  99. package/ol/controls/CopyrightControl.d.ts.map +1 -0
  100. package/ol/controls/RoutingControl.d.ts +180 -0
  101. package/ol/controls/RoutingControl.d.ts.map +1 -0
  102. package/ol/controls/StopFinderControl.d.ts +32 -0
  103. package/ol/controls/StopFinderControl.d.ts.map +1 -0
  104. package/ol/controls/index.d.ts +4 -0
  105. package/ol/controls/index.d.ts.map +1 -0
  106. package/ol/index.d.ts +6 -0
  107. package/ol/index.d.ts.map +1 -0
  108. package/ol/layers/Layer.d.ts +49 -0
  109. package/ol/layers/Layer.d.ts.map +1 -0
  110. package/ol/layers/MapboxLayer.d.ts +42 -0
  111. package/ol/layers/MapboxLayer.d.ts.map +1 -0
  112. package/ol/layers/MapboxStyleLayer.d.ts +146 -0
  113. package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
  114. package/ol/layers/MaplibreLayer.d.ts +27 -0
  115. package/ol/layers/MaplibreLayer.d.ts.map +1 -0
  116. package/ol/layers/RealtimeLayer.d.ts +119 -0
  117. package/ol/layers/RealtimeLayer.d.ts.map +1 -0
  118. package/ol/layers/RoutingLayer.d.ts +24 -0
  119. package/ol/layers/RoutingLayer.d.ts.map +1 -0
  120. package/ol/layers/VectorLayer.d.ts +23 -0
  121. package/ol/layers/VectorLayer.d.ts.map +1 -0
  122. package/ol/layers/WMSLayer.d.ts +38 -0
  123. package/ol/layers/WMSLayer.d.ts.map +1 -0
  124. package/ol/layers/index.d.ts +9 -0
  125. package/ol/layers/index.d.ts.map +1 -0
  126. package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
  127. package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
  128. package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
  129. package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
  130. package/ol/styles/index.d.ts +3 -0
  131. package/ol/styles/index.d.ts.map +1 -0
  132. package/package.json +56 -95
  133. package/setupTests.d.ts +2 -0
  134. package/setupTests.d.ts.map +1 -0
  135. package/types/index.d.ts +10 -0
  136. package/types/realtime.d.ts +24 -0
  137. package/types/routing.d.ts +206 -0
  138. package/types/stops.d.ts +143 -0
  139. package/api/index.js +0 -3
  140. package/api/routing/RoutingAPI.js +0 -44
  141. package/api/routing/RoutingAPI.test.js +0 -41
  142. package/api/stops/StopsAPI.js +0 -41
  143. package/api/stops/StopsAPI.test.js +0 -34
  144. package/api/tralis/TralisAPI.js +0 -731
  145. package/api/tralis/TralisAPI.test.js +0 -75
  146. package/api/tralis/TralisAPIUtils.js +0 -73
  147. package/api/tralis/WebSocketConnector.js +0 -338
  148. package/api/tralis/WebSocketConnector.test.js +0 -356
  149. package/api/tralis/typedefs.js +0 -81
  150. package/common/Tracker.js +0 -197
  151. package/common/api/api.js +0 -64
  152. package/common/api/api.test.js +0 -68
  153. package/common/controls/Control.js +0 -146
  154. package/common/controls/Control.test.js +0 -98
  155. package/common/layers/Layer.js +0 -404
  156. package/common/layers/Layer.test.js +0 -585
  157. package/common/mixins/CopyrightMixin.js +0 -48
  158. package/common/mixins/SearchMixin.js +0 -176
  159. package/common/mixins/TralisLayerMixin.js +0 -930
  160. package/common/styles/index.js +0 -4
  161. package/common/styles/trackerDefaultStyle.js +0 -333
  162. package/common/styles/trackerSimpleStyle.js +0 -22
  163. package/common/trackerConfig.js +0 -190
  164. package/common/trackerConfig.test.js +0 -25
  165. package/common/typedefs.js +0 -23
  166. package/common/utils/createTrackerFilters.js +0 -87
  167. package/common/utils/createTrackerFilters.test.js +0 -95
  168. package/common/utils/getMapboxMapCopyrights.js +0 -32
  169. package/common/utils/getMapboxMapCopyrights.test.js +0 -47
  170. package/common/utils/getMapboxStyleUrl.js +0 -32
  171. package/common/utils/getVehiclePosition.js +0 -72
  172. package/common/utils/index.js +0 -6
  173. package/common/utils/removeDuplicate.js +0 -22
  174. package/common/utils/removeDuplicate.test.js +0 -22
  175. package/common/utils/sortByDelay.js +0 -23
  176. package/common/utils/timeUtils.js +0 -44
  177. package/common/utils/timeUtils.test.js +0 -16
  178. package/index.js +0 -2
  179. package/index.js.map +0 -1
  180. package/mapbox/controls/CopyrightControl.js +0 -58
  181. package/mapbox/index.js +0 -3
  182. package/mapbox/layers/Layer.js +0 -118
  183. package/mapbox/layers/Layer.test.js +0 -202
  184. package/mapbox/layers/TralisLayer.js +0 -329
  185. package/mapbox/layers/TralisLayer.test.js +0 -40
  186. package/mapbox/utils.js +0 -46
  187. package/module.js +0 -23
  188. package/ol/README.md +0 -0
  189. package/ol/controls/CopyrightControl.js +0 -80
  190. package/ol/controls/CopyrightControl.test.js +0 -211
  191. package/ol/controls/RoutingControl.js +0 -752
  192. package/ol/controls/RoutingControl.test.js +0 -216
  193. package/ol/controls/StopFinderControl.js +0 -38
  194. package/ol/controls/StopFinderControl.test.js +0 -59
  195. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  196. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  197. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  198. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  199. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  200. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  201. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
  202. package/ol/index.js +0 -13
  203. package/ol/layers/Layer.js +0 -193
  204. package/ol/layers/Layer.test.js +0 -197
  205. package/ol/layers/MapboxLayer.js +0 -378
  206. package/ol/layers/MapboxLayer.test.js +0 -186
  207. package/ol/layers/MapboxStyleLayer.js +0 -417
  208. package/ol/layers/MapboxStyleLayer.test.js +0 -262
  209. package/ol/layers/MaplibreLayer.js +0 -280
  210. package/ol/layers/RoutingLayer.js +0 -91
  211. package/ol/layers/RoutingLayer.test.js +0 -49
  212. package/ol/layers/TralisLayer.js +0 -359
  213. package/ol/layers/TralisLayer.test.js +0 -97
  214. package/ol/layers/VectorLayer.js +0 -43
  215. package/ol/layers/VectorLayer.test.js +0 -98
  216. package/ol/layers/WMSLayer.js +0 -80
  217. package/ol/layers/WMSLayer.test.js +0 -84
  218. package/ol/styles/fullTrajectoryDelayStyle.js +0 -35
  219. package/ol/styles/fullTrajectoryStyle.js +0 -51
  220. package/ol/styles/index.js +0 -2
@@ -1,216 +0,0 @@
1
- import fetch from 'jest-fetch-mock';
2
- import View from 'ol/View';
3
- import qs from 'query-string';
4
- import Map from 'ol/Map';
5
- import RoutingControl from './RoutingControl';
6
-
7
- import RoutingControlStation1 from './snapshots/RoutingControlStation1.json';
8
- import RoutingControlStation2 from './snapshots/RoutingControlStation2.json';
9
- import RoutingControlRouteGen5 from './snapshots/RoutingControlRouteGen5.json';
10
- import RoutingControlRouteGen10 from './snapshots/RoutingControlRouteGen10.json';
11
- import RoutingControlRouteGen30 from './snapshots/RoutingControlRouteGen30.json';
12
- import RoutingControlRouteGen100 from './snapshots/RoutingControlRouteGen100.json';
13
- import RoutingControlRouteOSM from './snapshots/RoutingControlRouteOSM.json';
14
-
15
- describe('RoutingControl', () => {
16
- let map;
17
-
18
- beforeEach(() => {
19
- const target = document.createElement('div');
20
- document.body.appendChild(target);
21
- map = new Map({
22
- target,
23
- view: new View({
24
- center: [0, 0],
25
- zoom: 0,
26
- }),
27
- });
28
- global.fetch = fetch;
29
- });
30
-
31
- afterEach(() => {
32
- if (map) {
33
- map.setTarget(null);
34
- map = null;
35
- }
36
- fetch.resetMocks();
37
- });
38
-
39
- test('should be activate by default', () => {
40
- const control = new RoutingControl();
41
- expect(control.active).toBe(true);
42
- expect(control.snapToClosestStation).toBe(false);
43
- expect(control.useRawViaPoints).toBe(false);
44
- });
45
-
46
- test('launch routing and add features', (done) => {
47
- fetch.mockResponseOnce(JSON.stringify(global.fetchRouteResponse));
48
-
49
- const control = new RoutingControl({
50
- url: 'https://foo.ch',
51
- apiKey: 'foo',
52
- });
53
- control.map = map;
54
- expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
55
- control.viaPoints = [
56
- [950476.4055933182, 6003322.253698345],
57
- [950389.0813034325, 6003656.659274571],
58
- ];
59
- control
60
- .drawRoute(control.viaPoints)
61
- .then(() => {
62
- // Should use correct URL
63
- expect(fetch.mock.calls[0][0]).toEqual(
64
- 'https://foo.ch?coord-punish=1000&coord-radius=100&elevation=false&graph=osm&key=foo&mot=bus&resolve-hops=false&via=47.3739194713294%2C8.538274823394632%7C47.37595378493421%2C8.537490375951839',
65
- );
66
- // routingLayer should contain three features (2 x viapoints, 1 x route)
67
- expect(
68
- control.routingLayer.olLayer.getSource().getFeatures().length,
69
- ).toEqual(3);
70
- done();
71
- })
72
- .catch(() => {});
73
- });
74
-
75
- test('launch routing and add features for multiple graphs', (done) => {
76
- fetch.mockResponses(
77
- [JSON.stringify(RoutingControlStation1), { status: 200 }],
78
- [JSON.stringify(RoutingControlStation2), { status: 200 }],
79
- [JSON.stringify(RoutingControlRouteGen5), { status: 200 }],
80
- [JSON.stringify(RoutingControlRouteGen10), { status: 200 }],
81
- [JSON.stringify(RoutingControlRouteGen30), { status: 200 }],
82
- [JSON.stringify(RoutingControlRouteGen100), { status: 200 }],
83
- [JSON.stringify(RoutingControlRouteOSM), { status: 200 }],
84
- );
85
-
86
- const control = new RoutingControl({
87
- url: 'https://foo.ch/',
88
- stopsApiUrl: 'https://foo.ch/',
89
- apiKey: 'foo',
90
- graphs: [
91
- ['gen5', 6, 7],
92
- ['gen10', 8],
93
- ['gen30', 9, 10],
94
- ['gen100', 11, 13],
95
- ['osm', 14, 99],
96
- ],
97
- });
98
- control.map = map;
99
- control.viaPoints = ['a4dca961d199ff76', 'e3666f03cba06b2b'];
100
- control
101
- .drawRoute(control.viaPoints)
102
- .then(() => {
103
- // Should use correct URL
104
- expect(fetch.mock.calls[0][0]).toEqual(
105
- 'https://foo.ch/lookup/a4dca961d199ff76?key=foo',
106
- );
107
- expect(fetch.mock.calls[1][0]).toEqual(
108
- 'https://foo.ch/lookup/e3666f03cba06b2b?key=foo',
109
- );
110
- expect(fetch.mock.calls[2][0]).toEqual(
111
- 'https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen5&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b',
112
- );
113
- expect(fetch.mock.calls[3][0]).toEqual(
114
- 'https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen10&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b',
115
- );
116
- expect(fetch.mock.calls[4][0]).toEqual(
117
- 'https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen30&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b',
118
- );
119
- expect(fetch.mock.calls[5][0]).toEqual(
120
- 'https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen100&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b',
121
- );
122
- expect(fetch.mock.calls[6][0]).toEqual(
123
- 'https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=osm&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b',
124
- );
125
- // routingLayer should contain seven features (2 x viapoints, 5 x route for each graph)
126
- expect(
127
- control.routingLayer.olLayer.getSource().getFeatures().length,
128
- ).toEqual(7);
129
- done();
130
- })
131
- .catch(() => {});
132
- });
133
-
134
- test('ignores Abort Error and returns undefined', (done) => {
135
- const control = new RoutingControl({
136
- url: 'https://foo.ch',
137
- apiKey: 'foo',
138
- });
139
- control.map = map;
140
- control.viaPoints = [
141
- [950476.4055933182, 6003322.253698345],
142
- [950389.0813034325, 6003656.659274571],
143
- ];
144
- const error = new Error('Error');
145
- error.name = 'AbortError';
146
- fetch.mockRejectOnce(error);
147
- return control.drawRoute().then((data) => {
148
- expect(data).toEqual([undefined]);
149
- done();
150
- });
151
- });
152
-
153
- test('calls routing api with @ before the coordinates when snapToClosestStation is true', (done) => {
154
- fetch.mockResponses(
155
- [JSON.stringify(RoutingControlStation1), { status: 200 }],
156
- [JSON.stringify(global.fetchRouteResponse), { status: 200 }],
157
- );
158
-
159
- const control = new RoutingControl({
160
- apiKey: 'foo',
161
- snapToClosestStation: true,
162
- });
163
- control.map = map;
164
- expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
165
- control.viaPoints = [
166
- [950476.4055933182, 6003322.253698345],
167
- [950389.0813034325, 6003656.659274571],
168
- 'e3666f03cba06b2b',
169
- ];
170
- control
171
- .drawRoute(control.viaPoints)
172
- .then(() => {
173
- const params = qs.parseUrl(fetch.mock.calls[1][0]).query;
174
- expect(params.via).toBe(
175
- '@47.3739194713294,8.538274823394632|@47.37595378493421,8.537490375951839|!e3666f03cba06b2b',
176
- );
177
- done();
178
- })
179
- .catch(() => {});
180
- });
181
-
182
- test('calls routing api with raw via points', (done) => {
183
- fetch.mockResponses(
184
- [JSON.stringify(RoutingControlStation1), { status: 200 }],
185
- [JSON.stringify(RoutingControlStation2), { status: 200 }],
186
- [JSON.stringify(global.fetchRouteResponse), { status: 200 }],
187
- );
188
-
189
- const control = new RoutingControl({
190
- apiKey: 'foo',
191
- useRawViaPoints: true,
192
- });
193
- control.map = map;
194
- expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
195
- control.viaPoints = [
196
- '46.2,7.1',
197
- '@46.2,7.1',
198
- '@46.2,7$1',
199
- 'station name$2', // will send a stops request fo the station name
200
- 'station name@46.2,7', // will use the coordinate
201
- 'stationname@46.2,7.7$3', // will use the coordinate
202
- '!stationid', // will send a stops lookup request fo the station id
203
- [950389, 6003656],
204
- ];
205
- control
206
- .drawRoute(control.viaPoints)
207
- .then(() => {
208
- const params = qs.parseUrl(fetch.mock.calls[2][0]).query;
209
- expect(params.via).toBe(
210
- '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',
211
- );
212
- done();
213
- })
214
- .catch(() => {});
215
- });
216
- });
@@ -1,38 +0,0 @@
1
- import { fromLonLat } from 'ol/proj';
2
- import Control from '../../common/controls/Control';
3
- import mixin from '../../common/mixins/SearchMixin';
4
-
5
- /**
6
- * Search stations.
7
- *
8
- * @example
9
- * import { Map } from 'ol';
10
- * import { StopFinderControl } from 'mobility-toolbox-js/ol';
11
- *
12
- * const map = new Map({
13
- * target: 'map',
14
- * });
15
- *
16
- * const control = new StopFinderControl({
17
- * apiKey: [yourApiKey]
18
- * });
19
- *
20
- * control.map = map;
21
- *
22
- *
23
- * @see <a href="/example/ol-search">Openlayers search example</a>
24
- *
25
- * @extends {Control}
26
- * @implements {SearchInterface}
27
- */
28
- class StopFinderControl extends mixin(Control) {
29
- /**
30
- * @private
31
- */
32
- onSuggestionClick({ geometry }) {
33
- const coord = fromLonLat(geometry.coordinates);
34
- this.map.getView().setCenter(coord);
35
- }
36
- }
37
-
38
- export default StopFinderControl;
@@ -1,59 +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
-
6
- describe('StopFinderControl', () => {
7
- let map;
8
-
9
- beforeEach(() => {
10
- const target = document.createElement('div');
11
- document.body.appendChild(target);
12
- map = new Map({
13
- target,
14
- view: new View({
15
- center: [0, 0],
16
- zoom: 0,
17
- }),
18
- });
19
- global.fetch = fetch;
20
- });
21
-
22
- afterEach(() => {
23
- if (map) {
24
- map.setTarget(null);
25
- map = null;
26
- }
27
- fetch.resetMocks();
28
- });
29
-
30
- test('should be activate by default', () => {
31
- const control = new StopFinderControl();
32
- expect(control.active).toBe(true);
33
- });
34
-
35
- test('launch a search and display results', (done) => {
36
- fetch.mockResponseOnce(JSON.stringify(global.stopsSearchResponse));
37
-
38
- const control = new StopFinderControl({
39
- url: 'https://foo.ch',
40
- apiKey: 'foo',
41
- apiParams: {
42
- limit: 10,
43
- foo: 'bar',
44
- },
45
- });
46
- control.map = map;
47
- expect(control.element).toBeDefined();
48
- control.search('foo').then(() => {
49
- // Correct url
50
- expect(fetch.mock.calls[0][0]).toEqual(
51
- 'https://foo.ch?foo=bar&key=foo&limit=10&q=foo',
52
- );
53
- expect(
54
- control.element.querySelector('div').querySelector('div').innerHTML,
55
- ).toBe('Bern');
56
- done();
57
- });
58
- });
59
- });
@@ -1,58 +0,0 @@
1
- {
2
- "features": [
3
- {
4
- "geometry": {
5
- "coordinates": [
6
- [8.5234620579, 47.3714721139],
7
- [8.5266667916, 47.3612282162],
8
- [8.5195902956, 47.3496592003],
9
- [8.5196416298, 47.3431513437],
10
- [8.5203273884, 47.3346117124],
11
- [8.5241638676, 47.3123040635],
12
- [8.5440189992, 47.2868746026],
13
- [8.557497175, 47.2682770155],
14
- [8.576034425, 47.2390513262],
15
- [8.5759843702, 47.2390450906],
16
- [8.5441590719, 47.2047577363],
17
- [8.5152951716, 47.1736235466],
18
- [8.4831280768, 47.176204783],
19
- [8.4574835563, 47.1782428598],
20
- [8.4448812278, 47.1712413881],
21
- [8.4509444203, 47.1420209114],
22
- [8.4304740108, 47.1417591601],
23
- [8.3947761627, 47.1213268081],
24
- [8.3423448296, 47.0842576333],
25
- [8.2951813058, 47.0612043674],
26
- [8.2951327267, 47.0611946876],
27
- [8.310157237, 47.050170361]
28
- ],
29
- "type": "LineString"
30
- },
31
- "properties": {
32
- "beeline": false,
33
- "lines": [],
34
- "station_from": {
35
- "id": "",
36
- "latitude": 8.5234620579,
37
- "longitude": 47.3714721139,
38
- "name": "zuerich hauptbahnhof szu gleisende",
39
- "platform": ""
40
- },
41
- "station_to": {
42
- "id": "e3666f03cba06b2b",
43
- "latitude": 8.310157237,
44
- "longitude": 47.050170361,
45
- "name": "",
46
- "platform": ""
47
- }
48
- },
49
- "type": "Feature"
50
- }
51
- ],
52
- "properties": {
53
- "lines": [],
54
- "network": "trafper10_qfanas",
55
- "skippedVias": []
56
- },
57
- "type": "FeatureCollection"
58
- }
@@ -1,292 +0,0 @@
1
- {
2
- "features": [
3
- {
4
- "geometry": {
5
- "coordinates": [
6
- [8.540219095, 47.3782217834],
7
- [8.5370343144, 47.3789658727],
8
- [8.530674816, 47.3807640208],
9
- [8.5280715635, 47.3815284469],
10
- [8.5271904833, 47.3815745317],
11
- [8.5263956544, 47.381564028],
12
- [8.5254800798, 47.3815275521],
13
- [8.5244815341, 47.3814226825],
14
- [8.5239538099, 47.3813171407],
15
- [8.523393662, 47.3811245095],
16
- [8.5228853838, 47.3808774183],
17
- [8.5223767447, 47.380612338],
18
- [8.52173351, 47.3802405763],
19
- [8.5210623419, 47.3797971121],
20
- [8.5206853972, 47.37949481],
21
- [8.5198087084, 47.3787114497],
22
- [8.5194630685, 47.3782177401],
23
- [8.5191675176, 47.3776685778],
24
- [8.5188720829, 47.3770416838],
25
- [8.5187622258, 47.3766523236],
26
- [8.5188017241, 47.3758322667],
27
- [8.5190750668, 47.3719180133],
28
- [8.5180896063, 47.367717511],
29
- [8.5178208196, 47.3649045475],
30
- [8.5183436291, 47.3593406639],
31
- [8.5243285644, 47.3438038479],
32
- [8.526525205, 47.3386019279],
33
- [8.5279634859, 47.3351611837],
34
- [8.5390129081, 47.3132892501],
35
- [8.5442440444, 47.306041545],
36
- [8.5464973268, 47.3043737812],
37
- [8.5480354419, 47.3032975488],
38
- [8.5502252706, 47.3024039189],
39
- [8.5522655672, 47.3019524625],
40
- [8.5543107366, 47.301790687],
41
- [8.5560408033, 47.3016281019],
42
- [8.5577523818, 47.3012696851],
43
- [8.5604187583, 47.2999618607],
44
- [8.5620892916, 47.2981061314],
45
- [8.565538656, 47.2948881144],
46
- [8.5660991131, 47.2945048304],
47
- [8.5665300301, 47.294248746],
48
- [8.5681675936, 47.2935310786],
49
- [8.5688617306, 47.2932184345],
50
- [8.5690968157, 47.2930811994],
51
- [8.5705204523, 47.2910072877],
52
- [8.5725938324, 47.2877845504],
53
- [8.5735903944, 47.2861555699],
54
- [8.5738677876, 47.2855231593],
55
- [8.57406396, 47.2848015934],
56
- [8.5742766136, 47.283612102],
57
- [8.5747145215, 47.2818266915],
58
- [8.5750872704, 47.2807075833],
59
- [8.5753401006, 47.2801653644],
60
- [8.5756699212, 47.2795144401],
61
- [8.5769282379, 47.2777748974],
62
- [8.5784722051, 47.2757986336],
63
- [8.5787016207, 47.2754005648],
64
- [8.5788207086, 47.2747876956],
65
- [8.5789051553, 47.2713146092],
66
- [8.579080466, 47.2696217256],
67
- [8.5792278833, 47.2690985293],
68
- [8.579429686, 47.2686467584],
69
- [8.5811716124, 47.2660567973],
70
- [8.581663284, 47.2655661663],
71
- [8.5821564871, 47.2651474818],
72
- [8.5836402912, 47.2640892743],
73
- [8.5844968311, 47.2633611223],
74
- [8.585300116, 47.2626155025],
75
- [8.5868479746, 47.2608549644],
76
- [8.5875474373, 47.2602003171],
77
- [8.5890683042, 47.2590337201],
78
- [8.592901262, 47.2560268714],
79
- [8.5931332061, 47.255754682],
80
- [8.593284724, 47.2554293248],
81
- [8.5933301752, 47.255087039],
82
- [8.5933484294, 47.2547090435],
83
- [8.5932338128, 47.2542963971],
84
- [8.5929327146, 47.2538136542],
85
- [8.5924470835, 47.2533507494],
86
- [8.5918573423, 47.2529608487],
87
- [8.5911083271, 47.2525365559],
88
- [8.5886010535, 47.2514461566],
89
- [8.5853243239, 47.250201443],
90
- [8.5807965811, 47.2485192674],
91
- [8.5790995166, 47.2479612289],
92
- [8.5784324052, 47.2477093396],
93
- [8.5775663231, 47.2473385703],
94
- [8.5770135231, 47.2469684555],
95
- [8.5767395918, 47.2466486185],
96
- [8.5765142946, 47.2463013257],
97
- [8.5763160116, 47.245858143],
98
- [8.5762185204, 47.2452901664],
99
- [8.5763234058, 47.2447582592],
100
- [8.5767405752, 47.2442490979],
101
- [8.5772341559, 47.2437396534],
102
- [8.577713069, 47.2431908121],
103
- [8.5783628406, 47.2423692382],
104
- [8.5786465492, 47.2418872388],
105
- [8.5788007851, 47.2414360592],
106
- [8.5788612128, 47.2409062623],
107
- [8.5787165502, 47.2401920057],
108
- [8.578439005, 47.2395650634],
109
- [8.5780554384, 47.2389211778],
110
- [8.5770215024, 47.237534929],
111
- [8.5759677384, 47.2362397044],
112
- [8.5747655634, 47.2353936157],
113
- [8.5718044235, 47.2334809934],
114
- [8.5682381397, 47.2309958628],
115
- [8.5620321816, 47.2264364253],
116
- [8.5437281005, 47.2137386243],
117
- [8.5401533078, 47.209753775],
118
- [8.5390442141, 47.2092740183],
119
- [8.5332196437, 47.2076286876],
120
- [8.5307715727, 47.2066894093],
121
- [8.5266657142, 47.2040655982],
122
- [8.5262051255, 47.203485239],
123
- [8.5261764094, 47.2020732088],
124
- [8.5279497182, 47.1997086044],
125
- [8.5280140602, 47.1983316746],
126
- [8.5274999919, 47.1977158439],
127
- [8.5258060669, 47.196841292],
128
- [8.5229585755, 47.1956987241],
129
- [8.5204564511, 47.1946607883],
130
- [8.5191968856, 47.1937190887],
131
- [8.5186780599, 47.1928603838],
132
- [8.5184799033, 47.1921965712],
133
- [8.5178389927, 47.1884873996],
134
- [8.516991867, 47.1831416671],
135
- [8.5162356534, 47.1781322416],
136
- [8.5156988503, 47.174672254],
137
- [8.515519032, 47.1736034607],
138
- [8.5133192695, 47.1731112764],
139
- [8.5127631467, 47.1730085216],
140
- [8.5121293333, 47.1729784536],
141
- [8.511417466, 47.1730030835],
142
- [8.5108382132, 47.1730624557],
143
- [8.5102076423, 47.1731942676],
144
- [8.4827384765, 47.1811199744],
145
- [8.4781446967, 47.1823579608],
146
- [8.4762537994, 47.1828247989],
147
- [8.4756747498, 47.1829019817],
148
- [8.4750155015, 47.1829259107],
149
- [8.474380547, 47.1828416711],
150
- [8.4716071106, 47.1820210169],
151
- [8.4577549079, 47.1778402835],
152
- [8.4561740931, 47.1773728855],
153
- [8.4552709794, 47.1770570287],
154
- [8.4546063292, 47.176793033],
155
- [8.4531681153, 47.1760860804],
156
- [8.4519910167, 47.1752328832],
157
- [8.4511318744, 47.1744488412],
158
- [8.4506721908, 47.1738591816],
159
- [8.4504409923, 47.1734923991],
160
- [8.4500961202, 47.1726948311],
161
- [8.4499479078, 47.1718325655],
162
- [8.449912011, 47.1713291328],
163
- [8.4501607223, 47.1691736341],
164
- [8.4519946226, 47.1545251619],
165
- [8.4523052847, 47.1507352992],
166
- [8.452192975, 47.1489821558],
167
- [8.4520101813, 47.1483810641],
168
- [8.4516669794, 47.1476644426],
169
- [8.4503169406, 47.1466958089],
170
- [8.4490273201, 47.1461314289],
171
- [8.43987041, 47.1443764101],
172
- [8.4360979764, 47.1435815971],
173
- [8.423682298, 47.1409359663],
174
- [8.4204504596, 47.1401180207],
175
- [8.4192291961, 47.1396606723],
176
- [8.4183246334, 47.1392186048],
177
- [8.4176306557, 47.1387567468],
178
- [8.4163462132, 47.1377241921],
179
- [8.4151952671, 47.136780445],
180
- [8.4144496091, 47.13637298],
181
- [8.4137319611, 47.1360552281],
182
- [8.4126989726, 47.1357941161],
183
- [8.4112709091, 47.135554328],
184
- [8.4085218917, 47.1351637509],
185
- [8.4061152751, 47.1347522371],
186
- [8.404975934, 47.1344379778],
187
- [8.4042062966, 47.1341565858],
188
- [8.403435047, 47.133785247],
189
- [8.4027692472, 47.1334130192],
190
- [8.402021142, 47.1328615666],
191
- [8.4013521299, 47.1323094472],
192
- [8.4007872749, 47.1316844884],
193
- [8.40030054, 47.1310049004],
194
- [8.3983025488, 47.1269016434],
195
- [8.3976178683, 47.1254680717],
196
- [8.3972594666, 47.1245894986],
197
- [8.396905582, 47.1239627615],
198
- [8.3963929335, 47.1233013638],
199
- [8.3951825526, 47.1219441194],
200
- [8.3915624977, 47.1184749189],
201
- [8.3899977956, 47.1164458916],
202
- [8.3877746093, 47.114431277],
203
- [8.3861160642, 47.113041655],
204
- [8.3786494203, 47.1080474642],
205
- [8.3737587899, 47.1048849449],
206
- [8.3505111493, 47.0897433615],
207
- [8.3347254868, 47.0798825119],
208
- [8.333929768, 47.0795468851],
209
- [8.3314936001, 47.0787562453],
210
- [8.3305411173, 47.0784937776],
211
- [8.3292418337, 47.077964125],
212
- [8.3276747763, 47.0771666645],
213
- [8.324492299, 47.0758239275],
214
- [8.3202537794, 47.0743093016],
215
- [8.3177124107, 47.0730981887],
216
- [8.3164287976, 47.0723838643],
217
- [8.3145180566, 47.0716428246],
218
- [8.3113908341, 47.0697712694],
219
- [8.3078568571, 47.068214853],
220
- [8.3044644987, 47.0668551629],
221
- [8.3036896166, 47.0665630784],
222
- [8.3022972686, 47.0659422412],
223
- [8.300530638, 47.0649669033],
224
- [8.2982094152, 47.0642934416],
225
- [8.2973935886, 47.0641529169],
226
- [8.296131808, 47.0636208135],
227
- [8.294110164, 47.0622442822],
228
- [8.2920069064, 47.0615231954],
229
- [8.2898257791, 47.0611174904],
230
- [8.2883025648, 47.0605260693],
231
- [8.2874074613, 47.059696105],
232
- [8.28689052, 47.0588464749],
233
- [8.2870970547, 47.057548471],
234
- [8.2875268931, 47.0564298509],
235
- [8.2886602275, 47.0556838358],
236
- [8.2904013555, 47.055086227],
237
- [8.2927097865, 47.054574329],
238
- [8.2944524118, 47.0540755976],
239
- [8.2950942647, 47.0538819066],
240
- [8.2956828963, 47.0536526269],
241
- [8.296294389, 47.0530424375],
242
- [8.296617502, 47.0523288797],
243
- [8.2973874504, 47.0507793126],
244
- [8.299026315, 47.0479244533],
245
- [8.3007348437, 47.04532092],
246
- [8.3011849769, 47.0446698596],
247
- [8.3015733593, 47.0442711368],
248
- [8.3020933167, 47.0438714234],
249
- [8.3027445562, 47.0434527284],
250
- [8.3031884484, 47.0432334934],
251
- [8.3037644957, 47.0430492432],
252
- [8.3043414098, 47.0429189569],
253
- [8.3049191924, 47.0428426346],
254
- [8.3056036891, 47.0428554592],
255
- [8.306288768, 47.0429042576],
256
- [8.3071337804, 47.0430777801],
257
- [8.3079015997, 47.0433598278],
258
- [8.3085926966, 47.0436543762],
259
- [8.3102705434, 47.0451035743],
260
- [8.3106176759, 47.0474492161],
261
- [8.3103050536, 47.0499931973]
262
- ],
263
- "type": "LineString"
264
- },
265
- "properties": {
266
- "beeline": false,
267
- "lines": [],
268
- "station_from": {
269
- "id": "",
270
- "latitude": 8.540219095,
271
- "longitude": 47.3782217834,
272
- "name": "zuerich hauptbahnhof szu gleisende",
273
- "platform": ""
274
- },
275
- "station_to": {
276
- "id": "e3666f03cba06b2b",
277
- "latitude": 8.3103050536,
278
- "longitude": 47.0499931973,
279
- "name": "",
280
- "platform": ""
281
- }
282
- },
283
- "type": "Feature"
284
- }
285
- ],
286
- "properties": {
287
- "lines": [],
288
- "network": "trafper100_qfanas",
289
- "skippedVias": []
290
- },
291
- "type": "FeatureCollection"
292
- }