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.
- package/api/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/api/{tralis/TralisAPIUtils.js → TralisAPIUtils.js} +2 -32
- package/api/index.js +3 -3
- package/{ol/README.md → api/typedefs.js} +0 -0
- package/common/Tracker.js +14 -118
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +26 -91
- package/common/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +53 -244
- package/common/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +20 -44
- package/common/mixins/SearchMixin.js +100 -166
- package/common/mixins/TralisLayerMixin.js +443 -894
- package/common/styles/index.js +4 -4
- package/common/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +2 -11
- package/common/styles/trackerSimpleStyle.js +4 -8
- package/common/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +15 -17
- package/common/typedefs.js +0 -23
- package/common/utils/createTrackerFilters.js +10 -41
- package/common/utils/createTrackerFilters.test.js +40 -56
- package/common/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +32 -39
- package/common/utils/getMapboxStyleUrl.js +3 -13
- package/common/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -6
- package/common/utils/removeDuplicate.js +3 -17
- package/common/utils/removeDuplicate.test.js +17 -20
- package/common/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +8 -32
- package/common/utils/timeUtils.test.js +7 -13
- package/index.js +8 -2
- package/mapbox/controls/CopyrightControl.js +9 -38
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -3
- package/mapbox/layers/Layer.js +15 -76
- package/mapbox/layers/Layer.test.js +81 -101
- package/mapbox/layers/TralisLayer.js +46 -193
- package/mapbox/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +8 -46
- package/ol/controls/CopyrightControl.test.js +75 -121
- package/ol/controls/RoutingControl.js +167 -532
- package/ol/controls/RoutingControl.test.js +99 -164
- package/ol/controls/StopFinderControl.js +3 -31
- package/ol/controls/StopFinderControl.test.js +18 -29
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -13
- package/ol/layers/Layer.js +23 -128
- package/ol/layers/Layer.test.js +79 -102
- package/ol/layers/MapboxLayer.js +62 -237
- package/ol/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +38 -268
- package/ol/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +46 -187
- package/ol/layers/RoutingLayer.js +21 -51
- package/ol/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +102 -276
- package/ol/layers/TralisLayer.test.js +32 -50
- package/ol/layers/VectorLayer.js +3 -24
- package/ol/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +15 -57
- package/ol/layers/WMSLayer.test.js +35 -43
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +17 -25
- package/ol/styles/index.js +2 -2
- package/package.json +35 -62
- package/api/routing/RoutingAPI.js +0 -44
- package/api/routing/RoutingAPI.test.js +0 -41
- package/api/stops/StopsAPI.js +0 -41
- package/api/stops/StopsAPI.test.js +0 -34
- package/api/tralis/TralisAPI.js +0 -731
- package/api/tralis/TralisAPI.test.js +0 -75
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/typedefs.js +0 -81
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/index.js.map +0 -1
- package/module.js +0 -23
- package/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/ol/controls/snapshots/RoutingControlStation2.json +0 -49
|
@@ -1,33 +1,29 @@
|
|
|
1
|
-
import fetch from
|
|
2
|
-
import View from
|
|
3
|
-
import qs from
|
|
4
|
-
import Map from
|
|
5
|
-
import RoutingControl from
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
|
|
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(
|
|
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:
|
|
51
|
-
apiKey:
|
|
43
|
+
url: "https://foo.ch",
|
|
44
|
+
apiKey: "foo"
|
|
52
45
|
});
|
|
53
|
-
control.map
|
|
54
|
-
expect(map.getTarget().querySelector(
|
|
46
|
+
control.attachToMap(map);
|
|
47
|
+
expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
|
|
55
48
|
control.viaPoints = [
|
|
56
|
-
[950476.4055933182,
|
|
57
|
-
[950389.0813034325,
|
|
49
|
+
[950476.4055933182, 6003322253698345e-9],
|
|
50
|
+
[950389.0813034325, 6003656659274571e-9]
|
|
58
51
|
];
|
|
59
|
-
control
|
|
60
|
-
.
|
|
61
|
-
.
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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:
|
|
88
|
-
stopsApiUrl:
|
|
89
|
-
apiKey:
|
|
62
|
+
url: "https://foo.ch/",
|
|
63
|
+
stopsApiUrl: "https://foo.ch/",
|
|
64
|
+
apiKey: "foo",
|
|
90
65
|
graphs: [
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
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:
|
|
137
|
-
apiKey:
|
|
90
|
+
url: "https://foo.ch",
|
|
91
|
+
apiKey: "foo"
|
|
138
92
|
});
|
|
139
|
-
control.map
|
|
93
|
+
control.attachToMap(map);
|
|
140
94
|
control.viaPoints = [
|
|
141
|
-
[950476.4055933182,
|
|
142
|
-
[950389.0813034325,
|
|
95
|
+
[950476.4055933182, 6003322253698345e-9],
|
|
96
|
+
[950389.0813034325, 6003656659274571e-9]
|
|
143
97
|
];
|
|
144
|
-
const error = new Error(
|
|
145
|
-
error.name =
|
|
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([
|
|
102
|
+
expect(data).toEqual([void 0]);
|
|
149
103
|
done();
|
|
150
104
|
});
|
|
151
105
|
});
|
|
152
|
-
|
|
153
|
-
|
|
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:
|
|
161
|
-
snapToClosestStation: true
|
|
109
|
+
apiKey: "foo",
|
|
110
|
+
snapToClosestStation: true
|
|
162
111
|
});
|
|
163
|
-
control.map
|
|
164
|
-
expect(map.getTarget().querySelector(
|
|
112
|
+
control.attachToMap(map);
|
|
113
|
+
expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
|
|
165
114
|
control.viaPoints = [
|
|
166
|
-
[950476.4055933182,
|
|
167
|
-
[950389.0813034325,
|
|
168
|
-
|
|
115
|
+
[950476.4055933182, 6003322253698345e-9],
|
|
116
|
+
[950389.0813034325, 6003656659274571e-9],
|
|
117
|
+
"e3666f03cba06b2b"
|
|
169
118
|
];
|
|
170
|
-
control
|
|
171
|
-
.
|
|
172
|
-
.
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
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
|
-
|
|
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:
|
|
191
|
-
useRawViaPoints: true
|
|
129
|
+
apiKey: "foo",
|
|
130
|
+
useRawViaPoints: true
|
|
192
131
|
});
|
|
193
|
-
control.map
|
|
194
|
-
expect(map.getTarget().querySelector(
|
|
132
|
+
control.attachToMap(map);
|
|
133
|
+
expect(map.getTarget().querySelector("#ol-toggle-routing")).toBeDefined();
|
|
195
134
|
control.viaPoints = [
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
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
|
-
.
|
|
207
|
-
.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
2
|
-
import Control from
|
|
3
|
-
import mixin from
|
|
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
|
|
2
|
-
import View from
|
|
3
|
-
import Map from
|
|
4
|
-
import StopFinderControl from
|
|
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(
|
|
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:
|
|
40
|
-
apiKey:
|
|
33
|
+
url: "https://foo.ch",
|
|
34
|
+
apiKey: "foo",
|
|
41
35
|
apiParams: {
|
|
42
36
|
limit: 10,
|
|
43
|
-
foo:
|
|
44
|
-
}
|
|
37
|
+
foo: "bar"
|
|
38
|
+
}
|
|
45
39
|
});
|
|
46
|
-
control.map
|
|
40
|
+
control.attachToMap(map);
|
|
47
41
|
expect(control.element).toBeDefined();
|
|
48
|
-
control.search(
|
|
49
|
-
|
|
50
|
-
expect(
|
|
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
|
});
|
package/ol/index.js
CHANGED
|
@@ -1,13 +1,5 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
4
|
-
export
|
|
5
|
-
export
|
|
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";
|