mobility-toolbox-js 2.0.0 → 2.1.0
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/RealtimeAPI.d.ts +279 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RealtimeAPI.js +466 -0
- package/api/RoutingAPI.d.ts +37 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/RoutingAPI.js +35 -0
- package/api/StopsAPI.d.ts +38 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/StopsAPI.js +36 -0
- package/api/index.d.ts +4 -0
- package/api/index.d.ts.map +1 -0
- package/api/index.js +3 -3
- package/api/typedefs.d.ts +179 -0
- package/api/typedefs.d.ts.map +1 -0
- package/api/{tralis/typedefs.js → typedefs.js} +4 -10
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/HttpAPI.js +57 -0
- package/common/api/WebSocketAPI.d.ts +153 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.js +341 -0
- package/common/controls/ControlCommon.d.ts +76 -0
- package/common/controls/ControlCommon.d.ts.map +1 -0
- package/common/controls/ControlCommon.js +150 -0
- package/common/controls/CopyrightControlCommon.d.ts +13 -0
- package/common/controls/CopyrightControlCommon.d.ts.map +1 -0
- package/common/controls/CopyrightControlCommon.js +34 -0
- package/common/controls/StopFinderControlCommon.d.ts +55 -0
- package/common/controls/StopFinderControlCommon.d.ts.map +1 -0
- package/common/controls/StopFinderControlCommon.js +144 -0
- package/common/index.d.ts +3 -0
- package/common/index.d.ts.map +1 -0
- package/common/index.js +2 -0
- package/common/layers/LayerCommon.d.ts +94 -0
- package/common/layers/LayerCommon.d.ts.map +1 -0
- package/common/layers/LayerCommon.js +244 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +286 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.js +776 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +60 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.js +241 -0
- package/common/styles/index.d.ts +5 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/index.js +4 -4
- package/common/styles/realtimeDefaultStyle.d.ts +36 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.js +275 -0
- package/common/styles/{trackerDelayStyle.js → realtimeDelayStyle.d.ts} +4 -9
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.js +13 -0
- package/common/styles/realtimeHeadingStyle.d.ts +12 -0
- package/common/styles/realtimeHeadingStyle.d.ts.map +1 -0
- package/common/styles/realtimeHeadingStyle.js +85 -0
- package/common/styles/realtimeSimpleStyle.d.ts +4 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.js +23 -0
- package/common/typedefs.d.ts +111 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/typedefs.js +35 -6
- package/common/utils/compareDepartures.d.ts +11 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/compareDepartures.js +35 -0
- package/common/utils/createCanvas.d.ts +10 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createCanvas.js +27 -0
- package/common/utils/createRealtimeFilters.d.ts +13 -0
- package/common/utils/createRealtimeFilters.d.ts.map +1 -0
- package/common/utils/createRealtimeFilters.js +74 -0
- package/common/utils/debounceDeparturesMessages.d.ts +12 -0
- package/common/utils/debounceDeparturesMessages.d.ts.map +1 -0
- package/common/utils/debounceDeparturesMessages.js +24 -0
- package/common/utils/debounceWebsocketMessages.d.ts +11 -0
- package/common/utils/debounceWebsocketMessages.d.ts.map +1 -0
- package/common/utils/debounceWebsocketMessages.js +29 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.js +15 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +18 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.js +21 -23
- package/common/utils/getMapboxRender.d.ts +7 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMapboxRender.js +87 -0
- package/common/utils/getMaplibreRender.d.ts +7 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.js +38 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +10 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.js +7 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.js +18 -0
- package/common/utils/getVehiclePosition.d.ts +16 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.js +60 -60
- package/common/utils/index.d.ts +17 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/index.js +13 -2
- package/common/utils/realtimeConfig.d.ts +49 -0
- package/common/utils/realtimeConfig.d.ts.map +1 -0
- package/common/utils/realtimeConfig.js +173 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/removeDuplicate.js +5 -12
- package/common/utils/renderTrajectories.d.ts +17 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/renderTrajectories.js +110 -0
- package/common/utils/sortAndFilterDepartures.d.ts +16 -0
- package/common/utils/sortAndFilterDepartures.d.ts.map +1 -0
- package/common/utils/sortAndFilterDepartures.js +58 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/sortByDelay.js +17 -20
- package/common/utils/timeUtils.d.ts +24 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/timeUtils.js +13 -18
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/iife.js +5 -0
- package/index.d.ts +10 -0
- package/index.d.ts.map +1 -0
- package/index.js +10 -2
- package/mapbox/controls/CopyrightControl.d.ts +29 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.js +25 -35
- package/mapbox/controls/index.d.ts +2 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/controls/index.js +2 -0
- package/mapbox/index.d.ts +6 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/index.js +5 -3
- package/mapbox/layers/Layer.d.ts +59 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/Layer.js +78 -95
- package/mapbox/layers/RealtimeLayer.d.ts +181 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.js +276 -0
- package/mapbox/layers/index.d.ts +3 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/layers/index.js +2 -0
- package/mapbox/utils/getMercatorResolution.d.ts +9 -0
- package/mapbox/utils/getMercatorResolution.d.ts.map +1 -0
- package/mapbox/utils/getMercatorResolution.js +18 -0
- package/mapbox/utils/getSourceCoordinates.d.ts +9 -0
- package/mapbox/utils/getSourceCoordinates.d.ts.map +1 -0
- package/mapbox/utils/getSourceCoordinates.js +27 -0
- package/mapbox/utils/index.d.ts +3 -0
- package/mapbox/utils/index.d.ts.map +1 -0
- package/mapbox/utils/index.js +2 -0
- package/mbt.js +60005 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1084 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.js +44 -56
- package/ol/controls/RoutingControl.d.ts +193 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.js +546 -667
- package/ol/controls/StopFinderControl.d.ts +30 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.js +10 -16
- package/ol/controls/index.d.ts +4 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.d.ts +6 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/index.js +4 -12
- package/ol/layers/Layer.d.ts +86 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/Layer.js +147 -166
- package/ol/layers/MapGlLayer.d.ts +67 -0
- package/ol/layers/MapGlLayer.d.ts.map +1 -0
- package/ol/layers/MapGlLayer.js +218 -0
- package/ol/layers/MapboxLayer.d.ts +50 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.js +79 -348
- package/ol/layers/MapboxStyleLayer.d.ts +129 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.js +329 -368
- package/ol/layers/MaplibreLayer.d.ts +28 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.js +13 -259
- package/ol/layers/RealtimeLayer.d.ts +202 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.js +340 -0
- package/ol/layers/RoutingLayer.d.ts +34 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.js +62 -68
- package/ol/layers/VectorLayer.d.ts +25 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.js +27 -32
- package/ol/layers/WMSLayer.d.ts +42 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.js +74 -66
- package/ol/layers/index.d.ts +9 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/layers/index.js +8 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.js +23 -25
- package/ol/styles/fullTrajectoryStyle.d.ts +5 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.js +37 -44
- package/ol/styles/index.d.ts +3 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +98 -177
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/setupTests.js +26 -0
- package/types/common.d.ts +122 -0
- package/types/index.d.ts +11 -0
- package/types/realtime.d.ts +320 -0
- package/types/routing.d.ts +206 -0
- package/types/stops.d.ts +143 -0
- package/README.md +0 -23
- 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/TralisAPIUtils.js +0 -73
- package/api/tralis/WebSocketConnector.js +0 -338
- package/api/tralis/WebSocketConnector.test.js +0 -356
- package/common/Tracker.js +0 -197
- package/common/api/api.js +0 -64
- package/common/api/api.test.js +0 -68
- package/common/controls/Control.js +0 -146
- package/common/controls/Control.test.js +0 -98
- package/common/layers/Layer.js +0 -404
- package/common/layers/Layer.test.js +0 -585
- package/common/mixins/CopyrightMixin.js +0 -48
- package/common/mixins/SearchMixin.js +0 -176
- package/common/mixins/TralisLayerMixin.js +0 -930
- package/common/styles/trackerDefaultStyle.js +0 -333
- package/common/styles/trackerSimpleStyle.js +0 -22
- package/common/trackerConfig.js +0 -190
- package/common/trackerConfig.test.js +0 -25
- package/common/utils/createTrackerFilters.js +0 -87
- package/common/utils/createTrackerFilters.test.js +0 -95
- package/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/common/utils/getMapboxStyleUrl.js +0 -32
- package/common/utils/removeDuplicate.test.js +0 -22
- package/common/utils/timeUtils.test.js +0 -16
- package/index.js.map +0 -1
- package/mapbox/layers/Layer.test.js +0 -202
- package/mapbox/layers/TralisLayer.js +0 -329
- package/mapbox/layers/TralisLayer.test.js +0 -40
- package/mapbox/utils.js +0 -46
- package/module.js +0 -23
- package/ol/README.md +0 -0
- package/ol/controls/CopyrightControl.test.js +0 -211
- package/ol/controls/RoutingControl.test.js +0 -216
- package/ol/controls/StopFinderControl.test.js +0 -59
- 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
- package/ol/layers/Layer.test.js +0 -197
- package/ol/layers/MapboxLayer.test.js +0 -186
- package/ol/layers/MapboxStyleLayer.test.js +0 -262
- package/ol/layers/RoutingLayer.test.js +0 -49
- package/ol/layers/TralisLayer.js +0 -359
- package/ol/layers/TralisLayer.test.js +0 -97
- package/ol/layers/VectorLayer.test.js +0 -98
- package/ol/layers/WMSLayer.test.js +0 -84
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import View from 'ol/View';
|
|
2
|
-
import Tile from 'ol/Tile';
|
|
3
|
-
import TileLayer from 'ol/layer/Tile';
|
|
4
|
-
import TileSource from 'ol/source/Tile';
|
|
5
|
-
import { createXYZ } from 'ol/tilegrid';
|
|
6
|
-
import { Map } from 'ol';
|
|
7
|
-
import Layer from '../layers/Layer';
|
|
8
|
-
import CopyrightControl from './CopyrightControl';
|
|
9
|
-
|
|
10
|
-
const tileLoadFunction = () => {
|
|
11
|
-
const tile = new Tile([0, 0, -1], 2 /* LOADED */);
|
|
12
|
-
tile.getImage = () => {
|
|
13
|
-
const image = new Image();
|
|
14
|
-
image.width = 256;
|
|
15
|
-
image.height = 256;
|
|
16
|
-
return image;
|
|
17
|
-
};
|
|
18
|
-
return tile;
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const getOLTileLayer = () => {
|
|
22
|
-
const layer = new TileLayer({
|
|
23
|
-
source: new TileSource({
|
|
24
|
-
projection: 'EPSG:3857',
|
|
25
|
-
tileGrid: createXYZ(),
|
|
26
|
-
}),
|
|
27
|
-
});
|
|
28
|
-
layer.getSource().getTile = tileLoadFunction;
|
|
29
|
-
return layer;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
|
-
const getLayer = (copyrights, visible = true) =>
|
|
33
|
-
new Layer({
|
|
34
|
-
visible,
|
|
35
|
-
copyrights,
|
|
36
|
-
olLayer: getOLTileLayer(),
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
describe('CopyrightControl', () => {
|
|
40
|
-
let map;
|
|
41
|
-
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
const target = document.createElement('div');
|
|
44
|
-
document.body.appendChild(target);
|
|
45
|
-
map = new Map({
|
|
46
|
-
target,
|
|
47
|
-
view: new View({
|
|
48
|
-
center: [0, 0],
|
|
49
|
-
zoom: 0,
|
|
50
|
-
}),
|
|
51
|
-
});
|
|
52
|
-
getLayer(true, 'bar').init(map);
|
|
53
|
-
map.setSize([200, 200]);
|
|
54
|
-
map.renderSync();
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
if (map) {
|
|
59
|
-
map.setTarget(null);
|
|
60
|
-
map = null;
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
test('should be activate by default', () => {
|
|
65
|
-
const control = new CopyrightControl();
|
|
66
|
-
expect(control.active).toBe(true);
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
test('renders a string copyright', () => {
|
|
70
|
-
const control = new CopyrightControl();
|
|
71
|
-
control.map = map;
|
|
72
|
-
expect(control.element.innerHTML).toBe('');
|
|
73
|
-
getLayer('copyright').init(map);
|
|
74
|
-
map.renderSync();
|
|
75
|
-
expect(control.element.innerHTML).toBe('copyright');
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
test('renders an array of copyrights', () => {
|
|
79
|
-
const control = new CopyrightControl();
|
|
80
|
-
control.map = map;
|
|
81
|
-
expect(control.element.innerHTML).toBe('');
|
|
82
|
-
getLayer(['copyright 1', 'copyright 2']).init(map);
|
|
83
|
-
map.renderSync();
|
|
84
|
-
expect(control.element.innerHTML).toBe('copyright 1 | copyright 2');
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('renders unique copyrights', () => {
|
|
88
|
-
const control = new CopyrightControl();
|
|
89
|
-
control.map = map;
|
|
90
|
-
expect(control.element.innerHTML).toBe('');
|
|
91
|
-
getLayer(['copyright 1', 'copyright 2']).init(map);
|
|
92
|
-
getLayer('copyright 1').init(map);
|
|
93
|
-
getLayer(['copyright 2']).init(map);
|
|
94
|
-
map.renderSync();
|
|
95
|
-
expect(control.element.innerHTML).toBe('copyright 1 | copyright 2');
|
|
96
|
-
});
|
|
97
|
-
|
|
98
|
-
test("doesn't render copyright of an hidden layer", () => {
|
|
99
|
-
const control = new CopyrightControl();
|
|
100
|
-
control.map = map;
|
|
101
|
-
expect(control.element.innerHTML).toBe('');
|
|
102
|
-
const layer1 = getLayer('copyright hidden', false);
|
|
103
|
-
layer1.init(map);
|
|
104
|
-
const layer2 = getLayer('copyright', true);
|
|
105
|
-
layer2.init(map);
|
|
106
|
-
map.renderSync();
|
|
107
|
-
expect(control.element.innerHTML).toBe('copyright');
|
|
108
|
-
|
|
109
|
-
// the we update visibility of both layers
|
|
110
|
-
layer1.setVisible(true);
|
|
111
|
-
map.renderSync();
|
|
112
|
-
layer2.setVisible(false);
|
|
113
|
-
map.renderSync();
|
|
114
|
-
expect(control.element.innerHTML).toBe('copyright hidden');
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('should activate the control on construction then deactivate it', () => {
|
|
118
|
-
getLayer('copyright 1').init(map);
|
|
119
|
-
const control = new CopyrightControl({ active: true });
|
|
120
|
-
control.map = map;
|
|
121
|
-
map.renderSync();
|
|
122
|
-
|
|
123
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
124
|
-
|
|
125
|
-
// Should be activated by default.
|
|
126
|
-
expect(control.active).toBe(true);
|
|
127
|
-
expect(control.element.innerHTML).toBe('copyright 1');
|
|
128
|
-
|
|
129
|
-
// on deactivation
|
|
130
|
-
control.active = false;
|
|
131
|
-
map.renderSync();
|
|
132
|
-
expect(control.element.innerHTML).toBe('');
|
|
133
|
-
});
|
|
134
|
-
|
|
135
|
-
test('should deactivate the control on constrcution then activate it', () => {
|
|
136
|
-
getLayer('copyright 1').init(map);
|
|
137
|
-
const control = new CopyrightControl({ active: false });
|
|
138
|
-
control.map = map;
|
|
139
|
-
map.renderSync();
|
|
140
|
-
|
|
141
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
142
|
-
|
|
143
|
-
// Should be activated by default.
|
|
144
|
-
expect(control.active).toBe(false);
|
|
145
|
-
map.renderSync();
|
|
146
|
-
expect(control.element.innerHTML).toBe('');
|
|
147
|
-
|
|
148
|
-
// on deactivation
|
|
149
|
-
control.active = true;
|
|
150
|
-
map.renderSync();
|
|
151
|
-
expect(control.element.innerHTML).toBe('copyright 1');
|
|
152
|
-
});
|
|
153
|
-
|
|
154
|
-
test('should add copyrights in the map container element then remove it.', () => {
|
|
155
|
-
getLayer('copyright value').init(map);
|
|
156
|
-
map.renderSync();
|
|
157
|
-
|
|
158
|
-
const control = new CopyrightControl();
|
|
159
|
-
|
|
160
|
-
// Add control
|
|
161
|
-
control.map = map;
|
|
162
|
-
expect(control.element.parentNode).toBe(map.getTargetElement());
|
|
163
|
-
|
|
164
|
-
// Remove control
|
|
165
|
-
control.map = null;
|
|
166
|
-
expect(control.element.parentNode).toBe(null);
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
test('should add copyrights in the target element then remove it.', () => {
|
|
170
|
-
getLayer(['copyright value']).init(map);
|
|
171
|
-
map.renderSync();
|
|
172
|
-
|
|
173
|
-
const target = document.createElement('div');
|
|
174
|
-
target.setAttribute('id', 'copyright');
|
|
175
|
-
document.body.appendChild(target);
|
|
176
|
-
|
|
177
|
-
const control = new CopyrightControl({
|
|
178
|
-
target: document.getElementById('copyright'),
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// Add control
|
|
182
|
-
control.map = map;
|
|
183
|
-
expect(control.element.parentNode).toBe(target);
|
|
184
|
-
|
|
185
|
-
// Remove control
|
|
186
|
-
control.map = null;
|
|
187
|
-
expect(control.element.parentNode).toBe(null);
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
test('renders custom copyrights with the render method ', () => {
|
|
191
|
-
const control = new CopyrightControl({
|
|
192
|
-
active: true,
|
|
193
|
-
render() {
|
|
194
|
-
if (!this.element) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
this.element.innerHTML = this.active
|
|
198
|
-
? this.getCopyrights().join(', ')
|
|
199
|
-
: '';
|
|
200
|
-
},
|
|
201
|
-
});
|
|
202
|
-
control.map = map;
|
|
203
|
-
getLayer(['copyright 1', 'copyright 2', 'copyright 3']).init(map);
|
|
204
|
-
map.renderSync();
|
|
205
|
-
|
|
206
|
-
// Add control
|
|
207
|
-
expect(control.element.innerHTML).toBe(
|
|
208
|
-
'copyright 1, copyright 2, copyright 3',
|
|
209
|
-
);
|
|
210
|
-
});
|
|
211
|
-
});
|
|
@@ -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,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
|
-
}
|