mobility-toolbox-js 2.0.0-beta.34 → 2.0.0-beta.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -8
- package/api/RealtimeAPI.d.ts +6 -6
- package/api/RealtimeAPI.d.ts.map +1 -1
- package/api/RealtimeAPI.js +170 -197
- package/api/RealtimeAPI.test.d.ts +2 -0
- package/api/RealtimeAPI.test.d.ts.map +1 -0
- package/api/RealtimeAPI.test.js +67 -0
- package/api/RoutingAPI.d.ts +6 -2
- package/api/RoutingAPI.d.ts.map +1 -1
- package/api/RoutingAPI.js +8 -38
- package/api/RoutingAPI.test.d.ts +2 -0
- package/api/RoutingAPI.test.d.ts.map +1 -0
- package/api/RoutingAPI.test.js +29 -0
- package/api/StopsAPI.d.ts +1 -1
- package/api/StopsAPI.d.ts.map +1 -1
- package/api/StopsAPI.js +8 -40
- package/api/StopsAPI.test.d.ts +2 -0
- package/api/StopsAPI.test.d.ts.map +1 -0
- package/api/StopsAPI.test.js +26 -0
- package/api/index.d.ts +3 -4
- package/api/index.d.ts.map +1 -1
- package/api/index.js +3 -10
- package/api/typedefs.js +1 -0
- package/common/api/HttpAPI.d.ts +2 -2
- package/common/api/HttpAPI.d.ts.map +1 -1
- package/common/api/HttpAPI.js +21 -48
- package/common/api/HttpAPI.test.d.ts +2 -0
- package/common/api/HttpAPI.test.d.ts.map +1 -0
- package/common/api/HttpAPI.test.js +54 -0
- package/common/api/WebSocketAPI.d.ts +8 -4
- package/common/api/WebSocketAPI.d.ts.map +1 -1
- package/common/api/WebSocketAPI.js +125 -129
- package/common/api/WebSocketAPI.test.d.ts +2 -0
- package/common/api/WebSocketAPI.test.d.ts.map +1 -0
- package/common/api/WebSocketAPI.test.js +380 -0
- package/common/controls/Control.d.ts +5 -5
- package/common/controls/Control.d.ts.map +1 -1
- package/common/controls/Control.js +44 -77
- package/common/controls/Control.test.d.ts +2 -0
- package/common/controls/Control.test.d.ts.map +1 -0
- package/common/controls/Control.test.js +89 -0
- package/common/index.js +2 -18
- package/common/layers/Layer.d.ts +11 -11
- package/common/layers/Layer.d.ts.map +1 -1
- package/common/layers/Layer.js +70 -104
- package/common/layers/Layer.test.d.ts +2 -0
- package/common/layers/Layer.test.d.ts.map +1 -0
- package/common/layers/Layer.test.js +137 -0
- package/common/mixins/CopyrightMixin.js +23 -52
- package/common/mixins/MapboxLayerMixin.js +162 -204
- package/common/mixins/RealtimeLayerMixin.js +580 -635
- package/common/mixins/StopFinderMixin.d.ts +3 -3
- package/common/mixins/StopFinderMixin.d.ts.map +1 -1
- package/common/mixins/StopFinderMixin.js +115 -157
- package/common/mixins/UserInteractionsLayerMixin.js +142 -175
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts +2 -0
- package/common/mixins/UserInteractionsLayerMixin.test.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.test.js +214 -0
- package/common/styles/index.js +4 -24
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -1
- package/common/styles/realtimeDefaultStyle.js +67 -78
- package/common/styles/realtimeDelayStyle.js +4 -17
- package/common/styles/realtimeSimpleStyle.js +5 -7
- package/common/typedefs.js +1 -0
- package/common/utils/cleanStopTime.js +3 -5
- package/common/utils/compareDepartures.d.ts +1 -1
- package/common/utils/compareDepartures.d.ts.map +1 -1
- package/common/utils/compareDepartures.js +8 -11
- package/common/utils/createCanvas.js +3 -5
- package/common/utils/createTrackerFilters.d.ts +1 -1
- package/common/utils/createTrackerFilters.d.ts.map +1 -1
- package/common/utils/createTrackerFilters.js +22 -32
- package/common/utils/createTrackerFilters.test.d.ts +2 -0
- package/common/utils/createTrackerFilters.test.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.test.js +79 -0
- package/common/utils/getLayersAsFlatArray.js +6 -8
- package/common/utils/getMapboxMapCopyrights.js +9 -11
- package/common/utils/getMapboxMapCopyrights.test.d.ts +2 -0
- package/common/utils/getMapboxMapCopyrights.test.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.test.js +40 -0
- package/common/utils/getMapboxRender.js +12 -15
- package/common/utils/getMaplibreRender.js +10 -13
- package/common/utils/getRealtimeModeSuffix.js +2 -6
- package/common/utils/getUrlWithParams.js +5 -8
- package/common/utils/getVehiclePosition.js +20 -23
- package/common/utils/index.js +12 -37
- package/common/utils/removeDuplicate.d.ts +1 -1
- package/common/utils/removeDuplicate.d.ts.map +1 -1
- package/common/utils/removeDuplicate.js +6 -21
- package/common/utils/removeDuplicate.test.d.ts +2 -0
- package/common/utils/removeDuplicate.test.d.ts.map +1 -0
- package/common/utils/removeDuplicate.test.js +19 -0
- package/common/utils/renderTrajectories.js +31 -43
- package/common/utils/sortByDelay.js +4 -6
- package/common/utils/timeUtils.js +14 -24
- package/common/utils/timeUtils.test.d.ts +2 -0
- package/common/utils/timeUtils.test.d.ts.map +1 -0
- package/common/utils/timeUtils.test.js +10 -0
- package/common/utils/trackerConfig.js +27 -39
- package/common/utils/trackerConfig.test.d.ts +2 -0
- package/common/utils/trackerConfig.test.d.ts.map +1 -0
- package/common/utils/trackerConfig.test.js +23 -0
- package/iife.js +3 -5
- package/index.d.ts +4 -0
- package/index.js +9 -10
- package/mapbox/controls/CopyrightControl.d.ts +0 -1
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -1
- package/mapbox/controls/CopyrightControl.js +18 -38
- package/mapbox/controls/index.js +1 -5
- package/mapbox/index.js +4 -20
- package/mapbox/layers/Layer.d.ts +1 -1
- package/mapbox/layers/Layer.d.ts.map +1 -1
- package/mapbox/layers/Layer.js +29 -71
- package/mapbox/layers/Layer.test.d.ts +2 -0
- package/mapbox/layers/Layer.test.d.ts.map +1 -0
- package/mapbox/layers/Layer.test.js +204 -0
- package/mapbox/layers/RealtimeLayer.d.ts +4 -4
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -1
- package/mapbox/layers/RealtimeLayer.js +83 -125
- package/mapbox/layers/RealtimeLayer.test.d.ts +2 -0
- package/mapbox/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.test.js +10 -0
- package/mapbox/layers/index.js +2 -7
- package/mapbox/utils.js +19 -33
- package/mbt.js +59 -37
- package/mbt.js.map +2 -2
- package/mbt.min.js +10 -10
- package/mbt.min.js.map +2 -2
- package/ol/controls/CopyrightControl.js +26 -47
- package/ol/controls/CopyrightControl.test.d.ts +2 -0
- package/ol/controls/CopyrightControl.test.d.ts.map +1 -0
- package/ol/controls/CopyrightControl.test.js +177 -0
- package/ol/controls/RoutingControl.d.ts +6 -5
- package/ol/controls/RoutingControl.d.ts.map +1 -1
- package/ol/controls/RoutingControl.js +209 -270
- package/ol/controls/RoutingControl.test.d.ts +2 -0
- package/ol/controls/RoutingControl.test.d.ts.map +1 -0
- package/ol/controls/RoutingControl.test.js +150 -0
- package/ol/controls/StopFinderControl.js +9 -32
- package/ol/controls/StopFinderControl.test.d.ts +2 -0
- package/ol/controls/StopFinderControl.test.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.test.js +49 -0
- package/ol/controls/index.js +3 -9
- package/ol/index.js +5 -21
- package/ol/layers/Layer.d.ts +1 -1
- package/ol/layers/Layer.d.ts.map +1 -1
- package/ol/layers/Layer.js +40 -72
- package/ol/layers/Layer.test.d.ts +2 -0
- package/ol/layers/Layer.test.d.ts.map +1 -0
- package/ol/layers/Layer.test.js +196 -0
- package/ol/layers/MapboxLayer.d.ts +7 -7
- package/ol/layers/MapboxLayer.d.ts.map +1 -1
- package/ol/layers/MapboxLayer.js +30 -66
- package/ol/layers/MapboxLayer.test.d.ts +2 -0
- package/ol/layers/MapboxLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.test.js +164 -0
- package/ol/layers/MapboxStyleLayer.d.ts +3 -3
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -1
- package/ol/layers/MapboxStyleLayer.js +92 -135
- package/ol/layers/MapboxStyleLayer.test.d.ts +2 -0
- package/ol/layers/MapboxStyleLayer.test.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.test.js +232 -0
- package/ol/layers/MaplibreLayer.d.ts +1 -1
- package/ol/layers/MaplibreLayer.d.ts.map +1 -1
- package/ol/layers/MaplibreLayer.js +14 -48
- package/ol/layers/RealtimeLayer.d.ts +2 -2
- package/ol/layers/RealtimeLayer.d.ts.map +1 -1
- package/ol/layers/RealtimeLayer.js +111 -147
- package/ol/layers/RealtimeLayer.test.d.ts +2 -0
- package/ol/layers/RealtimeLayer.test.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.test.js +71 -0
- package/ol/layers/RoutingLayer.d.ts +2 -2
- package/ol/layers/RoutingLayer.d.ts.map +1 -1
- package/ol/layers/RoutingLayer.js +29 -61
- package/ol/layers/RoutingLayer.test.d.ts +2 -0
- package/ol/layers/RoutingLayer.test.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.test.js +39 -0
- package/ol/layers/VectorLayer.d.ts +1 -1
- package/ol/layers/VectorLayer.d.ts.map +1 -1
- package/ol/layers/VectorLayer.js +14 -48
- package/ol/layers/VectorLayer.test.d.ts +2 -0
- package/ol/layers/VectorLayer.test.d.ts.map +1 -0
- package/ol/layers/VectorLayer.test.js +87 -0
- package/ol/layers/WMSLayer.d.ts +1 -1
- package/ol/layers/WMSLayer.d.ts.map +1 -1
- package/ol/layers/WMSLayer.js +34 -68
- package/ol/layers/WMSLayer.test.d.ts +2 -0
- package/ol/layers/WMSLayer.test.d.ts.map +1 -0
- package/ol/layers/WMSLayer.test.js +66 -0
- package/ol/layers/index.js +8 -19
- package/ol/styles/fullTrajectoryDelayStyle.js +11 -13
- package/ol/styles/fullTrajectoryStyle.js +16 -18
- package/ol/styles/index.js +2 -7
- package/package.json +5 -2
- package/setupTests.js +12 -14
|
@@ -1,17 +1,6 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
1
|
/* eslint-disable no-param-reassign */
|
|
13
|
-
|
|
14
|
-
|
|
2
|
+
import { compose, apply, create } from 'ol/transform';
|
|
3
|
+
import getVehiclePosition from './getVehiclePosition';
|
|
15
4
|
/**
|
|
16
5
|
* Draw all the trajectories available in a canvas.
|
|
17
6
|
* @param {HTMLCanvas|HTMLOffscreenCanvas} The canvas where to draw the trajectories.
|
|
@@ -25,41 +14,40 @@ var getVehiclePosition_1 = require("./getVehiclePosition");
|
|
|
25
14
|
* during map navigation.
|
|
26
15
|
* @private
|
|
27
16
|
*/
|
|
28
|
-
|
|
29
|
-
var _a;
|
|
17
|
+
const renderTrajectories = (canvas, trajectories, style, viewState, options) => {
|
|
30
18
|
if (!canvas) {
|
|
31
19
|
return {};
|
|
32
20
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
const { time = Date.now(), size = [], center, resolution, rotation = 0, pixelRatio, } = viewState;
|
|
22
|
+
const { noInterpolate = false, hoverVehicleId, selectedVehicleId } = options;
|
|
23
|
+
const context = canvas.getContext('2d');
|
|
36
24
|
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
37
|
-
|
|
25
|
+
const [width, height] = size;
|
|
38
26
|
if (width && height && (canvas.width !== width || canvas.height !== height)) {
|
|
39
|
-
|
|
27
|
+
[canvas.width, canvas.height] = [width * pixelRatio, height * pixelRatio];
|
|
40
28
|
}
|
|
41
|
-
|
|
29
|
+
const coordinateToPixelTransform = compose(create(), size[0] / 2, size[1] / 2, 1 / resolution, -1 / resolution, -rotation, -center[0], -center[1]);
|
|
42
30
|
// Offscreen canvas has not style attribute
|
|
43
31
|
if (canvas.style) {
|
|
44
|
-
canvas.style.width =
|
|
45
|
-
canvas.style.height =
|
|
32
|
+
canvas.style.width = `${canvas.width / pixelRatio}px`;
|
|
33
|
+
canvas.style.height = `${canvas.height / pixelRatio}px`;
|
|
46
34
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (
|
|
57
|
-
|
|
35
|
+
let hoverVehicleImg;
|
|
36
|
+
let hoverVehiclePx;
|
|
37
|
+
let hoverVehicleWidth;
|
|
38
|
+
let hoverVehicleHeight;
|
|
39
|
+
let selectedVehicleImg;
|
|
40
|
+
let selectedVehiclePx;
|
|
41
|
+
let selectedVehicleWidth;
|
|
42
|
+
let selectedVehicleHeight;
|
|
43
|
+
const renderedTrajectories = [];
|
|
44
|
+
for (let i = trajectories.length - 1; i >= 0; i -= 1) {
|
|
45
|
+
const trajectory = trajectories[i];
|
|
58
46
|
// We simplify the trajectory object
|
|
59
|
-
|
|
47
|
+
const { train_id: id, timeOffset } = trajectory.properties;
|
|
60
48
|
// We set the rotation and the timeFraction of the trajectory (used by tralis).
|
|
61
49
|
// if rotation === null that seems there is no rotation available.
|
|
62
|
-
|
|
50
|
+
const { coord, rotation: rotationIcon } = getVehiclePosition(time - (timeOffset || 0), trajectory, noInterpolate);
|
|
63
51
|
// We store the current vehicle position to the trajectory.
|
|
64
52
|
trajectories[i].properties.coordinate = coord;
|
|
65
53
|
trajectories[i].properties.rotation = rotationIcon;
|
|
@@ -67,12 +55,12 @@ var renderTrajectories = function (canvas, trajectories, style, viewState, optio
|
|
|
67
55
|
// eslint-disable-next-line no-continue
|
|
68
56
|
continue;
|
|
69
57
|
}
|
|
70
|
-
|
|
58
|
+
let px = apply(coordinateToPixelTransform, [...coord]);
|
|
71
59
|
if (!px) {
|
|
72
60
|
// eslint-disable-next-line no-continue
|
|
73
61
|
continue;
|
|
74
62
|
}
|
|
75
|
-
px = px.map(
|
|
63
|
+
px = px.map((p) => p * pixelRatio);
|
|
76
64
|
if (px[0] < 0 ||
|
|
77
65
|
px[0] > canvas.width ||
|
|
78
66
|
px[1] < 0 ||
|
|
@@ -80,13 +68,13 @@ var renderTrajectories = function (canvas, trajectories, style, viewState, optio
|
|
|
80
68
|
// eslint-disable-next-line no-continue
|
|
81
69
|
continue;
|
|
82
70
|
}
|
|
83
|
-
|
|
71
|
+
const vehicleImg = style(trajectory, viewState, options);
|
|
84
72
|
if (!vehicleImg) {
|
|
85
73
|
// eslint-disable-next-line no-continue
|
|
86
74
|
continue;
|
|
87
75
|
}
|
|
88
|
-
|
|
89
|
-
|
|
76
|
+
const imgWidth = vehicleImg.width;
|
|
77
|
+
const imgHeight = vehicleImg.height;
|
|
90
78
|
if (hoverVehicleId !== id && selectedVehicleId !== id) {
|
|
91
79
|
context.drawImage(vehicleImg, px[0] - imgWidth / 2, px[1] - imgHeight / 2, imgWidth, imgHeight);
|
|
92
80
|
}
|
|
@@ -113,7 +101,7 @@ var renderTrajectories = function (canvas, trajectories, style, viewState, optio
|
|
|
113
101
|
context.drawImage(hoverVehicleImg, hoverVehiclePx[0] - hoverVehicleWidth / 2, hoverVehiclePx[1] - hoverVehicleHeight / 2, hoverVehicleWidth, hoverVehicleHeight);
|
|
114
102
|
}
|
|
115
103
|
return {
|
|
116
|
-
renderedTrajectories
|
|
104
|
+
renderedTrajectories,
|
|
117
105
|
};
|
|
118
106
|
};
|
|
119
|
-
|
|
107
|
+
export default renderTrajectories;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var props1 = traj1.properties;
|
|
5
|
-
var props2 = traj2.properties;
|
|
1
|
+
const sortByDelay = (traj1, traj2) => {
|
|
2
|
+
const props1 = traj1.properties;
|
|
3
|
+
const props2 = traj2.properties;
|
|
6
4
|
if (props1.delay === null && props2.delay !== null) {
|
|
7
5
|
return 1;
|
|
8
6
|
}
|
|
@@ -19,4 +17,4 @@ var sortByDelay = function (traj1, traj2) {
|
|
|
19
17
|
}
|
|
20
18
|
return props2.delay - props1.delay;
|
|
21
19
|
};
|
|
22
|
-
|
|
20
|
+
export default sortByDelay;
|
|
@@ -1,49 +1,39 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getHoursAndMinutes = exports.pad = exports.getUTCTimeString = exports.getUTCDateString = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Get a Date object as UTC date string .
|
|
6
3
|
* ex: 2019 09 01
|
|
7
4
|
* @ignore
|
|
8
5
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
day = day.length === 1 ? "0".concat(day) : day;
|
|
6
|
+
export const getUTCDateString = (now = new Date()) => {
|
|
7
|
+
let month = (now.getUTCMonth() + 1).toString();
|
|
8
|
+
month = month.length === 1 ? `0${month}` : month;
|
|
9
|
+
let day = now.getUTCDate().toString();
|
|
10
|
+
day = day.length === 1 ? `0${day}` : day;
|
|
15
11
|
return [now.getUTCFullYear(), month, day].join('');
|
|
16
12
|
};
|
|
17
|
-
exports.getUTCDateString = getUTCDateString;
|
|
18
13
|
/**
|
|
19
14
|
* Get the UTC time string of Date object.
|
|
20
15
|
* ex: 09:05:01.123
|
|
21
16
|
* @ignore
|
|
22
17
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
].join(':');
|
|
29
|
-
};
|
|
30
|
-
exports.getUTCTimeString = getUTCTimeString;
|
|
18
|
+
export const getUTCTimeString = (date) => [
|
|
19
|
+
date.getUTCHours(),
|
|
20
|
+
date.getUTCMinutes(),
|
|
21
|
+
`${date.getUTCSeconds()}.${date.getUTCMilliseconds()}`,
|
|
22
|
+
].join(':');
|
|
31
23
|
/**
|
|
32
24
|
* Returns a string representation of a number, with a zero if the number is lower than 10.
|
|
33
25
|
* @ignore
|
|
34
26
|
*/
|
|
35
|
-
|
|
36
|
-
exports.pad = pad;
|
|
27
|
+
export const pad = (integer) => (integer < 10 ? `0${integer}` : integer);
|
|
37
28
|
/**
|
|
38
29
|
* Returns a 'hh:mm' string from a time in ms.
|
|
39
30
|
* @param {Number} timeInMs Time in milliseconds.
|
|
40
31
|
* @ignore
|
|
41
32
|
*/
|
|
42
|
-
|
|
33
|
+
export const getHoursAndMinutes = (timeInMs) => {
|
|
43
34
|
if (!timeInMs || timeInMs <= 0) {
|
|
44
35
|
return '';
|
|
45
36
|
}
|
|
46
|
-
|
|
47
|
-
return
|
|
37
|
+
const date = new Date(timeInMs);
|
|
38
|
+
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
48
39
|
};
|
|
49
|
-
exports.getHoursAndMinutes = getHoursAndMinutes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeUtils.test.d.ts","sourceRoot":"","sources":["../../../src/common/utils/timeUtils.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { getUTCDateString, getUTCTimeString } from './timeUtils';
|
|
2
|
+
describe('timeUtils', () => {
|
|
3
|
+
test('getUTCDateString should be correct.', () => {
|
|
4
|
+
expect(getUTCDateString(new Date(2020, 5, 30))).toBe('20200630');
|
|
5
|
+
expect(getUTCDateString(new Date('January 1, 2021 00:15:30 GMT+2:00'))).toBe('20201231');
|
|
6
|
+
});
|
|
7
|
+
test('getUTCTimeString should be correct.', () => {
|
|
8
|
+
expect(getUTCTimeString(new Date(2020, 5, 30, 11, 5, 1, 123))).toBe('11:5:1.123');
|
|
9
|
+
});
|
|
10
|
+
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDelayText = exports.getDelayColor = exports.getTextSize = exports.getTextColor = exports.getBgColor = exports.getRadius = exports.getTypeIndex = exports.textColors = exports.bgColors = exports.types = void 0;
|
|
4
|
-
var trackerRadiusMapping = {
|
|
1
|
+
const trackerRadiusMapping = {
|
|
5
2
|
0: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
6
3
|
1: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
7
4
|
2: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15],
|
|
@@ -20,7 +17,7 @@ var trackerRadiusMapping = {
|
|
|
20
17
|
*
|
|
21
18
|
* @ignore
|
|
22
19
|
*/
|
|
23
|
-
|
|
20
|
+
export const types = [
|
|
24
21
|
/^Tram/i,
|
|
25
22
|
/^Subway( \/ Metro \/ S-Bahn)?/i,
|
|
26
23
|
/^Train/i,
|
|
@@ -35,7 +32,7 @@ exports.types = [
|
|
|
35
32
|
/**
|
|
36
33
|
* @ignore
|
|
37
34
|
*/
|
|
38
|
-
|
|
35
|
+
export const bgColors = [
|
|
39
36
|
'#ffb400',
|
|
40
37
|
'#ff5400',
|
|
41
38
|
'#ff8080',
|
|
@@ -50,7 +47,7 @@ exports.bgColors = [
|
|
|
50
47
|
/**
|
|
51
48
|
* @ignore
|
|
52
49
|
*/
|
|
53
|
-
|
|
50
|
+
export const textColors = [
|
|
54
51
|
'#000000',
|
|
55
52
|
'#ffffff',
|
|
56
53
|
'#000000',
|
|
@@ -65,79 +62,72 @@ exports.textColors = [
|
|
|
65
62
|
/**
|
|
66
63
|
* @ignore
|
|
67
64
|
*/
|
|
68
|
-
|
|
65
|
+
export const getTypeIndex = (type) => {
|
|
69
66
|
if (typeof type === 'string') {
|
|
70
|
-
return
|
|
67
|
+
return types.findIndex((t) => t.test(type));
|
|
71
68
|
}
|
|
72
69
|
return type;
|
|
73
70
|
};
|
|
74
|
-
exports.getTypeIndex = getTypeIndex;
|
|
75
71
|
/**
|
|
76
72
|
* @ignore
|
|
77
73
|
*/
|
|
78
|
-
|
|
74
|
+
export const getRadius = (type, zoom) => {
|
|
79
75
|
try {
|
|
80
|
-
|
|
76
|
+
const typeIdx = getTypeIndex(type || 0);
|
|
81
77
|
return trackerRadiusMapping[typeIdx][zoom];
|
|
82
78
|
}
|
|
83
79
|
catch (e) {
|
|
84
80
|
return 1;
|
|
85
81
|
}
|
|
86
82
|
};
|
|
87
|
-
exports.getRadius = getRadius;
|
|
88
83
|
/**
|
|
89
84
|
* @ignore
|
|
90
85
|
*/
|
|
91
|
-
|
|
92
|
-
if (type === void 0) { type = 0; }
|
|
86
|
+
export const getBgColor = (type = 0) => {
|
|
93
87
|
try {
|
|
94
|
-
|
|
95
|
-
return
|
|
88
|
+
const typeIdx = getTypeIndex(type);
|
|
89
|
+
return bgColors[typeIdx];
|
|
96
90
|
}
|
|
97
91
|
catch (e) {
|
|
98
92
|
return 1;
|
|
99
93
|
}
|
|
100
94
|
};
|
|
101
|
-
exports.getBgColor = getBgColor;
|
|
102
95
|
/**
|
|
103
96
|
* @ignore
|
|
104
97
|
*/
|
|
105
|
-
|
|
106
|
-
if (type === void 0) { type = 0; }
|
|
98
|
+
export const getTextColor = (type = 0) => {
|
|
107
99
|
try {
|
|
108
|
-
|
|
109
|
-
return
|
|
100
|
+
const typeIdx = getTypeIndex(type);
|
|
101
|
+
return textColors[typeIdx];
|
|
110
102
|
}
|
|
111
103
|
catch (e) {
|
|
112
104
|
return 1;
|
|
113
105
|
}
|
|
114
106
|
};
|
|
115
|
-
exports.getTextColor = getTextColor;
|
|
116
107
|
/**
|
|
117
108
|
* @ignore
|
|
118
109
|
*/
|
|
119
|
-
|
|
120
|
-
ctx.font =
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
110
|
+
export const getTextSize = (ctx, markerSize, text, fontSize) => {
|
|
111
|
+
ctx.font = `bold ${fontSize}px Arial`;
|
|
112
|
+
let newText = ctx.measureText(text);
|
|
113
|
+
const maxiter = 25;
|
|
114
|
+
let i = 0;
|
|
124
115
|
while (newText.width > markerSize - 6 && i < maxiter) {
|
|
125
116
|
// eslint-disable-next-line no-param-reassign
|
|
126
117
|
fontSize -= 0.5;
|
|
127
|
-
ctx.font =
|
|
118
|
+
ctx.font = `bold ${fontSize}px arial, sans-serif`;
|
|
128
119
|
newText = ctx.measureText(text);
|
|
129
120
|
i += 1;
|
|
130
121
|
}
|
|
131
122
|
return fontSize;
|
|
132
123
|
};
|
|
133
|
-
exports.getTextSize = getTextSize;
|
|
134
124
|
/**
|
|
135
125
|
* @ignore
|
|
136
126
|
* @param {number} delayInMs Delay in milliseconds.
|
|
137
127
|
* @param {boolean} cancelled true if the journey is cancelled.
|
|
138
128
|
* @param {boolean} isDelayText true if the color is used for delay text of the symbol.
|
|
139
129
|
*/
|
|
140
|
-
|
|
130
|
+
export const getDelayColor = (delayInMs, cancelled, isDelayText) => {
|
|
141
131
|
if (cancelled) {
|
|
142
132
|
return isDelayText ? '#ff0000' : '#a0a0a0'; // red or gray
|
|
143
133
|
}
|
|
@@ -158,25 +148,23 @@ var getDelayColor = function (delayInMs, cancelled, isDelayText) {
|
|
|
158
148
|
}
|
|
159
149
|
return '#00a00c'; // green { r: 0, g: 160, b: 12, s: '0,160,12' };
|
|
160
150
|
};
|
|
161
|
-
exports.getDelayColor = getDelayColor;
|
|
162
151
|
/**
|
|
163
152
|
* @ignore
|
|
164
153
|
*/
|
|
165
|
-
|
|
154
|
+
export const getDelayText = (delayInMs, cancelled) => {
|
|
166
155
|
if (cancelled) {
|
|
167
156
|
return String.fromCodePoint(0x00d7);
|
|
168
157
|
}
|
|
169
158
|
if (delayInMs > 3600000) {
|
|
170
|
-
|
|
171
|
-
return
|
|
159
|
+
const rounded = Math.round(delayInMs / 3600000);
|
|
160
|
+
return `+${rounded}h`;
|
|
172
161
|
}
|
|
173
162
|
if (delayInMs > 59000) {
|
|
174
|
-
|
|
175
|
-
return
|
|
163
|
+
const rounded = Math.round(delayInMs / 60000);
|
|
164
|
+
return `+${rounded}m`;
|
|
176
165
|
}
|
|
177
166
|
if (delayInMs > 0) {
|
|
178
|
-
return
|
|
167
|
+
return `+${delayInMs}s`;
|
|
179
168
|
}
|
|
180
169
|
return '';
|
|
181
170
|
};
|
|
182
|
-
exports.getDelayText = getDelayText;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"trackerConfig.test.d.ts","sourceRoot":"","sources":["../../../src/common/utils/trackerConfig.test.js"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { getTypeIndex } from './trackerConfig';
|
|
2
|
+
describe('trackerConfig', () => {
|
|
3
|
+
describe('#getTypeIndex()', () => {
|
|
4
|
+
test("retrurn the type is it's not a string", () => {
|
|
5
|
+
const obj = { foo: 'foo' };
|
|
6
|
+
expect(getTypeIndex(obj)).toBe(obj);
|
|
7
|
+
expect(getTypeIndex(0)).toBe(0);
|
|
8
|
+
expect(getTypeIndex(null)).toBe(null);
|
|
9
|
+
expect(getTypeIndex(undefined)).toBe(undefined);
|
|
10
|
+
});
|
|
11
|
+
test('find good index for new tracker values', () => {
|
|
12
|
+
expect(getTypeIndex('tram')).toBe(0);
|
|
13
|
+
expect(getTypeIndex('subway')).toBe(1);
|
|
14
|
+
expect(getTypeIndex('bus')).toBe(3);
|
|
15
|
+
expect(getTypeIndex('ferry')).toBe(4);
|
|
16
|
+
expect(getTypeIndex('cablecar')).toBe(5);
|
|
17
|
+
expect(getTypeIndex('gondola')).toBe(6);
|
|
18
|
+
expect(getTypeIndex('funicular')).toBe(7);
|
|
19
|
+
expect(getTypeIndex('coach')).toBe(8);
|
|
20
|
+
expect(getTypeIndex('rail')).toBe(9);
|
|
21
|
+
});
|
|
22
|
+
});
|
|
23
|
+
});
|
package/iife.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
var index_1 = require("./index");
|
|
1
|
+
import mbt from './index';
|
|
4
2
|
if (typeof window !== 'undefined') {
|
|
5
|
-
window.mbt =
|
|
3
|
+
window.mbt = mbt;
|
|
6
4
|
}
|
|
7
|
-
|
|
5
|
+
export default mbt;
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
export * as ol from "./ol";
|
|
2
|
+
export * as mapbox from "./mapbox";
|
|
1
3
|
declare namespace _default {
|
|
2
4
|
export { ol };
|
|
3
5
|
export { mapbox };
|
|
4
6
|
}
|
|
5
7
|
export default _default;
|
|
8
|
+
import * as ol from "./ol";
|
|
9
|
+
import * as mapbox from "./mapbox";
|
|
6
10
|
//# sourceMappingURL=index.d.ts.map
|
package/index.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
mapbox: mapbox,
|
|
1
|
+
import * as ol from './ol';
|
|
2
|
+
import * as mapbox from './mapbox';
|
|
3
|
+
import * as ol_1 from './ol';
|
|
4
|
+
export { ol_1 as ol };
|
|
5
|
+
import * as mapbox_1 from './mapbox';
|
|
6
|
+
export { mapbox_1 as mapbox };
|
|
7
|
+
export default {
|
|
8
|
+
ol,
|
|
9
|
+
mapbox,
|
|
11
10
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CopyrightControl.d.ts","sourceRoot":"","sources":["../../../src/mapbox/controls/CopyrightControl.js"],"names":[],"mappings":";AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,0DAFgB,kBAAkB;IAGhC,0BAGC;
|
|
1
|
+
{"version":3,"file":"CopyrightControl.d.ts","sourceRoot":"","sources":["../../../src/mapbox/controls/CopyrightControl.js"],"names":[],"mappings":";AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,0DAFgB,kBAAkB;IAGhC,0BAGC;IAoBD,uBAEC;CACF"}
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
var Control_1 = require("../../common/controls/Control");
|
|
19
|
-
var CopyrightMixin_1 = require("../../common/mixins/CopyrightMixin");
|
|
20
|
-
var utils_1 = require("../../common/utils");
|
|
1
|
+
import Control from '../../common/controls/Control';
|
|
2
|
+
import mixin from '../../common/mixins/CopyrightMixin';
|
|
3
|
+
import { getMapboxMapCopyrights } from '../../common/utils';
|
|
21
4
|
/**
|
|
22
5
|
* Display layer's copyrights.
|
|
23
6
|
*
|
|
@@ -42,32 +25,29 @@ var utils_1 = require("../../common/utils");
|
|
|
42
25
|
* @extends {Control}
|
|
43
26
|
* @implements {CopyrightInterface}
|
|
44
27
|
*/
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
_this.render = _this.render.bind(_this);
|
|
50
|
-
return _this;
|
|
28
|
+
class CopyrightControl extends mixin(Control) {
|
|
29
|
+
constructor(options) {
|
|
30
|
+
super(options);
|
|
31
|
+
this.render = this.render.bind(this);
|
|
51
32
|
}
|
|
52
|
-
|
|
53
|
-
|
|
33
|
+
activate() {
|
|
34
|
+
super.activate();
|
|
54
35
|
if (this.map) {
|
|
55
36
|
this.map.on('sourcedata', this.render);
|
|
56
37
|
this.map.on('styledata', this.render);
|
|
57
38
|
this.map.on('idle', this.render);
|
|
58
39
|
}
|
|
59
|
-
}
|
|
60
|
-
|
|
40
|
+
}
|
|
41
|
+
deactivate() {
|
|
61
42
|
if (this.map) {
|
|
62
43
|
this.map.off('sourcedata', this.render);
|
|
63
44
|
this.map.off('styledata', this.render);
|
|
64
45
|
this.map.off('idle', this.render);
|
|
65
46
|
}
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
exports.default = CopyrightControl;
|
|
47
|
+
super.deactivate();
|
|
48
|
+
}
|
|
49
|
+
getCopyrights() {
|
|
50
|
+
return getMapboxMapCopyrights(this.map);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
export default CopyrightControl;
|
package/mapbox/controls/index.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.CopyrightControl = void 0;
|
|
4
1
|
// eslint-disable-next-line import/prefer-default-export
|
|
5
|
-
|
|
6
|
-
Object.defineProperty(exports, "CopyrightControl", { enumerable: true, get: function () { return CopyrightControl_1.default; } });
|
|
2
|
+
export { default as CopyrightControl } from './CopyrightControl';
|
package/mapbox/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("../api"), exports);
|
|
18
|
-
__exportStar(require("../common"), exports);
|
|
19
|
-
__exportStar(require("./controls"), exports);
|
|
20
|
-
__exportStar(require("./layers"), exports);
|
|
1
|
+
export * from '../api';
|
|
2
|
+
export * from '../common';
|
|
3
|
+
export * from './controls';
|
|
4
|
+
export * from './layers';
|
package/mapbox/layers/Layer.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../../src/mapbox/layers/Layer.js"],"names":[],"mappings":";AAKA;;;;;;;;;;;;;;GAcG;AACH;IACE;;;OAGG;IACH,4BAcC;IALG,wBAGC;IAIL,sBAMC;IAED,iCAmBC;IAED,mCAKC;IAED;;;OAGG;IACH,+BAMC;IAED;;OAEG;IACH,gDAOC;IAED;;OAEG;IACH,iBAEC;IAED;;;;OAIG;IACH,
|
|
1
|
+
{"version":3,"file":"Layer.d.ts","sourceRoot":"","sources":["../../../src/mapbox/layers/Layer.js"],"names":[],"mappings":";AAKA;;;;;;;;;;;;;;GAcG;AACH;IACE;;;OAGG;IACH,4BAcC;IALG,wBAGC;IAIL,sBAMC;IAED,iCAmBC;IAED,mCAKC;IAED;;;OAGG;IACH,+BAMC;IAED;;OAEG;IACH,gDAOC;IAED;;OAEG;IACH,iBAEC;IAED;;;;OAIG;IACH,kBAHW,MAAM,GACL,KAAK,CAIhB;CACF"}
|