mobility-toolbox-js 2.0.0-beta.8 → 2.0.1-beta.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RoutingAPI.js +15 -0
- package/api/RoutingAPI.test.js +25 -0
- package/api/StopsAPI.js +12 -0
- package/api/StopsAPI.test.js +22 -0
- package/api/TralisAPI.js +359 -0
- package/api/TralisAPI.test.js +67 -0
- package/{src/api/tralis → api}/TralisAPIUtils.js +2 -32
- package/api/index.js +3 -0
- package/{index.html → api/typedefs.js} +0 -0
- package/common/Tracker.js +93 -0
- package/common/api/HttpAPI.js +30 -0
- package/common/api/HttpAPI.test.js +50 -0
- package/common/api/WebSocketAPI.js +175 -0
- package/{src/api/tralis/WebSocketConnector.test.js → common/api/WebSocketAPI.test.js} +100 -145
- package/common/controls/Control.js +81 -0
- package/{src/common → common}/controls/Control.test.js +32 -43
- package/common/index.js +4 -0
- package/common/layers/Layer.js +213 -0
- package/{src/common → common}/layers/Layer.test.js +185 -244
- package/common/mixins/CopyrightMixin.js +24 -0
- package/common/mixins/SearchMixin.js +110 -0
- package/common/mixins/TralisLayerMixin.js +479 -0
- package/common/styles/index.js +4 -0
- package/{src/common → common}/styles/trackerDefaultStyle.js +39 -175
- package/common/styles/trackerDelayStyle.js +8 -0
- package/{src/common → common}/styles/trackerSimpleStyle.js +4 -8
- package/{src/common → common}/trackerConfig.js +61 -99
- package/common/trackerConfig.test.js +23 -0
- package/{src/doc/examples/ol-mapbox-layer.md → common/typedefs.js} +0 -0
- package/common/utils/createTrackerFilters.js +56 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/{src/common → common}/utils/getMapboxMapCopyrights.js +3 -16
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/{src/common → common}/utils/getMapboxStyleUrl.js +3 -13
- package/{src/common → common}/utils/getVehiclePosition.js +3 -33
- package/common/utils/index.js +5 -0
- package/common/utils/removeDuplicate.js +8 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/{src/common → common}/utils/sortByDelay.js +2 -7
- package/common/utils/timeUtils.js +20 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/index.js +8 -0
- package/mapbox/controls/CopyrightControl.js +29 -0
- package/mapbox/controls/index.js +1 -0
- package/mapbox/index.js +4 -0
- package/mapbox/layers/Layer.js +57 -0
- package/mapbox/layers/Layer.test.js +182 -0
- package/mapbox/layers/TralisLayer.js +182 -0
- package/{src/mapbox → mapbox}/layers/TralisLayer.test.js +12 -14
- package/mapbox/layers/index.js +2 -0
- package/{src/mapbox → mapbox}/utils.js +7 -21
- package/mbt.js +50444 -0
- package/mbt.js.map +7 -0
- package/mbt.min.js +1005 -0
- package/mbt.min.js.map +7 -0
- package/ol/controls/CopyrightControl.js +42 -0
- package/ol/controls/CopyrightControl.test.js +165 -0
- package/ol/controls/RoutingControl.js +387 -0
- package/ol/controls/RoutingControl.test.js +151 -0
- package/ol/controls/StopFinderControl.js +10 -0
- package/ol/controls/StopFinderControl.test.js +48 -0
- package/ol/controls/index.js +3 -0
- package/ol/index.js +5 -0
- package/ol/layers/Layer.js +88 -0
- package/ol/layers/Layer.test.js +174 -0
- package/ol/layers/MapboxLayer.js +203 -0
- package/{src/ol → ol}/layers/MapboxLayer.test.js +58 -84
- package/ol/layers/MapboxStyleLayer.js +187 -0
- package/{src/ol → ol}/layers/MapboxStyleLayer.test.js +97 -128
- package/ol/layers/MaplibreLayer.js +139 -0
- package/ol/layers/RoutingLayer.js +61 -0
- package/{src/ol → ol}/layers/RoutingLayer.test.js +15 -24
- package/ol/layers/TralisLayer.js +185 -0
- package/ol/layers/TralisLayer.test.js +79 -0
- package/ol/layers/VectorLayer.js +22 -0
- package/{src/ol → ol}/layers/VectorLayer.test.js +34 -45
- package/ol/layers/WMSLayer.js +38 -0
- package/ol/layers/WMSLayer.test.js +76 -0
- package/ol/layers/index.js +8 -0
- package/{src/ol → ol}/styles/fullTrajectoryDelayStyle.js +11 -15
- package/ol/styles/fullTrajectoryStyle.js +43 -0
- package/ol/styles/index.js +2 -0
- package/package.json +34 -74
- package/.babelrc +0 -6
- package/.esdoc.json +0 -17
- package/.eslintignore +0 -1
- package/.github/workflows/conventional-pr-title.yml +0 -21
- package/.github/workflows/cypress.yml +0 -29
- package/.github/workflows/nodejs.yml +0 -28
- package/.husky/commit-msg +0 -4
- package/.husky/post-checkout +0 -4
- package/.husky/post-merge +0 -4
- package/.husky/post-rebase +0 -4
- package/.husky/pre-commit +0 -4
- package/.neutrinorc.js +0 -176
- package/.nvmrc +0 -1
- package/CHANGELOG.md +0 -10
- package/LICENSE +0 -21
- package/__mocks__/mapbox-gl.js +0 -81
- package/__mocks__/maplibre-gl.js +0 -81
- package/commitlint.config.js +0 -1
- package/cypress/fixtures/example.json +0 -5
- package/cypress/integration/examples/api.spec.js +0 -7
- package/cypress/integration/examples/examples.spec.js +0 -7
- package/cypress/integration/examples/navigation.spec.js +0 -29
- package/cypress/plugins/index.js +0 -21
- package/cypress/support/commands.js +0 -25
- package/cypress/support/index.js +0 -20
- package/cypress.json +0 -4
- package/data/fetchRoute.json +0 -292
- package/data/fetchTrajectories.json +0 -18
- package/data/fetchTrajectoryById.json +0 -3
- package/data/fetchTrajectoryStations.json +0 -18
- package/data/stopsSearch.json +0 -15
- package/documentation.yml +0 -4
- package/esdoc/README.md +0 -27
- package/esdoc/plugins/MyPlugin.js +0 -69
- package/esdoc/plugins/dynamic-property-plugin/Plugin.js +0 -50
- package/esdoc/plugins/externals-plugin/Plugin.js +0 -45
- package/esdoc/plugins/externals-plugin/externals.js +0 -96
- package/global-setup.js +0 -3
- package/indexweb.html +0 -49
- package/jest.config.js +0 -5
- package/pull_request_template.md +0 -17
- package/renovate.json +0 -4
- package/scripts/read-pkg-json.js +0 -22
- package/src/api/index.js +0 -3
- package/src/api/routing/RoutingAPI.js +0 -44
- package/src/api/routing/RoutingAPI.test.js +0 -41
- package/src/api/stops/StopsAPI.js +0 -41
- package/src/api/stops/StopsAPI.test.js +0 -34
- package/src/api/tralis/TralisAPI.js +0 -731
- package/src/api/tralis/TralisAPI.test.js +0 -75
- package/src/api/tralis/WebSocketConnector.js +0 -338
- package/src/api/tralis/typedefs.js +0 -81
- package/src/assets/Lato-Black.ttf +0 -0
- package/src/assets/Lato-BlackItalic.ttf +0 -0
- package/src/assets/Lato-Bold.ttf +0 -0
- package/src/assets/Lato-BoldItalic.ttf +0 -0
- package/src/assets/Lato-Italic.ttf +0 -0
- package/src/assets/Lato-Light.ttf +0 -0
- package/src/assets/Lato-LightItalic.ttf +0 -0
- package/src/assets/Lato-Regular.ttf +0 -0
- package/src/assets/Lato-Thin.ttf +0 -0
- package/src/assets/Lato-ThinItalic.ttf +0 -0
- package/src/assets/OFL.txt +0 -93
- package/src/common/Tracker.js +0 -197
- package/src/common/api/api.js +0 -64
- package/src/common/api/api.test.js +0 -68
- package/src/common/controls/Control.js +0 -146
- package/src/common/index.js +0 -5
- package/src/common/layers/Layer.js +0 -404
- package/src/common/mixins/CopyrightMixin.js +0 -48
- package/src/common/mixins/SearchMixin.js +0 -176
- package/src/common/mixins/TralisLayerMixin.js +0 -930
- package/src/common/styles/index.js +0 -4
- package/src/common/styles/trackerDelayStyle.js +0 -17
- package/src/common/trackerConfig.test.js +0 -25
- package/src/common/typedefs.js +0 -23
- package/src/common/utils/createTrackerFilters.js +0 -87
- package/src/common/utils/createTrackerFilters.test.js +0 -95
- package/src/common/utils/getMapboxMapCopyrights.test.js +0 -47
- package/src/common/utils/index.js +0 -5
- package/src/common/utils/removeDuplicate.js +0 -22
- package/src/common/utils/removeDuplicate.test.js +0 -22
- package/src/common/utils/timeUtils.js +0 -44
- package/src/common/utils/timeUtils.test.js +0 -16
- package/src/doc/App.js +0 -116
- package/src/doc/App.scss +0 -51
- package/src/doc/_redirects +0 -2
- package/src/doc/components/CodeSandboxButton.js +0 -103
- package/src/doc/components/Documentation.js +0 -40
- package/src/doc/components/Esdoc/Anchor.js +0 -57
- package/src/doc/components/Esdoc/ClassDoc.js +0 -272
- package/src/doc/components/Esdoc/DeprecatedHTML.js +0 -16
- package/src/doc/components/Esdoc/DetailDocs.js +0 -281
- package/src/doc/components/Esdoc/DetailHTML.js +0 -33
- package/src/doc/components/Esdoc/DirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/DocBuilderUtils.js +0 -694
- package/src/doc/components/Esdoc/DocLinkHTML.js +0 -62
- package/src/doc/components/Esdoc/DocsLinkHTML.js +0 -38
- package/src/doc/components/Esdoc/Esdoc.js +0 -63
- package/src/doc/components/Esdoc/EsdocContent.js +0 -51
- package/src/doc/components/Esdoc/EsdocNavigation.js +0 -13
- package/src/doc/components/Esdoc/EsdocSearch.js +0 -81
- package/src/doc/components/Esdoc/ExperimentalHTML.js +0 -17
- package/src/doc/components/Esdoc/ExtendsChainHTML.js +0 -32
- package/src/doc/components/Esdoc/FileDocLinkHTML.js +0 -60
- package/src/doc/components/Esdoc/IdentifiersDoc.js +0 -113
- package/src/doc/components/Esdoc/IndirectSubclassHTML.js +0 -30
- package/src/doc/components/Esdoc/InheritedSummaryDoc.js +0 -70
- package/src/doc/components/Esdoc/InheritedSummaryHTML.js +0 -38
- package/src/doc/components/Esdoc/MixinClassesHTML.js +0 -29
- package/src/doc/components/Esdoc/NavDoc.js +0 -112
- package/src/doc/components/Esdoc/OverrideMethod.js +0 -44
- package/src/doc/components/Esdoc/OverrideMethodDescription.js +0 -35
- package/src/doc/components/Esdoc/Properties.js +0 -89
- package/src/doc/components/Esdoc/README.md +0 -45
- package/src/doc/components/Esdoc/SignatureHTML.js +0 -123
- package/src/doc/components/Esdoc/SingleDoc.js +0 -31
- package/src/doc/components/Esdoc/SummaryDoc.js +0 -160
- package/src/doc/components/Esdoc/SummaryHTML.js +0 -96
- package/src/doc/components/Esdoc/TypeDocLinkHTML.js +0 -249
- package/src/doc/components/Esdoc/css/identifiers.css +0 -38
- package/src/doc/components/Esdoc/css/search.css +0 -76
- package/src/doc/components/Esdoc/css/style.css +0 -603
- package/src/doc/components/Esdoc/index.js +0 -7
- package/src/doc/components/Example.js +0 -153
- package/src/doc/components/Examples.js +0 -183
- package/src/doc/components/Home.js +0 -106
- package/src/doc/components/TrackerExample.js +0 -38
- package/src/doc/examples/assets/tralis-live-map/index.js +0 -11
- package/src/doc/examples/assets/tralis-live-map/s1kreis.svg +0 -105
- package/src/doc/examples/assets/tralis-live-map/s20kreis.svg +0 -101
- package/src/doc/examples/assets/tralis-live-map/s2kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s3kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s4kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s6kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s7kreis.svg +0 -95
- package/src/doc/examples/assets/tralis-live-map/s8kreis.svg +0 -93
- package/src/doc/examples/assets/tralis-live-map/unknown.svg +0 -107
- package/src/doc/examples/mb-copyright.html +0 -26
- package/src/doc/examples/mb-copyright.js +0 -37
- package/src/doc/examples/mb-tracker.html +0 -1
- package/src/doc/examples/mb-tracker.js +0 -39
- package/src/doc/examples/mb-tracker.md +0 -1
- package/src/doc/examples/mb-tralis.html +0 -1
- package/src/doc/examples/mb-tralis.js +0 -34
- package/src/doc/examples/ol-copyright.html +0 -26
- package/src/doc/examples/ol-copyright.js +0 -43
- package/src/doc/examples/ol-mapbox-layer.html +0 -1
- package/src/doc/examples/ol-mapbox-layer.js +0 -28
- package/src/doc/examples/ol-mapbox-style-layer.html +0 -12
- package/src/doc/examples/ol-mapbox-style-layer.js +0 -44
- package/src/doc/examples/ol-query.html +0 -32
- package/src/doc/examples/ol-query.js +0 -83
- package/src/doc/examples/ol-routing.html +0 -26
- package/src/doc/examples/ol-routing.js +0 -59
- package/src/doc/examples/ol-routing.md +0 -1
- package/src/doc/examples/ol-stop-finder.html +0 -15
- package/src/doc/examples/ol-stop-finder.js +0 -31
- package/src/doc/examples/ol-stop-finder.md +0 -1
- package/src/doc/examples/ol-tracker.html +0 -1
- package/src/doc/examples/ol-tracker.js +0 -44
- package/src/doc/examples/ol-tracker.md +0 -1
- package/src/doc/examples/ol-tralis.html +0 -5
- package/src/doc/examples/ol-tralis.js +0 -57
- package/src/doc/examples/tralis-live-map.html +0 -1
- package/src/doc/examples/tralis-live-map.js +0 -51
- package/src/doc/examples/tralis-live-map.md +0 -3
- package/src/doc/examples.js +0 -107
- package/src/doc/img/examples/live_tracker_mb.jpg +0 -0
- package/src/doc/img/examples/live_tracker_munich.jpg +0 -0
- package/src/doc/img/examples/live_tracker_ol.jpg +0 -0
- package/src/doc/img/examples/mapbox.jpg +0 -0
- package/src/doc/img/examples/mapbox_style.jpg +0 -0
- package/src/doc/img/examples/ol-copyright.png +0 -0
- package/src/doc/img/examples/query_objects.jpg +0 -0
- package/src/doc/img/examples/routing.jpg +0 -0
- package/src/doc/img/examples/simple_map.jpg +0 -0
- package/src/doc/img/examples/stops.jpg +0 -0
- package/src/doc/img/favico.ico +0 -0
- package/src/doc/index.js +0 -21
- package/src/iife.js +0 -7
- package/src/index.js +0 -10
- package/src/mapbox/controls/CopyrightControl.js +0 -58
- package/src/mapbox/controls/index.js +0 -2
- package/src/mapbox/index.js +0 -4
- package/src/mapbox/layers/Layer.js +0 -118
- package/src/mapbox/layers/Layer.test.js +0 -202
- package/src/mapbox/layers/TralisLayer.js +0 -329
- package/src/mapbox/layers/index.js +0 -2
- package/src/ol/README.md +0 -0
- package/src/ol/controls/CopyrightControl.js +0 -80
- package/src/ol/controls/CopyrightControl.test.js +0 -211
- package/src/ol/controls/RoutingControl.js +0 -752
- package/src/ol/controls/RoutingControl.test.js +0 -216
- package/src/ol/controls/StopFinderControl.js +0 -38
- package/src/ol/controls/StopFinderControl.test.js +0 -59
- package/src/ol/controls/index.js +0 -3
- package/src/ol/controls/snapshots/RoutingControlRouteGen10.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteGen100.json +0 -292
- package/src/ol/controls/snapshots/RoutingControlRouteGen30.json +0 -69
- package/src/ol/controls/snapshots/RoutingControlRouteGen5.json +0 -58
- package/src/ol/controls/snapshots/RoutingControlRouteOSM.json +0 -759
- package/src/ol/controls/snapshots/RoutingControlStation1.json +0 -60
- package/src/ol/controls/snapshots/RoutingControlStation2.json +0 -49
- package/src/ol/index.js +0 -5
- package/src/ol/layers/Layer.js +0 -193
- package/src/ol/layers/Layer.test.js +0 -197
- package/src/ol/layers/MapboxLayer.js +0 -378
- package/src/ol/layers/MapboxStyleLayer.js +0 -417
- package/src/ol/layers/MaplibreLayer.js +0 -280
- package/src/ol/layers/RoutingLayer.js +0 -91
- package/src/ol/layers/TralisLayer.js +0 -359
- package/src/ol/layers/TralisLayer.test.js +0 -97
- package/src/ol/layers/VectorLayer.js +0 -43
- package/src/ol/layers/WMSLayer.js +0 -80
- package/src/ol/layers/WMSLayer.test.js +0 -84
- package/src/ol/layers/index.js +0 -8
- package/src/ol/styles/fullTrajectoryStyle.js +0 -51
- package/src/ol/styles/index.js +0 -2
- package/src/setupTests.js +0 -15
- package/webpack.config.js +0 -6
|
@@ -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;
|
package/src/ol/README.md
DELETED
|
File without changes
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { inView } from 'ol/layer/Layer';
|
|
2
|
-
import Control from '../../common/controls/Control';
|
|
3
|
-
import mixin from '../../common/mixins/CopyrightMixin';
|
|
4
|
-
import removeDuplicate from '../../common/utils/removeDuplicate';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Display layer's copyrights.
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* import { Map } from 'ol';
|
|
11
|
-
* import { CopyrightControl } from 'mobility-toolbox-js/ol';
|
|
12
|
-
*
|
|
13
|
-
* const map = new Map({
|
|
14
|
-
* target: 'map',
|
|
15
|
-
* });
|
|
16
|
-
* const control = new CopyrightControl();
|
|
17
|
-
* control.map = map
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
* @see <a href="/example/ol-copyright">Openlayers copyright example</a>
|
|
21
|
-
*
|
|
22
|
-
* @extends {Control}
|
|
23
|
-
* @implements {CopyrightInterface}
|
|
24
|
-
*/
|
|
25
|
-
class CopyrightControl extends mixin(Control) {
|
|
26
|
-
constructor(options) {
|
|
27
|
-
super(options);
|
|
28
|
-
this.onPostRender = this.onPostRender.bind(this);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
getCopyrights() {
|
|
32
|
-
if (!this.frameState) {
|
|
33
|
-
return [];
|
|
34
|
-
}
|
|
35
|
-
let copyrights = [];
|
|
36
|
-
|
|
37
|
-
// This code loop comes mainly from ol.
|
|
38
|
-
this.frameState.layerStatesArray.forEach((layerState) => {
|
|
39
|
-
const { layer } = layerState;
|
|
40
|
-
if (
|
|
41
|
-
inView(layerState, this.frameState.viewState) &&
|
|
42
|
-
layer &&
|
|
43
|
-
layer.getSource &&
|
|
44
|
-
layer.getSource() &&
|
|
45
|
-
layer.getSource().getAttributions()
|
|
46
|
-
) {
|
|
47
|
-
copyrights = copyrights.concat(
|
|
48
|
-
layer.getSource().getAttributions()(this.frameState),
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
return removeDuplicate(copyrights);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
activate() {
|
|
56
|
-
super.activate();
|
|
57
|
-
if (this.map) {
|
|
58
|
-
this.map.on('postrender', this.onPostRender);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
deactivate() {
|
|
63
|
-
if (this.map) {
|
|
64
|
-
this.map.un('postrender', this.onPostRender);
|
|
65
|
-
}
|
|
66
|
-
super.deactivate();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
onPostRender(evt) {
|
|
70
|
-
if (this.map && this.element) {
|
|
71
|
-
/**
|
|
72
|
-
* @ignore
|
|
73
|
-
*/
|
|
74
|
-
this.frameState = evt.frameState;
|
|
75
|
-
this.render();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default CopyrightControl;
|