mobility-toolbox-js 2.0.0 → 2.0.1-beta.13

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 (102) hide show
  1. package/api/RoutingAPI.js +15 -0
  2. package/api/RoutingAPI.test.js +25 -0
  3. package/api/StopsAPI.js +12 -0
  4. package/api/StopsAPI.test.js +22 -0
  5. package/api/TralisAPI.js +359 -0
  6. package/api/TralisAPI.test.js +67 -0
  7. package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
  8. package/api/index.js +3 -3
  9. package/{ol/README.md → api/typedefs.js} +0 -0
  10. package/common/Tracker.js +14 -118
  11. package/common/api/HttpAPI.js +30 -0
  12. package/common/api/HttpAPI.test.js +50 -0
  13. package/common/api/WebSocketAPI.js +175 -0
  14. package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
  15. package/common/controls/Control.js +26 -91
  16. package/common/controls/Control.test.js +32 -43
  17. package/common/index.js +4 -0
  18. package/common/layers/Layer.js +53 -244
  19. package/common/layers/Layer.test.js +185 -244
  20. package/common/mixins/CopyrightMixin.js +20 -44
  21. package/common/mixins/SearchMixin.js +100 -166
  22. package/common/mixins/TralisLayerMixin.js +443 -894
  23. package/common/styles/index.js +4 -4
  24. package/common/styles/trackerDefaultStyle.js +39 -175
  25. package/common/styles/trackerDelayStyle.js +2 -11
  26. package/common/styles/trackerSimpleStyle.js +4 -8
  27. package/common/trackerConfig.js +61 -99
  28. package/common/trackerConfig.test.js +15 -17
  29. package/common/typedefs.js +0 -23
  30. package/common/utils/createTrackerFilters.js +10 -41
  31. package/common/utils/createTrackerFilters.test.js +40 -56
  32. package/common/utils/getMapboxMapCopyrights.js +3 -16
  33. package/common/utils/getMapboxMapCopyrights.test.js +32 -39
  34. package/common/utils/getMapboxStyleUrl.js +3 -13
  35. package/common/utils/getVehiclePosition.js +3 -33
  36. package/common/utils/index.js +5 -6
  37. package/common/utils/removeDuplicate.js +3 -17
  38. package/common/utils/removeDuplicate.test.js +17 -20
  39. package/common/utils/sortByDelay.js +2 -7
  40. package/common/utils/timeUtils.js +8 -32
  41. package/common/utils/timeUtils.test.js +7 -13
  42. package/index.js +8 -2
  43. package/mapbox/controls/CopyrightControl.js +9 -38
  44. package/mapbox/controls/index.js +1 -0
  45. package/mapbox/index.js +4 -3
  46. package/mapbox/layers/Layer.js +15 -76
  47. package/mapbox/layers/Layer.test.js +81 -101
  48. package/mapbox/layers/TralisLayer.js +46 -193
  49. package/mapbox/layers/TralisLayer.test.js +12 -14
  50. package/mapbox/layers/index.js +2 -0
  51. package/mapbox/utils.js +7 -21
  52. package/mbt.js +50444 -0
  53. package/mbt.js.map +7 -0
  54. package/mbt.min.js +1005 -0
  55. package/mbt.min.js.map +7 -0
  56. package/ol/controls/CopyrightControl.js +8 -46
  57. package/ol/controls/CopyrightControl.test.js +75 -121
  58. package/ol/controls/RoutingControl.js +167 -532
  59. package/ol/controls/RoutingControl.test.js +99 -164
  60. package/ol/controls/StopFinderControl.js +3 -31
  61. package/ol/controls/StopFinderControl.test.js +18 -29
  62. package/ol/controls/index.js +3 -0
  63. package/ol/index.js +5 -13
  64. package/ol/layers/Layer.js +23 -128
  65. package/ol/layers/Layer.test.js +79 -102
  66. package/ol/layers/MapboxLayer.js +62 -237
  67. package/ol/layers/MapboxLayer.test.js +58 -84
  68. package/ol/layers/MapboxStyleLayer.js +38 -268
  69. package/ol/layers/MapboxStyleLayer.test.js +97 -128
  70. package/ol/layers/MaplibreLayer.js +46 -187
  71. package/ol/layers/RoutingLayer.js +21 -51
  72. package/ol/layers/RoutingLayer.test.js +15 -24
  73. package/ol/layers/TralisLayer.js +102 -276
  74. package/ol/layers/TralisLayer.test.js +32 -50
  75. package/ol/layers/VectorLayer.js +3 -24
  76. package/ol/layers/VectorLayer.test.js +34 -45
  77. package/ol/layers/WMSLayer.js +15 -57
  78. package/ol/layers/WMSLayer.test.js +35 -43
  79. package/ol/layers/index.js +8 -0
  80. package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
  81. package/ol/styles/fullTrajectoryStyle.js +17 -25
  82. package/ol/styles/index.js +2 -2
  83. package/package.json +35 -62
  84. package/api/routing/RoutingAPI.js +0 -44
  85. package/api/routing/RoutingAPI.test.js +0 -41
  86. package/api/stops/StopsAPI.js +0 -41
  87. package/api/stops/StopsAPI.test.js +0 -34
  88. package/api/tralis/TralisAPI.js +0 -731
  89. package/api/tralis/TralisAPI.test.js +0 -75
  90. package/api/tralis/WebSocketConnector.js +0 -338
  91. package/api/tralis/typedefs.js +0 -81
  92. package/common/api/api.js +0 -64
  93. package/common/api/api.test.js +0 -68
  94. package/index.js.map +0 -1
  95. package/module.js +0 -23
  96. package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
  97. package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
  98. package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
  99. package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
  100. package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
  101. package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
  102. package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
