mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/api/RealtimeAPI.d.ts +6 -6
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +170 -197
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.js +8 -38
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.d.ts +1 -1
- package/api/StopsAPI.d.ts.map +1 -1
- package/api/StopsAPI.js +8 -40
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/api/index.d.ts +3 -4
- package/api/index.d.ts.map +1 -1
- package/api/index.js +3 -10
- package/api/typedefs.js +1 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +21 -48
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +8 -4
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +125 -129
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.d.ts +5 -5
- package/common/controls/Control.d.ts.map +1 -1
- package/common/controls/Control.js +44 -77
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/index.js +2 -18
- package/common/layers/Layer.d.ts +11 -11
- package/common/layers/Layer.d.ts.map +1 -1
- package/common/layers/Layer.js +70 -104
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/CopyrightMixin.js +23 -52
- package/common/mixins/MapboxLayerMixin.js +162 -204
- package/common/mixins/RealtimeLayerMixin.js +580 -635
- package/common/mixins/StopFinderMixin.d.ts +3 -3
- package/common/mixins/StopFinderMixin.d.ts.map +1 -1
- package/common/mixins/StopFinderMixin.js +115 -157
- package/common/mixins/UserInteractionsLayerMixin.js +142 -175
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/index.js +4 -24
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +67 -78
- package/common/styles/realtimeDelayStyle.js +4 -17
- package/common/styles/realtimeSimpleStyle.js +5 -7
- package/common/typedefs.js +1 -0
- package/common/utils/cleanStopTime.js +3 -5
- package/common/utils/compareDepartures.d.ts +1 -1
- package/common/utils/compareDepartures.d.ts.map +1 -1
- package/common/utils/compareDepartures.js +8 -11
- package/common/utils/createCanvas.js +3 -5
- package/common/utils/createTrackerFilters.d.ts +1 -1
- package/common/utils/createTrackerFilters.d.ts.map +1 -1
- package/common/utils/createTrackerFilters.js +22 -32
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getLayersAsFlatArray.js +6 -8
- package/common/utils/getMapboxMapCopyrights.js +9 -11
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/getMapboxRender.js +12 -15
- package/common/utils/getMaplibreRender.js +10 -13
- package/common/utils/getRealtimeModeSuffix.js +2 -6
- package/common/utils/getUrlWithParams.js +5 -8
- package/common/utils/getVehiclePosition.js +20 -23
- package/common/utils/index.js +12 -37
- package/common/utils/removeDuplicate.d.ts +1 -1
- package/common/utils/removeDuplicate.d.ts.map +1 -1
- package/common/utils/removeDuplicate.js +6 -21
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/renderTrajectories.js +31 -43
- package/common/utils/sortByDelay.js +4 -6
- package/common/utils/timeUtils.js +14 -24
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.js +27 -39
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/iife.js +3 -5
- package/index.d.ts +4 -0
- package/index.js +9 -10
- package/mapbox/controls/CopyrightControl.d.ts +0 -1
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
- package/mapbox/controls/CopyrightControl.js +18 -38
- package/mapbox/controls/index.js +1 -5
- package/mapbox/index.js +4 -20
- package/mapbox/layers/Layer.d.ts +1 -1
- package/mapbox/layers/Layer.d.ts.map +1 -1
- package/mapbox/layers/Layer.js +29 -71
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.d.ts +4 -4
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mapbox/layers/RealtimeLayer.js +83 -125
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +2 -7
- package/mapbox/utils.js +19 -33
- package/mbt.js +59 -37
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +26 -47
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +6 -5
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.js +209 -270
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.js +9 -32
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/controls/index.js +3 -9
- package/ol/index.js +5 -21
- package/ol/layers/Layer.d.ts +1 -1
- package/ol/layers/Layer.d.ts.map +1 -1
- package/ol/layers/Layer.js +40 -72
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts +7 -7
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +30 -66
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.d.ts +3 -3
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
- package/ol/layers/MapboxStyleLayer.js +92 -135
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/MaplibreLayer.d.ts +1 -1
- package/ol/layers/MaplibreLayer.d.ts.map +1 -1
- package/ol/layers/MaplibreLayer.js +14 -48
- package/ol/layers/RealtimeLayer.d.ts +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +111 -147
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.d.ts +2 -2
- package/ol/layers/RoutingLayer.d.ts.map +1 -1
- package/ol/layers/RoutingLayer.js +29 -61
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.d.ts +1 -1
- package/ol/layers/VectorLayer.d.ts.map +1 -1
- package/ol/layers/VectorLayer.js +14 -48
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.d.ts +1 -1
- package/ol/layers/WMSLayer.d.ts.map +1 -1
- package/ol/layers/WMSLayer.js +34 -68
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/ol/layers/index.js +8 -19
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
- package/ol/styles/fullTrajectoryStyle.js +16 -18
- package/ol/styles/index.js +2 -7
- package/package.json +5 -2
- package/setupTests.js +12 -14
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RoutingControl.test.d.ts","sourceRoot":"","sources":["../../../src/ol/controls/RoutingControl.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,150 @@
|
|
|
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, 6003322.253698345],
|
|
49
|
+
[950389.0813034325, 6003656.659274571],
|
|
50
|
+
];
|
|
51
|
+
control.drawRoute(control.viaPoints).then(() => {
|
|
52
|
+
// Should use correct URL
|
|
53
|
+
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');
|
|
54
|
+
// routingLayer should contain three features (2 x viapoints, 1 x route)
|
|
55
|
+
expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(3);
|
|
56
|
+
done();
|
|
57
|
+
});
|
|
58
|
+
});
|
|
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 }]);
|
|
61
|
+
const control = new RoutingControl({
|
|
62
|
+
url: 'https://foo.ch/',
|
|
63
|
+
stopsApiUrl: 'https://foo.ch/',
|
|
64
|
+
apiKey: 'foo',
|
|
65
|
+
graphs: [
|
|
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
|
+
// Should use correct URL
|
|
77
|
+
expect(fetch.mock.calls[0][0]).toEqual('https://foo.ch/lookup/a4dca961d199ff76?key=foo');
|
|
78
|
+
expect(fetch.mock.calls[1][0]).toEqual('https://foo.ch/lookup/e3666f03cba06b2b?key=foo');
|
|
79
|
+
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');
|
|
80
|
+
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');
|
|
81
|
+
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');
|
|
82
|
+
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');
|
|
83
|
+
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');
|
|
84
|
+
// routingLayer should contain seven features (2 x viapoints, 5 x route for each graph)
|
|
85
|
+
expect(control.routingLayer.olLayer.getSource().getFeatures().length).toEqual(7);
|
|
86
|
+
done();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
test('ignores Abort Error and returns undefined', (done) => {
|
|
90
|
+
const control = new RoutingControl({
|
|
91
|
+
url: 'https://foo.ch',
|
|
92
|
+
apiKey: 'foo',
|
|
93
|
+
});
|
|
94
|
+
control.attachToMap(map);
|
|
95
|
+
control.viaPoints = [
|
|
96
|
+
[950476.4055933182, 6003322.253698345],
|
|
97
|
+
[950389.0813034325, 6003656.659274571],
|
|
98
|
+
];
|
|
99
|
+
const error = new Error('Error');
|
|
100
|
+
error.name = 'AbortError';
|
|
101
|
+
fetch.mockRejectOnce(error);
|
|
102
|
+
return control.drawRoute().then((data) => {
|
|
103
|
+
expect(data).toEqual([undefined]);
|
|
104
|
+
done();
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
test('calls routing api with @ before the coordinates when snapToClosestStation is true', (done) => {
|
|
108
|
+
fetch.mockResponses([JSON.stringify(RoutingControlStation1), { status: 200 }], [JSON.stringify(global.fetchRouteResponse), { status: 200 }]);
|
|
109
|
+
const control = new RoutingControl({
|
|
110
|
+
apiKey: 'foo',
|
|
111
|
+
snapToClosestStation: true,
|
|
112
|
+
});
|
|
113
|
+
control.attachToMap(map);
|
|
114
|
+
expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
|
|
115
|
+
control.viaPoints = [
|
|
116
|
+
[950476.4055933182, 6003322.253698345],
|
|
117
|
+
[950389.0813034325, 6003656.659274571],
|
|
118
|
+
'e3666f03cba06b2b',
|
|
119
|
+
];
|
|
120
|
+
control.drawRoute(control.viaPoints).then(() => {
|
|
121
|
+
const { searchParams } = new URL(fetch.mock.calls[1][0]);
|
|
122
|
+
expect(searchParams.get('via')).toBe('@47.3739194713294,8.538274823394632|@47.37595378493421,8.537490375951839|!e3666f03cba06b2b');
|
|
123
|
+
done();
|
|
124
|
+
});
|
|
125
|
+
});
|
|
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 }]);
|
|
128
|
+
const control = new RoutingControl({
|
|
129
|
+
apiKey: 'foo',
|
|
130
|
+
useRawViaPoints: true,
|
|
131
|
+
});
|
|
132
|
+
control.attachToMap(map);
|
|
133
|
+
expect(map.getTarget().querySelector('#ol-toggle-routing')).toBeDefined();
|
|
134
|
+
control.viaPoints = [
|
|
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],
|
|
143
|
+
];
|
|
144
|
+
control.drawRoute(control.viaPoints).then(() => {
|
|
145
|
+
const params = new URL(fetch.mock.calls[2][0]).searchParams;
|
|
146
|
+
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');
|
|
147
|
+
done();
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
});
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
var proj_1 = require("ol/proj");
|
|
19
|
-
var Control_1 = require("../../common/controls/Control");
|
|
20
|
-
var StopFinderMixin_1 = require("../../common/mixins/StopFinderMixin");
|
|
1
|
+
import { fromLonLat } from 'ol/proj';
|
|
2
|
+
import Control from '../../common/controls/Control';
|
|
3
|
+
import mixin from '../../common/mixins/StopFinderMixin';
|
|
21
4
|
/**
|
|
22
5
|
* Search stations.
|
|
23
6
|
*
|
|
@@ -41,19 +24,13 @@ var StopFinderMixin_1 = require("../../common/mixins/StopFinderMixin");
|
|
|
41
24
|
* @extends {Control}
|
|
42
25
|
* @implements {StopFinderInterface}
|
|
43
26
|
*/
|
|
44
|
-
|
|
45
|
-
__extends(StopFinderControl, _super);
|
|
46
|
-
function StopFinderControl() {
|
|
47
|
-
return _super !== null && _super.apply(this, arguments) || this;
|
|
48
|
-
}
|
|
27
|
+
class StopFinderControl extends mixin(Control) {
|
|
49
28
|
/**
|
|
50
29
|
* @private
|
|
51
30
|
*/
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
var coord = (0, proj_1.fromLonLat)(geometry.coordinates);
|
|
31
|
+
onSuggestionClick({ geometry }) {
|
|
32
|
+
const coord = fromLonLat(geometry.coordinates);
|
|
55
33
|
this.map.getView().setCenter(coord);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
exports.default = StopFinderControl;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
export default StopFinderControl;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StopFinderControl.test.d.ts","sourceRoot":"","sources":["../../../src/ol/controls/StopFinderControl.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
// Correct url
|
|
44
|
+
expect(fetch.mock.calls[0][0]).toEqual('https://foo.ch/?key=foo&limit=10&foo=bar&q=foo');
|
|
45
|
+
expect(control.element.querySelector('div').querySelector('div').innerHTML).toBe('Bern');
|
|
46
|
+
done();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
});
|
package/ol/controls/index.js
CHANGED
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var CopyrightControl_1 = require("./CopyrightControl");
|
|
5
|
-
Object.defineProperty(exports, "CopyrightControl", { enumerable: true, get: function () { return CopyrightControl_1.default; } });
|
|
6
|
-
var RoutingControl_1 = require("./RoutingControl");
|
|
7
|
-
Object.defineProperty(exports, "RoutingControl", { enumerable: true, get: function () { return RoutingControl_1.default; } });
|
|
8
|
-
var StopFinderControl_1 = require("./StopFinderControl");
|
|
9
|
-
Object.defineProperty(exports, "StopFinderControl", { enumerable: true, get: function () { return StopFinderControl_1.default; } });
|
|
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,21 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("../api"), exports);
|
|
18
|
-
__exportStar(require("../common"), exports);
|
|
19
|
-
__exportStar(require("./controls"), exports);
|
|
20
|
-
__exportStar(require("./layers"), exports);
|
|
21
|
-
__exportStar(require("./styles"), exports);
|
|
1
|
+
export * from '../api';
|
|
2
|
+
export * from '../common';
|
|
3
|
+
export * from './controls';
|
|
4
|
+
export * from './layers';
|
|
5
|
+
export * from './styles';
|
package/ol/layers/Layer.d.ts
CHANGED
package/ol/layers/Layer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/Layer.js"],"names":[],"mappings":";AAIA;;;;;;;;;;;;;;GAcG;AACH;IAqBE;;;;OAIG;IACH,qCAQC;IAED;;;OAGG;IACH,4BAiDC;IAED;;OAEG;IACH,sBAYC;IAED,iCAyBC;IAjBG,4BAGC;IASD,4BAGC;IAIL,mCAEC;IAED;;;OAGG;IACH,+BAMC;IAED;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/Layer.js"],"names":[],"mappings":";AAIA;;;;;;;;;;;;;;GAcG;AACH;IAqBE;;;;OAIG;IACH,qCAQC;IAED;;;OAGG;IACH,4BAiDC;IAED;;OAEG;IACH,sBAYC;IAED,iCAyBC;IAjBG,4BAGC;IASD,4BAGC;IAIL,mCAEC;IAED;;;OAGG;IACH,+BAMC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,KAAK,CAIhB;CACF"}
|
package/ol/layers/Layer.js
CHANGED
|
@@ -1,34 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
var __assign = (this && this.__assign) || function () {
|
|
18
|
-
__assign = Object.assign || function(t) {
|
|
19
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
20
|
-
s = arguments[i];
|
|
21
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
22
|
-
t[p] = s[p];
|
|
23
|
-
}
|
|
24
|
-
return t;
|
|
25
|
-
};
|
|
26
|
-
return __assign.apply(this, arguments);
|
|
27
|
-
};
|
|
28
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
var Observable_1 = require("ol/Observable");
|
|
30
|
-
var Layer_1 = require("../../common/layers/Layer");
|
|
31
|
-
var UserInteractionsLayerMixin_1 = require("../../common/mixins/UserInteractionsLayerMixin");
|
|
1
|
+
import { unByKey } from 'ol/Observable';
|
|
2
|
+
import LayerCommon from '../../common/layers/Layer';
|
|
3
|
+
import userInteractionsMixin from '../../common/mixins/UserInteractionsLayerMixin';
|
|
32
4
|
/**
|
|
33
5
|
* A class representing a layer to display on an OpenLayers map.
|
|
34
6
|
*
|
|
@@ -44,8 +16,7 @@ var UserInteractionsLayerMixin_1 = require("../../common/mixins/UserInteractions
|
|
|
44
16
|
* @classproperty {ol/Map~Map} map - The map where the layer is displayed.
|
|
45
17
|
* @extends {Layer}
|
|
46
18
|
*/
|
|
47
|
-
|
|
48
|
-
__extends(Layer, _super);
|
|
19
|
+
class Layer extends userInteractionsMixin(LayerCommon) {
|
|
49
20
|
/**
|
|
50
21
|
* Constructor.
|
|
51
22
|
*
|
|
@@ -58,35 +29,33 @@ var Layer = /** @class */ (function (_super) {
|
|
|
58
29
|
* @param {Object} [options.properties={}] Application-specific layer properties.
|
|
59
30
|
* @param {boolean} [options.visible=true] If true this layer is the currently visible layer on the map.
|
|
60
31
|
*/
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
if (
|
|
64
|
-
|
|
32
|
+
constructor(options) {
|
|
33
|
+
super(options);
|
|
34
|
+
if (this.olLayer) {
|
|
35
|
+
this.olLayer.setVisible(this.visible);
|
|
65
36
|
}
|
|
66
|
-
return _this;
|
|
67
37
|
}
|
|
68
38
|
/**
|
|
69
39
|
* Define layer's properties.
|
|
70
40
|
*
|
|
71
41
|
* @ignore
|
|
72
42
|
*/
|
|
73
|
-
|
|
74
|
-
|
|
43
|
+
defineProperties(options) {
|
|
44
|
+
super.defineProperties(options);
|
|
75
45
|
Object.defineProperties(this, {
|
|
76
46
|
olLayer: { value: options.olLayer, writable: true },
|
|
77
47
|
olListenersKeys: {
|
|
78
48
|
value: [],
|
|
79
49
|
},
|
|
80
50
|
});
|
|
81
|
-
}
|
|
51
|
+
}
|
|
82
52
|
/**
|
|
83
53
|
* Initialize the layer and listen to feature clicks.
|
|
84
54
|
* @param {ol/Map~Map} map
|
|
85
55
|
*/
|
|
86
|
-
|
|
87
|
-
var _this = this;
|
|
56
|
+
attachToMap(map) {
|
|
88
57
|
var _a, _b, _c, _d;
|
|
89
|
-
|
|
58
|
+
super.attachToMap(map);
|
|
90
59
|
if (!this.map) {
|
|
91
60
|
return;
|
|
92
61
|
}
|
|
@@ -94,49 +63,49 @@ var Layer = /** @class */ (function (_super) {
|
|
|
94
63
|
!((_c = (_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getLayers()) === null || _b === void 0 ? void 0 : _b.getArray()) === null || _c === void 0 ? void 0 : _c.includes(this.olLayer))) {
|
|
95
64
|
this.map.addLayer(this.olLayer);
|
|
96
65
|
}
|
|
97
|
-
this.olListenersKeys.push(this.on('change:visible',
|
|
98
|
-
if (
|
|
99
|
-
|
|
66
|
+
this.olListenersKeys.push(this.on('change:visible', () => {
|
|
67
|
+
if (this.olLayer) {
|
|
68
|
+
this.olLayer.setVisible(this.visible);
|
|
100
69
|
}
|
|
101
70
|
}));
|
|
102
|
-
this.olListenersKeys.push(this.map.getLayers().on('remove',
|
|
103
|
-
if (evt.element ===
|
|
104
|
-
|
|
71
|
+
this.olListenersKeys.push(this.map.getLayers().on('remove', (evt) => {
|
|
72
|
+
if (evt.element === this.olLayer) {
|
|
73
|
+
this.detachFromMap();
|
|
105
74
|
}
|
|
106
75
|
}));
|
|
107
76
|
this.toggleVisibleListeners();
|
|
108
77
|
this.olListenersKeys.push(this.on('change:visible', this.toggleVisibleListeners));
|
|
109
78
|
// We set the copyright to the source used by the layer.
|
|
110
79
|
if (this.copyrights && this.olLayer) {
|
|
111
|
-
|
|
80
|
+
const attributions = this.copyrights || [];
|
|
112
81
|
if (this.olLayer.getLayers) {
|
|
113
82
|
this.olLayer
|
|
114
83
|
.getLayers()
|
|
115
84
|
.getArray()
|
|
116
|
-
.forEach(
|
|
85
|
+
.forEach((layer) => {
|
|
117
86
|
var _a;
|
|
118
|
-
(_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(
|
|
87
|
+
(_a = layer.getSource()) === null || _a === void 0 ? void 0 : _a.setAttributions(attributions);
|
|
119
88
|
});
|
|
120
89
|
}
|
|
121
90
|
else if (this.olLayer.getSource) {
|
|
122
|
-
(_d = this.olLayer.getSource()) === null || _d === void 0 ? void 0 : _d.setAttributions(
|
|
91
|
+
(_d = this.olLayer.getSource()) === null || _d === void 0 ? void 0 : _d.setAttributions(attributions);
|
|
123
92
|
}
|
|
124
93
|
}
|
|
125
|
-
}
|
|
94
|
+
}
|
|
126
95
|
/**
|
|
127
96
|
* Terminate what was initialized in init function. Remove layer, events...
|
|
128
97
|
*/
|
|
129
|
-
|
|
98
|
+
detachFromMap() {
|
|
130
99
|
var _a, _b, _c;
|
|
131
100
|
this.deactivateUserInteractions();
|
|
132
|
-
|
|
101
|
+
unByKey(this.olListenersKeys);
|
|
133
102
|
if (this.olLayer &&
|
|
134
103
|
((_c = (_b = (_a = this.map) === null || _a === void 0 ? void 0 : _a.getLayers()) === null || _b === void 0 ? void 0 : _b.getArray()) === null || _c === void 0 ? void 0 : _c.includes(this.olLayer))) {
|
|
135
104
|
this.map.removeLayer(this.olLayer);
|
|
136
105
|
}
|
|
137
|
-
|
|
138
|
-
}
|
|
139
|
-
|
|
106
|
+
super.detachFromMap();
|
|
107
|
+
}
|
|
108
|
+
activateUserInteractions() {
|
|
140
109
|
this.deactivateUserInteractions();
|
|
141
110
|
if (this.map &&
|
|
142
111
|
this.userInteractions &&
|
|
@@ -151,30 +120,29 @@ var Layer = /** @class */ (function (_super) {
|
|
|
151
120
|
this.userHoverCallbacks.length) {
|
|
152
121
|
this.pointerMoveListenerKey = this.map.on('pointermove', this.onUserMoveCallback);
|
|
153
122
|
}
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}
|
|
123
|
+
}
|
|
124
|
+
deactivateUserInteractions() {
|
|
125
|
+
unByKey([this.pointerMoveListenerKey, this.singleClickListenerKey]);
|
|
126
|
+
}
|
|
158
127
|
/**
|
|
159
128
|
* Toggle listeners needed when a layer is avisible or not.
|
|
160
129
|
* @private
|
|
161
130
|
*/
|
|
162
|
-
|
|
131
|
+
toggleVisibleListeners() {
|
|
163
132
|
if (this.visible) {
|
|
164
133
|
this.activateUserInteractions();
|
|
165
134
|
}
|
|
166
135
|
else {
|
|
167
136
|
this.deactivateUserInteractions();
|
|
168
137
|
}
|
|
169
|
-
}
|
|
138
|
+
}
|
|
170
139
|
/**
|
|
171
140
|
* Create a copy of the Layer.
|
|
172
141
|
* @param {Object} newOptions Options to override
|
|
173
142
|
* @return {Layer} A Layer
|
|
174
143
|
*/
|
|
175
|
-
|
|
176
|
-
return new Layer(
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
exports.default = Layer;
|
|
144
|
+
clone(newOptions) {
|
|
145
|
+
return new Layer(Object.assign(Object.assign({}, this.options), newOptions));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
export default Layer;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Layer.test.d.ts","sourceRoot":"","sources":["../../../src/ol/layers/Layer.test.js"],"names":[],"mappings":""}
|