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,202 +0,0 @@
|
|
|
1
|
-
import { Map } from 'maplibre-gl';
|
|
2
|
-
import { toLonLat } from 'ol/proj';
|
|
3
|
-
import Layer from './Layer';
|
|
4
|
-
|
|
5
|
-
let map;
|
|
6
|
-
let mapElement;
|
|
7
|
-
|
|
8
|
-
describe('Layer', () => {
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
mapElement = document.createElement('div');
|
|
11
|
-
const { style } = mapElement;
|
|
12
|
-
style.position = 'absolute';
|
|
13
|
-
style.left = '0px';
|
|
14
|
-
style.top = '0px';
|
|
15
|
-
style.width = '400px';
|
|
16
|
-
style.height = '400px';
|
|
17
|
-
mapElement.setAttribute('id', 'map');
|
|
18
|
-
document.body.appendChild(mapElement);
|
|
19
|
-
map = new Map({
|
|
20
|
-
container: document.getElementById('map'),
|
|
21
|
-
style: `path/to/style`,
|
|
22
|
-
center: toLonLat([831634, 5933959]),
|
|
23
|
-
zoom: 9,
|
|
24
|
-
});
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
afterEach(() => {
|
|
28
|
-
document.body.removeChild(mapElement);
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
test('should initialize.', () => {
|
|
32
|
-
const layer = new Layer({ name: 'Layer' });
|
|
33
|
-
expect(layer).toBeInstanceOf(Layer);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('should be visible by default.', () => {
|
|
37
|
-
const layer = new Layer({ name: 'Layer' });
|
|
38
|
-
expect(layer.visible).toBe(true);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
test('should be invisible if defined.', () => {
|
|
42
|
-
const layer = new Layer({ name: 'Layer', visible: false });
|
|
43
|
-
expect(layer.visible).toBe(false);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('should be invisible if set.', () => {
|
|
47
|
-
const layer = new Layer({ name: 'Layer' });
|
|
48
|
-
layer.setVisible(false);
|
|
49
|
-
expect(layer.visible).toBe(false);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('should visibility stay unchanged', () => {
|
|
53
|
-
const layer = new Layer({ name: 'Layer', visible: false });
|
|
54
|
-
layer.setVisible(false);
|
|
55
|
-
expect(layer.visible).toBe(false);
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('should return its name.', () => {
|
|
59
|
-
const layer = new Layer({ name: 'Layer', visible: false });
|
|
60
|
-
expect(layer.name).toEqual('Layer');
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('should call terminate on initialization.', () => {
|
|
64
|
-
const layer = new Layer({ name: 'Layer' });
|
|
65
|
-
const spy = jest.spyOn(layer, 'terminate');
|
|
66
|
-
layer.init(map);
|
|
67
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('should listen for click/hover events when layer is visible by default then should not when hidden.', async () => {
|
|
71
|
-
global.console.error = jest.fn();
|
|
72
|
-
const layer = new Layer({ name: 'Layer' });
|
|
73
|
-
expect(layer.visible).toBe(true);
|
|
74
|
-
const spy = jest.fn();
|
|
75
|
-
const spy2 = jest.fn();
|
|
76
|
-
layer.init(map);
|
|
77
|
-
layer.onHover(spy);
|
|
78
|
-
layer.onClick(spy2);
|
|
79
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
80
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
81
|
-
|
|
82
|
-
await map.fire('mousemove', {
|
|
83
|
-
type: 'mousemove',
|
|
84
|
-
lngLat: { toArray: () => [0, 0] },
|
|
85
|
-
coordinate: [0, 0],
|
|
86
|
-
});
|
|
87
|
-
await map.fire('click', {
|
|
88
|
-
type: 'click',
|
|
89
|
-
lngLat: { toArray: () => [0, 0] },
|
|
90
|
-
});
|
|
91
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
92
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
93
|
-
spy.mockReset();
|
|
94
|
-
spy2.mockReset();
|
|
95
|
-
|
|
96
|
-
layer.setVisible(false);
|
|
97
|
-
await map.fire('mousemove', {
|
|
98
|
-
type: 'mousemove',
|
|
99
|
-
lngLat: { toArray: () => [0, 0] },
|
|
100
|
-
});
|
|
101
|
-
await map.fire('click', {
|
|
102
|
-
type: 'click',
|
|
103
|
-
lngLat: { toArray: () => [0, 0] },
|
|
104
|
-
});
|
|
105
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
106
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
107
|
-
global.console.error.mockRestore();
|
|
108
|
-
});
|
|
109
|
-
|
|
110
|
-
test('should not listen for click/hover events when layer is not visible by default then should not when visible.', async () => {
|
|
111
|
-
global.console.error = jest.fn();
|
|
112
|
-
const layer = new Layer({ name: 'Layer', visible: false });
|
|
113
|
-
expect(layer.visible).toBe(false);
|
|
114
|
-
const spy = jest.fn();
|
|
115
|
-
const spy2 = jest.fn();
|
|
116
|
-
layer.init(map);
|
|
117
|
-
layer.onHover(spy);
|
|
118
|
-
layer.onClick(spy2);
|
|
119
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
120
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
121
|
-
|
|
122
|
-
await map.fire('mousemove', {
|
|
123
|
-
type: 'mousemove',
|
|
124
|
-
lngLat: { toArray: () => [0, 0] },
|
|
125
|
-
coordinate: [0, 0],
|
|
126
|
-
});
|
|
127
|
-
await map.fire('click', {
|
|
128
|
-
type: 'click',
|
|
129
|
-
lngLat: { toArray: () => [0, 0] },
|
|
130
|
-
});
|
|
131
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
132
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
133
|
-
spy.mockReset();
|
|
134
|
-
spy2.mockReset();
|
|
135
|
-
|
|
136
|
-
layer.setVisible(true);
|
|
137
|
-
await map.fire('mousemove', {
|
|
138
|
-
type: 'mousemove',
|
|
139
|
-
lngLat: { toArray: () => [0, 0] },
|
|
140
|
-
coordinate: [0, 0],
|
|
141
|
-
});
|
|
142
|
-
await map.fire('click', {
|
|
143
|
-
type: 'click',
|
|
144
|
-
lngLat: { toArray: () => [0, 0] },
|
|
145
|
-
});
|
|
146
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
147
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
148
|
-
global.console.error.mockRestore();
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
test('should not listen for click/hover events after layer.terminate()', async () => {
|
|
152
|
-
global.console.error = jest.fn();
|
|
153
|
-
const layer = new Layer({ name: 'Layer', visible: true });
|
|
154
|
-
expect(layer.visible).toBe(true);
|
|
155
|
-
const spy = jest.fn();
|
|
156
|
-
const spy2 = jest.fn();
|
|
157
|
-
layer.init(map);
|
|
158
|
-
layer.onHover(spy);
|
|
159
|
-
layer.onClick(spy2);
|
|
160
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
161
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
162
|
-
|
|
163
|
-
await map.fire('mousemove', {
|
|
164
|
-
type: 'mousemove',
|
|
165
|
-
lngLat: { toArray: () => [0, 0] },
|
|
166
|
-
coordinate: [0, 0],
|
|
167
|
-
});
|
|
168
|
-
await map.fire('click', {
|
|
169
|
-
type: 'click',
|
|
170
|
-
lngLat: { toArray: () => [0, 0] },
|
|
171
|
-
});
|
|
172
|
-
expect(spy).toHaveBeenCalledTimes(1);
|
|
173
|
-
expect(spy2).toHaveBeenCalledTimes(1);
|
|
174
|
-
spy.mockReset();
|
|
175
|
-
spy2.mockReset();
|
|
176
|
-
|
|
177
|
-
layer.terminate(map);
|
|
178
|
-
await map.fire('mousemove', {
|
|
179
|
-
type: 'mousemove',
|
|
180
|
-
lngLat: { toArray: () => [0, 0] },
|
|
181
|
-
coordinate: [0, 0],
|
|
182
|
-
});
|
|
183
|
-
await map.fire('click', {
|
|
184
|
-
type: 'click',
|
|
185
|
-
lngLat: { toArray: () => [0, 0] },
|
|
186
|
-
});
|
|
187
|
-
expect(spy).toHaveBeenCalledTimes(0);
|
|
188
|
-
expect(spy2).toHaveBeenCalledTimes(0);
|
|
189
|
-
global.console.error.mockRestore();
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
test('should clone', () => {
|
|
193
|
-
const layer = new Layer({
|
|
194
|
-
name: 'Layer',
|
|
195
|
-
copyrights: ['bar'],
|
|
196
|
-
});
|
|
197
|
-
const clone = layer.clone({ name: 'clone' });
|
|
198
|
-
expect(clone).not.toBe(layer);
|
|
199
|
-
expect(clone.name).toBe('clone');
|
|
200
|
-
expect(clone).toBeInstanceOf(Layer);
|
|
201
|
-
});
|
|
202
|
-
});
|
|
@@ -1,329 +0,0 @@
|
|
|
1
|
-
import { fromLonLat } from 'ol/proj';
|
|
2
|
-
import { unByKey } from 'ol/Observable';
|
|
3
|
-
import { getWidth, getHeight } from 'ol/extent';
|
|
4
|
-
import transformRotate from '@turf/transform-rotate';
|
|
5
|
-
import { point } from '@turf/helpers';
|
|
6
|
-
import mixin from '../../common/mixins/TralisLayerMixin';
|
|
7
|
-
import Layer from './Layer';
|
|
8
|
-
import { getSourceCoordinates, getMercatorResolution } from '../utils';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Responsible for loading and display data from a Tralis service.
|
|
12
|
-
*
|
|
13
|
-
* @example
|
|
14
|
-
* import { TralisLayer } from 'mobility-toolbox-js/mapbox';
|
|
15
|
-
*
|
|
16
|
-
* const layer = new TralisLayer({
|
|
17
|
-
* url: [yourUrl],
|
|
18
|
-
* apiKey: [yourApiKey],
|
|
19
|
-
* });
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
* @see <a href="/api/class/src/api/tralis/TralisAPI%20js~TralisAPI%20html">TralisAPI</a>
|
|
23
|
-
*
|
|
24
|
-
* @extends {Layer}
|
|
25
|
-
* @implements {TralisLayerInterface}
|
|
26
|
-
*/
|
|
27
|
-
class TralisLayer extends mixin(Layer) {
|
|
28
|
-
constructor(options = {}) {
|
|
29
|
-
super({
|
|
30
|
-
...options,
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
/** @ignore */
|
|
34
|
-
this.onLoad = this.onLoad.bind(this);
|
|
35
|
-
|
|
36
|
-
/** @ignore */
|
|
37
|
-
this.onMove = this.onMove.bind(this);
|
|
38
|
-
|
|
39
|
-
/** @ignore */
|
|
40
|
-
this.onMoveEnd = this.onMoveEnd.bind(this);
|
|
41
|
-
|
|
42
|
-
/** @ignore */
|
|
43
|
-
this.onZoomEnd = this.onZoomEnd.bind(this);
|
|
44
|
-
|
|
45
|
-
/** @ignore */
|
|
46
|
-
this.onVisibilityChange = this.onVisibilityChange.bind(this);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Initialize the layer.
|
|
51
|
-
*
|
|
52
|
-
* @param {mapboxgl.Map} map A [mapbox Map](https://docs.mapbox.com/mapbox-gl-js/api/map/).
|
|
53
|
-
* @param {string} beforeId Layer's id before which we want to add the new layer.
|
|
54
|
-
* @override
|
|
55
|
-
*/
|
|
56
|
-
init(map, beforeId) {
|
|
57
|
-
if (!map) {
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
const canvas = map.getCanvas();
|
|
62
|
-
|
|
63
|
-
super.init(map, {
|
|
64
|
-
width: canvas.width / this.pixelRatio,
|
|
65
|
-
height: canvas.height / this.pixelRatio,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
this.source = {
|
|
69
|
-
type: 'canvas',
|
|
70
|
-
canvas: this.tracker.canvas,
|
|
71
|
-
coordinates: getSourceCoordinates(map, this.pixelRatio),
|
|
72
|
-
// Set to true if the canvas source is animated. If the canvas is static, animate should be set to false to improve performance.
|
|
73
|
-
animate: true,
|
|
74
|
-
attribution: this.copyrights && this.copyrights.join(', '),
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
this.beforeId = beforeId;
|
|
78
|
-
this.layer = {
|
|
79
|
-
id: this.key,
|
|
80
|
-
type: 'raster',
|
|
81
|
-
source: this.key,
|
|
82
|
-
layout: {
|
|
83
|
-
visibility: this.visible ? 'visible' : 'none',
|
|
84
|
-
},
|
|
85
|
-
paint: {
|
|
86
|
-
'raster-opacity': 1,
|
|
87
|
-
'raster-fade-duration': 0,
|
|
88
|
-
'raster-resampling': 'nearest', // important otherwise it looks blurry
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
if (map.isStyleLoaded()) {
|
|
93
|
-
this.onLoad();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
this.map.on('load', this.onLoad);
|
|
97
|
-
|
|
98
|
-
this.listeners = [this.on('change:visible', this.onVisibilityChange)];
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* Remove listeners from the Mapbox Map.
|
|
103
|
-
*/
|
|
104
|
-
terminate() {
|
|
105
|
-
if (this.map) {
|
|
106
|
-
this.map.off('load', this.onLoad);
|
|
107
|
-
|
|
108
|
-
this.listeners.forEach((listener) => {
|
|
109
|
-
unByKey(listener);
|
|
110
|
-
});
|
|
111
|
-
if (this.map.getLayer(this.key)) {
|
|
112
|
-
this.map.removeLayer(this.key);
|
|
113
|
-
}
|
|
114
|
-
if (this.map.getSource(this.key)) {
|
|
115
|
-
this.map.removeSource(this.key);
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
super.terminate();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Start updating vehicles position.
|
|
123
|
-
*
|
|
124
|
-
* @listens {mapboxgl.map.event:zoomend} Listen to zoom end event.
|
|
125
|
-
* @listens {mapboxgl.map.event:mousemove} Listen to mousemove end.
|
|
126
|
-
* @override
|
|
127
|
-
*/
|
|
128
|
-
start() {
|
|
129
|
-
super.start();
|
|
130
|
-
|
|
131
|
-
this.map.on('move', this.onMove);
|
|
132
|
-
this.map.on('moveend', this.onMoveEnd);
|
|
133
|
-
this.map.on('zoomend', this.onZoomEnd);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Stop updating vehicles position, and unlisten events.
|
|
138
|
-
*
|
|
139
|
-
* @override
|
|
140
|
-
*/
|
|
141
|
-
stop() {
|
|
142
|
-
super.stop();
|
|
143
|
-
if (this.map) {
|
|
144
|
-
this.map.off('move', this.onMove);
|
|
145
|
-
this.map.off('moveend', this.onMoveEnd);
|
|
146
|
-
this.map.off('zoomend', this.onZoomEnd);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
onLoad() {
|
|
151
|
-
if (!this.map.getSource(this.key)) {
|
|
152
|
-
this.map.addSource(this.key, this.source);
|
|
153
|
-
}
|
|
154
|
-
if (!this.map.getLayer(this.key)) {
|
|
155
|
-
this.map.addLayer(this.layer, this.beforeId);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Function triggered when the user click the map.
|
|
161
|
-
* @override
|
|
162
|
-
*/
|
|
163
|
-
onUserClickCallback(evt) {
|
|
164
|
-
super.onUserClickCallback({
|
|
165
|
-
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
166
|
-
...evt,
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* Function triggered when the user moves the cursor over the map.
|
|
172
|
-
* @override
|
|
173
|
-
*/
|
|
174
|
-
onUserMoveCallback(evt) {
|
|
175
|
-
super.onUserMoveCallback({
|
|
176
|
-
coordinate: fromLonLat(evt.lngLat.toArray()),
|
|
177
|
-
...evt,
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Render the trajectories using current map's size, resolution and rotation.
|
|
183
|
-
* @param {boolean} noInterpolate if true, renders the vehicles without interpolating theirs positions.
|
|
184
|
-
* @overrides
|
|
185
|
-
*/
|
|
186
|
-
renderTrajectories(noInterpolate) {
|
|
187
|
-
const { width, height } = this.map.getCanvas();
|
|
188
|
-
const center = this.map.getCenter();
|
|
189
|
-
|
|
190
|
-
// We use turf here to have good transform.
|
|
191
|
-
const leftBottom = this.map.unproject({
|
|
192
|
-
x: 0,
|
|
193
|
-
y: height / this.pixelRatio,
|
|
194
|
-
}); // southWest
|
|
195
|
-
const rightTop = this.map.unproject({ x: width / this.pixelRatio, y: 0 }); // north east
|
|
196
|
-
|
|
197
|
-
const coord0 = transformRotate(
|
|
198
|
-
point([leftBottom.lng, leftBottom.lat]),
|
|
199
|
-
-this.map.getBearing(),
|
|
200
|
-
{
|
|
201
|
-
pivot: [center.lng, center.lat],
|
|
202
|
-
},
|
|
203
|
-
).geometry.coordinates;
|
|
204
|
-
const coord1 = transformRotate(
|
|
205
|
-
point([rightTop.lng, rightTop.lat]),
|
|
206
|
-
-this.map.getBearing(),
|
|
207
|
-
{
|
|
208
|
-
pivot: [center.lng, center.lat],
|
|
209
|
-
},
|
|
210
|
-
).geometry.coordinates;
|
|
211
|
-
|
|
212
|
-
const bounds = [...fromLonLat(coord0), ...fromLonLat(coord1)];
|
|
213
|
-
const xResolution = getWidth(bounds) / (width / this.pixelRatio);
|
|
214
|
-
const yResolution = getHeight(bounds) / (height / this.pixelRatio);
|
|
215
|
-
const res = Math.max(xResolution, yResolution);
|
|
216
|
-
|
|
217
|
-
// Coordinate of trajectories are in mercator so we have to pass the proper resolution and center in mercator.
|
|
218
|
-
const viewState = {
|
|
219
|
-
size: [width / this.pixelRatio, height / this.pixelRatio],
|
|
220
|
-
center: fromLonLat([center.lng, center.lat]),
|
|
221
|
-
extent: bounds,
|
|
222
|
-
resolution: res,
|
|
223
|
-
zoom: this.map.getZoom(),
|
|
224
|
-
rotation: -(this.map.getBearing() * Math.PI) / 180,
|
|
225
|
-
pixelRatio: this.pixelRatio,
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
super.renderTrajectories(viewState, noInterpolate);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
/**
|
|
232
|
-
* Return the delay in ms before the next rendering.
|
|
233
|
-
*/
|
|
234
|
-
getRefreshTimeInMs() {
|
|
235
|
-
return super.getRefreshTimeInMs(this.map.getZoom());
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
getFeatureInfoAtCoordinate(coordinate, options = {}) {
|
|
239
|
-
const resolution = getMercatorResolution(this.map);
|
|
240
|
-
return super.getFeatureInfoAtCoordinate(coordinate, {
|
|
241
|
-
resolution,
|
|
242
|
-
...options,
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
onVisibilityChange() {
|
|
247
|
-
if (this.visible && !this.map.getLayer(this.key)) {
|
|
248
|
-
this.map.addLayer(this.layer, this.beforeId);
|
|
249
|
-
} else if (this.map.getLayer(this.key)) {
|
|
250
|
-
this.map.removeLayer(this.key);
|
|
251
|
-
}
|
|
252
|
-
// We can't use setLayoutProperty it triggers an error probably a bug in mapbox
|
|
253
|
-
// this.map.setLayoutProperty(
|
|
254
|
-
// this.key,
|
|
255
|
-
// 'visibilty',
|
|
256
|
-
// this.visible ? 'visible' : 'none',
|
|
257
|
-
// );
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/**
|
|
261
|
-
* Remove the trajectory form the list if necessary.
|
|
262
|
-
*
|
|
263
|
-
* @private
|
|
264
|
-
*/
|
|
265
|
-
purgeTrajectory(trajectory, extent, zoom) {
|
|
266
|
-
return super.purgeTrajectory(
|
|
267
|
-
trajectory,
|
|
268
|
-
extent || this.getMercatorExtent(),
|
|
269
|
-
zoom || Math.floor(this.map.getZoom() + 1),
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
/**
|
|
274
|
-
* Send the current bbox to the websocket
|
|
275
|
-
*/
|
|
276
|
-
setBbox(extent, zoom) {
|
|
277
|
-
let newExtent = extent;
|
|
278
|
-
let newZoom = zoom;
|
|
279
|
-
if (!newExtent && this.isUpdateBboxOnMoveEnd) {
|
|
280
|
-
newExtent = extent || this.getMercatorExtent();
|
|
281
|
-
newZoom = Math.floor(this.getOlZoom());
|
|
282
|
-
}
|
|
283
|
-
super.setBbox(newExtent, newZoom);
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
/**
|
|
287
|
-
* Callback on 'move' event.
|
|
288
|
-
*
|
|
289
|
-
* @private
|
|
290
|
-
*/
|
|
291
|
-
onMove() {
|
|
292
|
-
const extent = getSourceCoordinates(this.map, this.pixelRatio);
|
|
293
|
-
const source = this.map.getSource(this.key);
|
|
294
|
-
if (source) {
|
|
295
|
-
source.setCoordinates(extent);
|
|
296
|
-
}
|
|
297
|
-
this.renderTrajectories();
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
/**
|
|
301
|
-
* Send the new BBOX to the websocket.
|
|
302
|
-
*
|
|
303
|
-
* @param {ol/MapEvent~MapEvent} evt Moveend event
|
|
304
|
-
* @private
|
|
305
|
-
* @override
|
|
306
|
-
*/
|
|
307
|
-
onMoveEnd() {
|
|
308
|
-
this.renderTrajectories();
|
|
309
|
-
|
|
310
|
-
if (this.visible && this.isUpdateBboxOnMoveEnd) {
|
|
311
|
-
this.setBbox();
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
/**
|
|
316
|
-
* Update the cursor style when hovering a vehicle.
|
|
317
|
-
*
|
|
318
|
-
* @private
|
|
319
|
-
* @override
|
|
320
|
-
*/
|
|
321
|
-
onFeatureHover(features, layer, coordinate) {
|
|
322
|
-
super.onFeatureHover(features, layer, coordinate);
|
|
323
|
-
this.map.getCanvasContainer().style.cursor = features.length
|
|
324
|
-
? 'pointer'
|
|
325
|
-
: 'auto';
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
export default TralisLayer;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import TralisLayer from './TralisLayer';
|
|
2
|
-
|
|
3
|
-
let layer;
|
|
4
|
-
let onClick;
|
|
5
|
-
|
|
6
|
-
describe('TralisLayer', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
onClick = jest.fn();
|
|
9
|
-
layer = new TralisLayer({
|
|
10
|
-
onClick,
|
|
11
|
-
});
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
test('should be instanced.', () => {
|
|
15
|
-
expect(layer).toBeInstanceOf(TralisLayer);
|
|
16
|
-
expect(layer.clickCallbacks[0]).toBe(onClick);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
test('#onClick', () => {
|
|
20
|
-
const f = () => {};
|
|
21
|
-
layer.onClick(f);
|
|
22
|
-
expect(layer.clickCallbacks[1]).toBe(f);
|
|
23
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
24
|
-
layer.onClick(f);
|
|
25
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
test('#unClick', () => {
|
|
29
|
-
const foo = () => {};
|
|
30
|
-
const bar = () => {};
|
|
31
|
-
layer.onClick(foo);
|
|
32
|
-
layer.onClick(bar);
|
|
33
|
-
expect(layer.clickCallbacks[1]).toBe(foo);
|
|
34
|
-
expect(layer.clickCallbacks[2]).toBe(bar);
|
|
35
|
-
expect(layer.clickCallbacks.length).toBe(3);
|
|
36
|
-
layer.unClick(foo);
|
|
37
|
-
expect(layer.clickCallbacks[1]).toBe(bar);
|
|
38
|
-
expect(layer.clickCallbacks.length).toBe(2);
|
|
39
|
-
});
|
|
40
|
-
});
|
package/mapbox/utils.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { getWidth, getHeight } from 'ol/extent';
|
|
2
|
-
import { fromLonLat } from 'ol/proj';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Get the current resolution of a Mapbox map.
|
|
6
|
-
* @param {mapboxgl.Map} map A map object.
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
export const getMercatorResolution = (map) => {
|
|
10
|
-
const bounds = map.getBounds().toArray();
|
|
11
|
-
const a = fromLonLat(bounds[0]);
|
|
12
|
-
const b = fromLonLat(bounds[1]);
|
|
13
|
-
const extent = [...a, ...b];
|
|
14
|
-
const { width, height } = map.getCanvas();
|
|
15
|
-
const xResolution = getWidth(extent) / width;
|
|
16
|
-
const yResolution = getHeight(extent) / height;
|
|
17
|
-
return Math.max(xResolution, yResolution);
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Get the canvas source coordinates of the current map's extent.
|
|
22
|
-
* @param {mapboxgl.Map} map A map object.
|
|
23
|
-
* @private
|
|
24
|
-
*/
|
|
25
|
-
export const getSourceCoordinates = (map, pixelRatio) => {
|
|
26
|
-
// Requesting getBounds is not enough when we rotate the map, so we request manually each corner.
|
|
27
|
-
const { width, height } = map.getCanvas();
|
|
28
|
-
const leftTop = map.unproject({ x: 0, y: 0 });
|
|
29
|
-
const leftBottom = map.unproject({ x: 0, y: height / pixelRatio }); // southWest
|
|
30
|
-
const rightBottom = map.unproject({
|
|
31
|
-
x: width / pixelRatio,
|
|
32
|
-
y: height / pixelRatio,
|
|
33
|
-
});
|
|
34
|
-
const rightTop = map.unproject({ x: width / pixelRatio, y: 0 }); // north east
|
|
35
|
-
return [
|
|
36
|
-
[leftTop.lng, leftTop.lat],
|
|
37
|
-
[rightTop.lng, rightTop.lat],
|
|
38
|
-
[rightBottom.lng, rightBottom.lat],
|
|
39
|
-
[leftBottom.lng, leftBottom.lat],
|
|
40
|
-
];
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
export default {
|
|
44
|
-
getMercatorResolution,
|
|
45
|
-
getSourceCoordinates,
|
|
46
|
-
};
|
package/module.js
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Layer as olLayer,
|
|
3
|
-
WMSLayer as olWMSLayer,
|
|
4
|
-
MapboxLayer as olMapboxLayer,
|
|
5
|
-
TralisLayer as olTralisLayer,
|
|
6
|
-
VectorLayer as olVectorLayer,
|
|
7
|
-
} from './ol';
|
|
8
|
-
import { TralisLayer as mbTralisLayer } from './mapbox';
|
|
9
|
-
|
|
10
|
-
const exports = {
|
|
11
|
-
mapbox: {
|
|
12
|
-
TralisLayer: mbTralisLayer,
|
|
13
|
-
},
|
|
14
|
-
ol: {
|
|
15
|
-
Layer: olLayer,
|
|
16
|
-
WMSLayer: olWMSLayer,
|
|
17
|
-
MapboxLayer: olMapboxLayer,
|
|
18
|
-
TralisLayer: olTralisLayer,
|
|
19
|
-
VectorLayer: olVectorLayer,
|
|
20
|
-
},
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export default exports;
|
package/ol/README.md
DELETED
|
File without changes
|