@@ -1,33 +1,29 @@
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', () => {
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
+ import RoutingControlStation1 from "./snapshots/RoutingControlStation1.json";
7
+ import RoutingControlStation2 from "./snapshots/RoutingControlStation2.json";
8
+ import RoutingControlRouteGen5 from "./snapshots/RoutingControlRouteGen5.json";
9
+ import RoutingControlRouteGen10 from "./snapshots/RoutingControlRouteGen10.json";
10
+ import RoutingControlRouteGen30 from "./snapshots/RoutingControlRouteGen30.json";
11
+ import RoutingControlRouteGen100 from "./snapshots/RoutingControlRouteGen100.json";
12
+ import RoutingControlRouteOSM from "./snapshots/RoutingControlRouteOSM.json";
13
+ describe("RoutingControl", () => {
16
14
  let map;
17
-
18
15
  beforeEach(() => {
19
- const target = document.createElement('div');
16
+ const target = document.createElement("div");
20
17
  document.body.appendChild(target);
21
18
  map = new Map({
22
19
  target,
23
20
  view: new View({
24
21
  center: [0, 0],
25
- zoom: 0,
26
- }),
22
+ zoom: 0
23
+ })
27
24
  });
28
25
  global.fetch = fetch;
29
26
  });
30
-
31
27
  afterEach(() => {
32
28
  if (map) {
33
29
  map.setTarget(null);
@@ -35,182 +31,121 @@ describe('RoutingControl', () => {
35
31
  }
36
32
  fetch.resetMocks();
37
33
  });
38
-
39
- test('should be activate by default', () => {
34
+ test("should be activate by default", () => {
40
35
  const control = new RoutingControl();
41
36
  expect(control.active).toBe(true);
42
37
  expect(control.snapToClosestStation).toBe(false);
43
38
  expect(control.useRawViaPoints).toBe(false);
44
39
  });
45
-
46
- test('launch routing and add features', (done) => {
40
+ test("launch routing and add features", (done) => {
47
41
  fetch.mockResponseOnce(JSON.stringify(global.fetchRouteResponse));
48
-
49
42
  const control = new RoutingControl({
50
- url: 'https://foo.ch',
51
- apiKey: 'foo',
43
+ url: "https://foo.ch",
44
+ apiKey: "foo"
52
45
  });
53
- control.map = map;
54
- expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
46
+ control.attachToMap(map);
47
+ expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
55
48
  control.viaPoints = [
56
- [950476.4055933182, 6003322.253698345],
57
- [950389.0813034325, 6003656.659274571],
49
+ [950476.4055933182, 6003322253698345e-9],
50
+ [950389.0813034325, 6003656659274571e-9]
58
51
  ];
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(() => {});
52
+ control.drawRoute(control.viaPoints).then(() => {
53
+ expect(fetch.mock.calls[0][0]).toEqual("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");
54
+ expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(3);
55
+ done();
56
+ }).catch(() => {
57
+ });
73
58
  });
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
-
59
+ test("launch routing and add features for multiple graphs", (done) => {
60
+ 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 }]);
86
61
  const control = new RoutingControl({
87
- url: 'https://foo.ch/',
88
- stopsApiUrl: 'https://foo.ch/',
89
- apiKey: 'foo',
62
+ url: "https://foo.ch/",
63
+ stopsApiUrl: "https://foo.ch/",
64
+ apiKey: "foo",
90
65
  graphs: [
91
- ['gen5', 6, 7],
92
- ['gen10', 8],
93
- ['gen30', 9, 10],
94
- ['gen100', 11, 13],
95
- ['osm', 14, 99],
96
- ],
66
+ ["gen5", 6, 7],
67
+ ["gen10", 8],
68
+ ["gen30", 9, 10],
69
+ ["gen100", 11, 13],
70
+ ["osm", 14, 99]
71
+ ]
72
+ });
73
+ control.attachToMap(map);
74
+ control.viaPoints = ["a4dca961d199ff76", "e3666f03cba06b2b"];
75
+ control.drawRoute(control.viaPoints).then(() => {
76
+ expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch/lookup/a4dca961d199ff76?key=foo");
77
+ expect(fetch.mock.calls[1][0]).toEqual("https://foo.ch/lookup/e3666f03cba06b2b?key=foo");
78
+ expect(fetch.mock.calls[2][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen5&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
79
+ expect(fetch.mock.calls[3][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen10&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
80
+ expect(fetch.mock.calls[4][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen30&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
81
+ expect(fetch.mock.calls[5][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=gen100&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
82
+ expect(fetch.mock.calls[6][0]).toEqual("https://foo.ch/?coord-punish=1000&coord-radius=100&elevation=false&graph=osm&key=foo&mot=bus&resolve-hops=false&via=%21a4dca961d199ff76%7C%21e3666f03cba06b2b");
83
+ expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(7);
84
+ done();
85
+ }).catch(() => {
97
86
  });
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
87
  });
133
-
134
- test('ignores Abort Error and returns undefined', (done) => {
88
+ test("ignores Abort Error and returns undefined", (done) => {
135
89
  const control = new RoutingControl({
136
- url: 'https://foo.ch',
137
- apiKey: 'foo',
90
+ url: "https://foo.ch",
91
+ apiKey: "foo"
138
92
  });
139
- control.map = map;
93
+ control.attachToMap(map);
140
94
  control.viaPoints = [
141
- [950476.4055933182, 6003322.253698345],
142
- [950389.0813034325, 6003656.659274571],
95
+ [950476.4055933182, 6003322253698345e-9],
96
+ [950389.0813034325, 6003656659274571e-9]
143
97
  ];
144
- const error = new Error('Error');
145
- error.name = 'AbortError';
98
+ const error = new Error("Error");
99
+ error.name = "AbortError";
146
100
  fetch.mockRejectOnce(error);
147
101
  return control.drawRoute().then((data) => {
148
- expect(data).toEqual([undefined]);
102
+ expect(data).toEqual([void 0]);
149
103
  done();
150
104
  });
151
105
  });
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
-
106
+ test("calls routing api with @ before the coordinates when snapToClosestStation is true", (done) => {
107
+ fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
159
108
  const control = new RoutingControl({
160
- apiKey: 'foo',
161
- snapToClosestStation: true,
109
+ apiKey: "foo",
110
+ snapToClosestStation: true
162
111
  });
163
- control.map = map;
164
- expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
112
+ control.attachToMap(map);
113
+ expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
165
114
  control.viaPoints = [
166
- [950476.4055933182, 6003322.253698345],
167
- [950389.0813034325, 6003656.659274571],
168
- 'e3666f03cba06b2b',
115
+ [950476.4055933182, 6003322253698345e-9],
116
+ [950389.0813034325, 6003656659274571e-9],
117
+ "e3666f03cba06b2b"
169
118
  ];
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(() => {});
119
+ control.drawRoute(control.viaPoints).then(() => {
120
+ const params = qs.parseUrl(fetch.mock.calls[1][0]).query;
121
+ expect(params.via).toBe("@47.3739194713294,8.538274823394632|@47.37595378493421,8.537490375951839|!e3666f03cba06b2b");
122
+ done();
123
+ }).catch(() => {
124
+ });
180
125
  });
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
-
126
+ test("calls routing api with raw via points", (done) => {
127
+ fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(RoutingControlStation2), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
189
128
  const control = new RoutingControl({
190
- apiKey: 'foo',
191
- useRawViaPoints: true,
129
+ apiKey: "foo",
130
+ useRawViaPoints: true
192
131
  });
193
- control.map = map;
194
- expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
132
+ control.attachToMap(map);
133
+ expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
195
134
  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],
135
+ "46.2,7.1",
136
+ "@46.2,7.1",
137
+ "@46.2,7$1",
138
+ "station name$2",
139
+ "station name@46.2,7",
140
+ "stationname@46.2,7.7$3",
141
+ "!stationid",
142
+ [950389, 6003656]
204
143
  ];
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(() => {});
144
+ control.drawRoute(control.viaPoints).then(() => {
145
+ const params = qs.parseUrl(fetch.mock.calls[2][0]).query;
146
+ expect(params.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");
147
+ done();
148
+ }).catch(() => {
149
+ });
215
150
  });
216
151
  });
@@ -1,38 +1,10 @@
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
- */
1
+ import { fromLonLat } from "ol/proj";
2
+ import Control from "../../common/controls/Control";
3
+ import mixin from "../../common/mixins/SearchMixin";
28
4
  class StopFinderControl extends mixin(Control) {
29
- /**
30
- * @private
31
- */
32
5
  onSuggestionClick({ geometry }) {
33
6
  const coord = fromLonLat(geometry.coordinates);
34
7
  this.map.getView().setCenter(coord);
35
8
  }
36
9
  }
37
-
38
10
  export default StopFinderControl;
@@ -1,24 +1,21 @@
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', () => {
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", () => {
7
6
  let map;
8
-
9
7
  beforeEach(() => {
10
- const target = document.createElement('div');
8
+ const target = document.createElement("div");
11
9
  document.body.appendChild(target);
12
10
  map = new Map({
13
11
  target,
14
12
  view: new View({
15
13
  center: [0, 0],
16
- zoom: 0,
17
- }),
14
+ zoom: 0
15
+ })
18
16
  });
19
17
  global.fetch = fetch;
20
18
  });
21
-
22
19
  afterEach(() => {
23
20
  if (map) {
24
21
  map.setTarget(null);
@@ -26,33 +23,25 @@ describe('StopFinderControl', () => {
26
23
  }
27
24
  fetch.resetMocks();
28
25
  });
29
-
30
- test('should be activate by default', () => {
26
+ test("should be activate by default", () => {
31
27
  const control = new StopFinderControl();
32
28
  expect(control.active).toBe(true);
33
29
  });
34
-
35
- test('launch a search and display results', (done) => {
30
+ test("launch a search and display results", (done) => {
36
31
  fetch.mockResponseOnce(JSON.stringify(global.stopsSearchResponse));
37
-
38
32
  const control = new StopFinderControl({
39
- url: 'https://foo.ch',
40
- apiKey: 'foo',
33
+ url: "https://foo.ch",
34
+ apiKey: "foo",
41
35
  apiParams: {
42
36
  limit: 10,
43
- foo: 'bar',
44
- },
37
+ foo: "bar"
38
+ }
45
39
  });
46
- control.map = map;
40
+ control.attachToMap(map);
47
41
  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');
42
+ control.search("foo").then(() => {
43
+ expect(fetch.mock.calls[0][0]).toEqual("https://foo.ch?foo=bar&key=foo&limit=10&q=foo");
44
+ expect(control.element.querySelector("div").querySelector("div").innerHTML).toBe("Bern");
56
45
  done();
57
46
  });
58
47
  });
@@ -0,0 +1,3 @@
1
+ export { default as CopyrightControl } from "./CopyrightControl";
2
+ export { default as RoutingControl } from "./RoutingControl";
3
+ export { default as StopFinderControl } from "./StopFinderControl";
package/ol/index.js CHANGED
@@ -1,13 +1,5 @@
1
- export { default as Layer } from './layers/Layer';
2
- export { default as MapboxLayer } from './layers/MapboxLayer';
3
- export { default as MaplibreLayer } from './layers/MaplibreLayer';
4
- export { default as MapboxStyleLayer } from './layers/MapboxStyleLayer';
5
- export { default as RoutingLayer } from './layers/RoutingLayer';
6
- export { default as TralisLayer } from './layers/TralisLayer';
7
- export { default as VectorLayer } from './layers/VectorLayer';
8
- export { default as WMSLayer } from './layers/WMSLayer';
9
- export { default as CopyrightControl } from './controls/CopyrightControl';
10
- export { default as RoutingControl } from './controls/RoutingControl';
11
- export { default as StopFinderControl } from './controls/StopFinderControl';
12
- export * from '../common/styles';
13
- export * from './styles';
1
+ export * from "../api";
2
+ export * from "../common";
3
+ export * from "./controls";
4
+ export * from "./layers";
5
+ export * from "./styles";