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
package/src/common/Tracker.js
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-param-reassign */
|
|
2
|
-
import { compose, apply, create } from 'ol/transform';
|
|
3
|
-
import getVehiclePosition from './utils/getVehiclePosition';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Tracker. This class stores and allows to draw trajectories on a canvas.
|
|
7
|
-
* @class
|
|
8
|
-
* @param {Object} options
|
|
9
|
-
* @private
|
|
10
|
-
*/
|
|
11
|
-
export default class Tracker {
|
|
12
|
-
/**
|
|
13
|
-
* @private
|
|
14
|
-
*/
|
|
15
|
-
constructor(options) {
|
|
16
|
-
/**
|
|
17
|
-
* Function use to style the features displayed.
|
|
18
|
-
* @type {function}
|
|
19
|
-
*/
|
|
20
|
-
this.style = options.style;
|
|
21
|
-
|
|
22
|
-
// we draw directly on the canvas since openlayers is too slow.
|
|
23
|
-
/**
|
|
24
|
-
* HTML <canvas> element.
|
|
25
|
-
* @type {Canvas}
|
|
26
|
-
*/
|
|
27
|
-
this.canvas = options.canvas || document.createElement('canvas');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Draw all the trajectories available to the canvas.
|
|
32
|
-
* @param {ViewState} trajectories An array of trajectories.
|
|
33
|
-
* @param {ViewState} viewState The view state of the map.
|
|
34
|
-
* @param {boolean} options.hoverVehicleId The id of the vehicle to highlight.
|
|
35
|
-
* @param {boolean} options.selectedVehicleId The id of the vehicle to select.
|
|
36
|
-
* @param {boolean} options.noInterpolate If true trajectories are not interpolated but
|
|
37
|
-
* drawn at the last known coordinate. Use this for performance optimization
|
|
38
|
-
* during map navigation.
|
|
39
|
-
* @private
|
|
40
|
-
*/
|
|
41
|
-
renderTrajectories(trajectories, viewState, options) {
|
|
42
|
-
const {
|
|
43
|
-
time = Date.now(),
|
|
44
|
-
size = [],
|
|
45
|
-
center,
|
|
46
|
-
resolution,
|
|
47
|
-
rotation = 0,
|
|
48
|
-
pixelRatio,
|
|
49
|
-
} = viewState;
|
|
50
|
-
const {
|
|
51
|
-
noInterpolate = false,
|
|
52
|
-
hoverVehicleId,
|
|
53
|
-
selectedVehicleId,
|
|
54
|
-
} = options;
|
|
55
|
-
|
|
56
|
-
const { canvas } = this;
|
|
57
|
-
const context = canvas.getContext('2d');
|
|
58
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
59
|
-
|
|
60
|
-
const [width, height] = size;
|
|
61
|
-
if (
|
|
62
|
-
width &&
|
|
63
|
-
height &&
|
|
64
|
-
(canvas.width !== width || canvas.height !== height)
|
|
65
|
-
) {
|
|
66
|
-
[canvas.width, canvas.height] = [width * pixelRatio, height * pixelRatio];
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const coordinateToPixelTransform = compose(
|
|
70
|
-
create(),
|
|
71
|
-
size[0] / 2,
|
|
72
|
-
size[1] / 2,
|
|
73
|
-
1 / resolution,
|
|
74
|
-
-1 / resolution,
|
|
75
|
-
-rotation,
|
|
76
|
-
-center[0],
|
|
77
|
-
-center[1],
|
|
78
|
-
);
|
|
79
|
-
|
|
80
|
-
// Offscreen canvas has not style attribute
|
|
81
|
-
if (canvas.style) {
|
|
82
|
-
canvas.style.width = `${canvas.width / pixelRatio}px`;
|
|
83
|
-
canvas.style.height = `${canvas.height / pixelRatio}px`;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
let hoverVehicleImg;
|
|
87
|
-
let hoverVehiclePx;
|
|
88
|
-
let hoverVehicleWidth;
|
|
89
|
-
let hoverVehicleHeight;
|
|
90
|
-
let selectedVehicleImg;
|
|
91
|
-
let selectedVehiclePx;
|
|
92
|
-
let selectedVehicleWidth;
|
|
93
|
-
let selectedVehicleHeight;
|
|
94
|
-
let nbRendered = 0;
|
|
95
|
-
|
|
96
|
-
for (let i = trajectories.length - 1; i >= 0; i -= 1) {
|
|
97
|
-
const trajectory = trajectories[i];
|
|
98
|
-
|
|
99
|
-
// We simplify the trajectory object
|
|
100
|
-
const { train_id: id, timeOffset } = trajectory.properties;
|
|
101
|
-
// We set the rotation and the timeFraction of the trajectory (used by tralis).
|
|
102
|
-
// if rotation === null that seems there is no rotation available.
|
|
103
|
-
const { coord, rotation: rotationIcon } = getVehiclePosition(
|
|
104
|
-
time - (timeOffset || 0),
|
|
105
|
-
trajectory,
|
|
106
|
-
noInterpolate,
|
|
107
|
-
);
|
|
108
|
-
|
|
109
|
-
// We store the current vehicle position to the trajectory.
|
|
110
|
-
trajectories[i].properties.coordinate = coord;
|
|
111
|
-
trajectories[i].properties.rotation = rotationIcon;
|
|
112
|
-
|
|
113
|
-
if (!coord) {
|
|
114
|
-
// eslint-disable-next-line no-continue
|
|
115
|
-
continue;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
let px = apply(coordinateToPixelTransform, [...coord]);
|
|
119
|
-
if (!px) {
|
|
120
|
-
// eslint-disable-next-line no-continue
|
|
121
|
-
continue;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
px = px.map((p) => p * pixelRatio);
|
|
125
|
-
|
|
126
|
-
if (
|
|
127
|
-
px[0] < 0 ||
|
|
128
|
-
px[0] > canvas.width ||
|
|
129
|
-
px[1] < 0 ||
|
|
130
|
-
px[1] > canvas.height
|
|
131
|
-
) {
|
|
132
|
-
// eslint-disable-next-line no-continue
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
const vehicleImg = this.style(trajectory, viewState, options);
|
|
137
|
-
if (!vehicleImg) {
|
|
138
|
-
// eslint-disable-next-line no-continue
|
|
139
|
-
continue;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
nbRendered += 1;
|
|
143
|
-
|
|
144
|
-
const imgWidth = vehicleImg.width;
|
|
145
|
-
const imgHeight = vehicleImg.height;
|
|
146
|
-
|
|
147
|
-
if (hoverVehicleId !== id && selectedVehicleId !== id) {
|
|
148
|
-
context.drawImage(
|
|
149
|
-
vehicleImg,
|
|
150
|
-
px[0] - imgWidth / 2,
|
|
151
|
-
px[1] - imgHeight / 2,
|
|
152
|
-
imgWidth,
|
|
153
|
-
imgHeight,
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
if (hoverVehicleId && hoverVehicleId === id) {
|
|
158
|
-
// Store the canvas to draw it at the end
|
|
159
|
-
hoverVehicleImg = vehicleImg;
|
|
160
|
-
hoverVehiclePx = px;
|
|
161
|
-
hoverVehicleWidth = imgWidth;
|
|
162
|
-
hoverVehicleHeight = imgHeight;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (selectedVehicleId && selectedVehicleId === id) {
|
|
166
|
-
// Store the canvas to draw it at the end
|
|
167
|
-
selectedVehicleImg = vehicleImg;
|
|
168
|
-
selectedVehiclePx = px;
|
|
169
|
-
selectedVehicleWidth = imgWidth;
|
|
170
|
-
selectedVehicleHeight = imgHeight;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
if (selectedVehicleImg) {
|
|
175
|
-
context.drawImage(
|
|
176
|
-
selectedVehicleImg,
|
|
177
|
-
selectedVehiclePx[0] - selectedVehicleWidth / 2,
|
|
178
|
-
selectedVehiclePx[1] - selectedVehicleHeight / 2,
|
|
179
|
-
selectedVehicleWidth,
|
|
180
|
-
selectedVehicleHeight,
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
if (hoverVehicleImg) {
|
|
185
|
-
context.drawImage(
|
|
186
|
-
hoverVehicleImg,
|
|
187
|
-
hoverVehiclePx[0] - hoverVehicleWidth / 2,
|
|
188
|
-
hoverVehiclePx[1] - hoverVehicleHeight / 2,
|
|
189
|
-
hoverVehicleWidth,
|
|
190
|
-
hoverVehicleHeight,
|
|
191
|
-
);
|
|
192
|
-
}
|
|
193
|
-
return {
|
|
194
|
-
nbTrajectoriesRendered: nbRendered,
|
|
195
|
-
};
|
|
196
|
-
}
|
|
197
|
-
}
|
package/src/common/api/api.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import qs from 'query-string';
|
|
2
|
-
import BaseObject from 'ol/Object';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Common class to access to a geOps api.
|
|
6
|
-
*
|
|
7
|
-
* @example
|
|
8
|
-
* import { API } from 'mobility-toolbox-js/api';
|
|
9
|
-
*
|
|
10
|
-
* const api = new API({
|
|
11
|
-
* url: [yourUrl],
|
|
12
|
-
* apiKey: [yourApiKey]
|
|
13
|
-
* });
|
|
14
|
-
*
|
|
15
|
-
* @classproperty {string} url Url of the service.
|
|
16
|
-
* @classproperty {string} apiKey Api key to access the service.
|
|
17
|
-
*/
|
|
18
|
-
class API extends BaseObject {
|
|
19
|
-
constructor(options = {}) {
|
|
20
|
-
super();
|
|
21
|
-
/** @ignore */
|
|
22
|
-
this.url = options.url;
|
|
23
|
-
|
|
24
|
-
/** @ignore */
|
|
25
|
-
this.apiKey = options.apiKey;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Append the apiKey before sending the request.
|
|
30
|
-
* @ignore
|
|
31
|
-
*/
|
|
32
|
-
fetch(path, params, config) {
|
|
33
|
-
// Clean requets parameters, removing undefined and null values.
|
|
34
|
-
const urlParams = { ...(params || {}), key: this.apiKey };
|
|
35
|
-
const clone = { ...urlParams };
|
|
36
|
-
Object.keys(urlParams).forEach(
|
|
37
|
-
(key) =>
|
|
38
|
-
(clone[key] === undefined || clone[key] === null) && delete clone[key],
|
|
39
|
-
);
|
|
40
|
-
if (!this.apiKey) {
|
|
41
|
-
// eslint-disable-next-line no-console
|
|
42
|
-
return Promise.reject(
|
|
43
|
-
new Error(`No apiKey defined for request to ${this.url}`),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
return fetch(
|
|
47
|
-
`${this.url}${path || ''}?${qs.stringify(clone)}`,
|
|
48
|
-
config,
|
|
49
|
-
).then((response) => {
|
|
50
|
-
try {
|
|
51
|
-
return response.json().then((data) => {
|
|
52
|
-
if (data.error) {
|
|
53
|
-
throw new Error(data.error);
|
|
54
|
-
}
|
|
55
|
-
return data;
|
|
56
|
-
});
|
|
57
|
-
} catch (err) {
|
|
58
|
-
return Promise.reject(new Error(err));
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export default API;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import fetch from 'jest-fetch-mock';
|
|
2
|
-
import API from './api';
|
|
3
|
-
|
|
4
|
-
let api;
|
|
5
|
-
|
|
6
|
-
describe('API', () => {
|
|
7
|
-
beforeEach(() => {
|
|
8
|
-
global.fetch = fetch;
|
|
9
|
-
fetch.resetMocks();
|
|
10
|
-
|
|
11
|
-
api = new API({ url: 'https://foo.ch', apiKey: 'apiKey' });
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
describe('#fetch', () => {
|
|
15
|
-
test('should success', () => {
|
|
16
|
-
fetch.mockResponseOnce(JSON.stringify({ foo: 'bar' }));
|
|
17
|
-
|
|
18
|
-
return api
|
|
19
|
-
.fetch('/path', {
|
|
20
|
-
q: 'Bern',
|
|
21
|
-
fooUndefined: undefined,
|
|
22
|
-
fooNull: null,
|
|
23
|
-
fooEmpty: '',
|
|
24
|
-
})
|
|
25
|
-
.then((response) => {
|
|
26
|
-
// Correct url
|
|
27
|
-
expect(fetch.mock.calls[0][0]).toEqual(
|
|
28
|
-
'https://foo.ch/path?fooEmpty=&key=apiKey&q=Bern',
|
|
29
|
-
);
|
|
30
|
-
|
|
31
|
-
// Correct search result
|
|
32
|
-
expect(response).toEqual({ foo: 'bar' });
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
describe('should display error message', () => {
|
|
37
|
-
test('reject error', (done) => {
|
|
38
|
-
fetch.mockRejectOnce(new Error('Fake error message'));
|
|
39
|
-
return api.fetch().catch((err) => {
|
|
40
|
-
expect(err.name).toEqual('Error');
|
|
41
|
-
expect(err.message).toEqual('Fake error message');
|
|
42
|
-
done();
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
test('if the response is invalid json', (done) => {
|
|
47
|
-
fetch.mockResponseOnce('invalid json');
|
|
48
|
-
|
|
49
|
-
api.fetch().catch((err) => {
|
|
50
|
-
expect(err.name).toEqual('FetchError');
|
|
51
|
-
expect(err.message).toEqual(
|
|
52
|
-
'invalid json response body at reason: Unexpected token i in JSON at position 0',
|
|
53
|
-
);
|
|
54
|
-
done();
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
test('if the response contains an error message', (done) => {
|
|
59
|
-
fetch.mockResponseOnce('{"error":"foo2"}');
|
|
60
|
-
api.fetch().catch((err) => {
|
|
61
|
-
expect(err.name).toEqual('Error');
|
|
62
|
-
expect(err.message).toEqual('foo2');
|
|
63
|
-
done();
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
});
|
|
68
|
-
});
|
|
@@ -1,146 +0,0 @@
|
|
|
1
|
-
import BaseObject from 'ol/Object';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* A class representing a control to display on map.
|
|
5
|
-
*
|
|
6
|
-
* @example
|
|
7
|
-
* const control = new Control();
|
|
8
|
-
*
|
|
9
|
-
* @classproperty {ol/Map~Map|mapboxgl.Map} map - The map which the control refers to.
|
|
10
|
-
* @classproperty {boolean} active - Active the control.
|
|
11
|
-
* @classproperty {HTMLElement} element - The HTML element used to render the control.
|
|
12
|
-
* @classproperty {HTMLElement} target - The HTML element where to render the element property. Default is the map's element. Read only.
|
|
13
|
-
*/
|
|
14
|
-
class Control extends BaseObject {
|
|
15
|
-
/**
|
|
16
|
-
* Constructor
|
|
17
|
-
*
|
|
18
|
-
* @param {Object} [options] Control options.
|
|
19
|
-
* @param {boolean} [options.active = true] Whether the control is active or not.
|
|
20
|
-
* @param {HTMLElement} [options.element] The HTML element used to render the control.
|
|
21
|
-
* @param {HTMLElement} [options.target] The HTML element where to render the element property. Default is the map's element.
|
|
22
|
-
* @param {function} [options.render] Render function called whenever the control needs to be rerendered.
|
|
23
|
-
*/
|
|
24
|
-
constructor(options = {}) {
|
|
25
|
-
super(options);
|
|
26
|
-
this.defineProperties(options);
|
|
27
|
-
|
|
28
|
-
const { active } = {
|
|
29
|
-
active: options.active !== false,
|
|
30
|
-
...options,
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* @ignore
|
|
35
|
-
*/
|
|
36
|
-
this.active = active;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Define control's properties.
|
|
41
|
-
*
|
|
42
|
-
* @private
|
|
43
|
-
*/
|
|
44
|
-
defineProperties(options) {
|
|
45
|
-
const { target, element, render } = {
|
|
46
|
-
...options,
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
Object.defineProperties(this, {
|
|
50
|
-
active: {
|
|
51
|
-
get: () => this.get('active'),
|
|
52
|
-
set: (newActive) => {
|
|
53
|
-
this.set('active', newActive);
|
|
54
|
-
if (newActive) {
|
|
55
|
-
this.activate();
|
|
56
|
-
} else {
|
|
57
|
-
this.deactivate();
|
|
58
|
-
}
|
|
59
|
-
this.render();
|
|
60
|
-
},
|
|
61
|
-
},
|
|
62
|
-
map: {
|
|
63
|
-
get: () => this.get('map'),
|
|
64
|
-
set: (map) => {
|
|
65
|
-
// Remove previous node.
|
|
66
|
-
if (this.map && this.element && this.element.parentNode) {
|
|
67
|
-
this.element.parentNode.removeChild(this.element);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// Clean listeners
|
|
71
|
-
this.deactivate();
|
|
72
|
-
|
|
73
|
-
this.set('map', map);
|
|
74
|
-
|
|
75
|
-
if (this.map) {
|
|
76
|
-
// Add new node
|
|
77
|
-
const targett =
|
|
78
|
-
this.target ||
|
|
79
|
-
(this.map.getTargetElement && this.map.getTargetElement()) ||
|
|
80
|
-
(this.map.getContainer && this.map.getContainer());
|
|
81
|
-
|
|
82
|
-
if (!this.element) {
|
|
83
|
-
this.createDefaultElement();
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
if (this.element) {
|
|
87
|
-
targett.appendChild(this.element);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// Add listeners
|
|
91
|
-
if (this.active) {
|
|
92
|
-
this.activate();
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
this.render();
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
target: {
|
|
99
|
-
value: target,
|
|
100
|
-
},
|
|
101
|
-
element: {
|
|
102
|
-
value: element,
|
|
103
|
-
writable: true,
|
|
104
|
-
},
|
|
105
|
-
render: {
|
|
106
|
-
/** @ignore */
|
|
107
|
-
value: render || this.render,
|
|
108
|
-
writable: true,
|
|
109
|
-
},
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* Add listeners then renders the control.
|
|
115
|
-
* To be defined in inherited classes.
|
|
116
|
-
*/
|
|
117
|
-
activate() {
|
|
118
|
-
this.deactivate();
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Remove listeners added by activate() function then renders the control.
|
|
123
|
-
* To be defined in inherited classes.
|
|
124
|
-
*/
|
|
125
|
-
// eslint-disable-next-line class-methods-use-this
|
|
126
|
-
deactivate() {}
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* The default render function. It renders content in the HTML element.
|
|
130
|
-
* To be defined in inherited classes.
|
|
131
|
-
*
|
|
132
|
-
* @private
|
|
133
|
-
*/
|
|
134
|
-
render() {}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* The default element to display if this.element is not defined.
|
|
138
|
-
* To be defined in inherited classes.
|
|
139
|
-
*
|
|
140
|
-
* @private
|
|
141
|
-
*/
|
|
142
|
-
// eslint-disable-next-line class-methods-use-this
|
|
143
|
-
createDefaultElement() {}
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
export default Control;
|