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,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTextCanvas = exports.getCircleCanvas = exports.getDelayTextCanvas = exports.getDelayBgCanvas = void 0;
|
|
4
|
-
var createCanvas_1 = require("../utils/createCanvas");
|
|
1
|
+
import createCanvas from '../utils/createCanvas';
|
|
5
2
|
/** @private */
|
|
6
|
-
|
|
3
|
+
const cacheDelayBg = {};
|
|
7
4
|
/**
|
|
8
5
|
* Draw circle delay background
|
|
9
6
|
*
|
|
10
7
|
* @private
|
|
11
8
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
export const getDelayBgCanvas = (origin, radius, color) => {
|
|
10
|
+
const key = `${origin}, ${radius}, ${color}`;
|
|
14
11
|
if (!cacheDelayBg[key]) {
|
|
15
|
-
|
|
12
|
+
const canvas = createCanvas(origin * 2, origin * 2);
|
|
16
13
|
if (canvas) {
|
|
17
|
-
|
|
14
|
+
const ctx = canvas.getContext('2d');
|
|
18
15
|
ctx.beginPath();
|
|
19
16
|
ctx.arc(origin, origin, radius, 0, 2 * Math.PI, false);
|
|
20
17
|
ctx.fillStyle = color;
|
|
@@ -25,29 +22,26 @@ var getDelayBgCanvas = function (origin, radius, color) {
|
|
|
25
22
|
}
|
|
26
23
|
return cacheDelayBg[key];
|
|
27
24
|
};
|
|
28
|
-
exports.getDelayBgCanvas = getDelayBgCanvas;
|
|
29
25
|
/** @private */
|
|
30
|
-
|
|
26
|
+
const cacheDelayText = {};
|
|
31
27
|
/**
|
|
32
28
|
* Draw delay text
|
|
33
29
|
*
|
|
34
30
|
* @private
|
|
35
31
|
*/
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
if (pixelRatio === void 0) { pixelRatio = 1; }
|
|
39
|
-
var key = "".concat(width, ", ").concat(text, ", ").concat(font, ", ").concat(delayColor, ", ").concat(delayOutlineColor, ", ").concat(pixelRatio);
|
|
32
|
+
export const getDelayTextCanvas = (width, text, fontSize, font, delayColor, delayOutlineColor = '#000', pixelRatio = 1) => {
|
|
33
|
+
const key = `${width}, ${text}, ${font}, ${delayColor}, ${delayOutlineColor}, ${pixelRatio}`;
|
|
40
34
|
if (!cacheDelayText[key]) {
|
|
41
|
-
|
|
35
|
+
const canvas = createCanvas(width, fontSize + 8 * pixelRatio);
|
|
42
36
|
if (canvas) {
|
|
43
|
-
|
|
37
|
+
const ctx = canvas.getContext('2d');
|
|
44
38
|
ctx.textAlign = 'left';
|
|
45
39
|
ctx.textBaseline = 'middle';
|
|
46
40
|
ctx.font = font;
|
|
47
41
|
ctx.fillStyle = delayColor;
|
|
48
42
|
ctx.strokeStyle = delayOutlineColor;
|
|
49
43
|
ctx.lineWidth = 1.5 * pixelRatio;
|
|
50
|
-
|
|
44
|
+
const delayText = text;
|
|
51
45
|
ctx.strokeText(delayText, 0, fontSize);
|
|
52
46
|
ctx.fillText(delayText, 0, fontSize);
|
|
53
47
|
cacheDelayText[key] = canvas;
|
|
@@ -55,20 +49,19 @@ var getDelayTextCanvas = function (width, text, fontSize, font, delayColor, dela
|
|
|
55
49
|
}
|
|
56
50
|
return cacheDelayText[key];
|
|
57
51
|
};
|
|
58
|
-
exports.getDelayTextCanvas = getDelayTextCanvas;
|
|
59
52
|
/** @private */
|
|
60
|
-
|
|
53
|
+
const cacheCircle = {};
|
|
61
54
|
/**
|
|
62
55
|
* Draw colored circle with black border
|
|
63
56
|
*
|
|
64
57
|
* @private
|
|
65
58
|
*/
|
|
66
|
-
|
|
67
|
-
|
|
59
|
+
export const getCircleCanvas = (origin, radius, color, hasStroke, hasDash, pixelRatio) => {
|
|
60
|
+
const key = `${origin}, ${radius}, ${color}, ${hasStroke}, ${hasDash}, ${pixelRatio}`;
|
|
68
61
|
if (!cacheCircle[key]) {
|
|
69
|
-
|
|
62
|
+
const canvas = createCanvas(origin * 2, origin * 2);
|
|
70
63
|
if (canvas) {
|
|
71
|
-
|
|
64
|
+
const ctx = canvas.getContext('2d');
|
|
72
65
|
ctx.fillStyle = color;
|
|
73
66
|
if (hasStroke) {
|
|
74
67
|
ctx.lineWidth = 1 * pixelRatio;
|
|
@@ -88,26 +81,25 @@ var getCircleCanvas = function (origin, radius, color, hasStroke, hasDash, pixel
|
|
|
88
81
|
}
|
|
89
82
|
return cacheCircle[key];
|
|
90
83
|
};
|
|
91
|
-
exports.getCircleCanvas = getCircleCanvas;
|
|
92
84
|
/** @private */
|
|
93
|
-
|
|
85
|
+
const cacheText = {};
|
|
94
86
|
/**
|
|
95
87
|
* Draw text in the circle
|
|
96
88
|
*
|
|
97
89
|
* @private
|
|
98
90
|
*/
|
|
99
|
-
|
|
100
|
-
|
|
91
|
+
export const getTextCanvas = (text, origin, textSize, fillColor, strokeColor, hasStroke, pixelRatio) => {
|
|
92
|
+
const key = `${text}, ${origin}, ${textSize}, ${fillColor},${strokeColor}, ${hasStroke}, ${pixelRatio}`;
|
|
101
93
|
if (!cacheText[key]) {
|
|
102
|
-
|
|
94
|
+
const canvas = createCanvas(origin * 2, origin * 2);
|
|
103
95
|
if (canvas) {
|
|
104
|
-
|
|
96
|
+
const ctx = canvas.getContext('2d');
|
|
105
97
|
// Draw a stroke to the text only if a provider provides realtime but we don't use it.
|
|
106
98
|
if (hasStroke) {
|
|
107
99
|
ctx.save();
|
|
108
100
|
ctx.textBaseline = 'middle';
|
|
109
101
|
ctx.textAlign = 'center';
|
|
110
|
-
ctx.font =
|
|
102
|
+
ctx.font = `bold ${textSize + 2}px Arial`;
|
|
111
103
|
ctx.strokeStyle = strokeColor;
|
|
112
104
|
ctx.strokeText(text, origin, origin);
|
|
113
105
|
ctx.restore();
|
|
@@ -116,7 +108,7 @@ var getTextCanvas = function (text, origin, textSize, fillColor, strokeColor, ha
|
|
|
116
108
|
ctx.textBaseline = 'middle';
|
|
117
109
|
ctx.textAlign = 'center';
|
|
118
110
|
ctx.fillStyle = fillColor;
|
|
119
|
-
ctx.font =
|
|
111
|
+
ctx.font = `bold ${textSize}px Arial`;
|
|
120
112
|
ctx.strokeStyle = strokeColor;
|
|
121
113
|
ctx.strokeText(text, origin, origin);
|
|
122
114
|
ctx.fillText(text, origin, origin);
|
|
@@ -125,9 +117,8 @@ var getTextCanvas = function (text, origin, textSize, fillColor, strokeColor, ha
|
|
|
125
117
|
}
|
|
126
118
|
return cacheText[key];
|
|
127
119
|
};
|
|
128
|
-
exports.getTextCanvas = getTextCanvas;
|
|
129
120
|
/** @private */
|
|
130
|
-
|
|
121
|
+
const cache = {};
|
|
131
122
|
/**
|
|
132
123
|
* A tracker style that take in account the delay.
|
|
133
124
|
*
|
|
@@ -136,15 +127,13 @@ var cache = {};
|
|
|
136
127
|
* @param {*} options Some options to change the rendering
|
|
137
128
|
* @return a canvas
|
|
138
129
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
// until the backend change is on prod.
|
|
147
|
-
cancelled = cancelled === true || state === 'JOURNEY_CANCELLED';
|
|
130
|
+
const realtimeDefaultStyle = (trajectory, viewState, options) => {
|
|
131
|
+
const { hoverVehicleId, selectedVehicleId, useDelayStyle, delayOutlineColor = '#000', delayDisplay = 300000, getRadius, getBgColor, getDelayColor, getDelayText, getTextColor, getTextSize, } = options;
|
|
132
|
+
const { zoom, pixelRatio } = viewState;
|
|
133
|
+
let { type } = trajectory.properties;
|
|
134
|
+
const { train_id: id, line, delay, state, operator_provides_realtime_journey: operatorProvidesRealtime, } = trajectory.properties;
|
|
135
|
+
let { name, text_color: textColor, color } = line || {};
|
|
136
|
+
const cancelled = state === 'JOURNEY_CANCELLED';
|
|
148
137
|
if (!type) {
|
|
149
138
|
type = 'Rail';
|
|
150
139
|
}
|
|
@@ -155,89 +144,89 @@ var realtimeDefaultStyle = function (trajectory, viewState, options) {
|
|
|
155
144
|
textColor = '#000000';
|
|
156
145
|
}
|
|
157
146
|
if (color && color[0] !== '#') {
|
|
158
|
-
color =
|
|
147
|
+
color = `#${color}`;
|
|
159
148
|
}
|
|
160
149
|
if (textColor[0] !== '#') {
|
|
161
|
-
textColor =
|
|
150
|
+
textColor = `#${textColor}`;
|
|
162
151
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
const z = Math.min(Math.floor(zoom || 1), 16);
|
|
153
|
+
const hover = hoverVehicleId && hoverVehicleId === id;
|
|
154
|
+
const selected = selectedVehicleId && selectedVehicleId === id;
|
|
166
155
|
// Calcul the radius of the circle
|
|
167
|
-
|
|
168
|
-
|
|
156
|
+
let radius = getRadius(type, z) * pixelRatio;
|
|
157
|
+
const isDisplayStrokeAndDelay = radius >= 7 * pixelRatio;
|
|
169
158
|
if (hover || selected) {
|
|
170
159
|
radius = isDisplayStrokeAndDelay
|
|
171
160
|
? radius + 5 * pixelRatio
|
|
172
161
|
: 14 * pixelRatio;
|
|
173
162
|
}
|
|
174
|
-
|
|
163
|
+
const mustDrawText = radius > 10 * pixelRatio;
|
|
175
164
|
// Optimize the cache key, very important in high zoom level
|
|
176
|
-
|
|
165
|
+
let key = `${radius}${hover}${selected}${cancelled}${delay}`;
|
|
177
166
|
if (useDelayStyle) {
|
|
178
|
-
key +=
|
|
167
|
+
key += `${operatorProvidesRealtime}`;
|
|
179
168
|
}
|
|
180
169
|
else {
|
|
181
|
-
key +=
|
|
170
|
+
key += `${type}${color}`;
|
|
182
171
|
}
|
|
183
172
|
if (mustDrawText) {
|
|
184
|
-
key +=
|
|
173
|
+
key += `${name}${textColor}`;
|
|
185
174
|
}
|
|
186
175
|
if (!cache[key]) {
|
|
187
176
|
if (radius === 0) {
|
|
188
177
|
cache[key] = null;
|
|
189
178
|
return null;
|
|
190
179
|
}
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
180
|
+
const margin = 1 * pixelRatio;
|
|
181
|
+
const radiusDelay = radius + 2;
|
|
182
|
+
const markerSize = radius * 2;
|
|
183
|
+
const size = radiusDelay * 2 + margin * 2 + 100 * pixelRatio; // add space for delay information
|
|
184
|
+
const origin = size / 2;
|
|
196
185
|
// Create the canvas
|
|
197
|
-
|
|
186
|
+
const canvas = createCanvas(size, size);
|
|
198
187
|
if (canvas) {
|
|
199
|
-
|
|
188
|
+
const ctx = canvas.getContext('2d');
|
|
200
189
|
if (isDisplayStrokeAndDelay && delay !== null) {
|
|
201
190
|
// Draw circle delay background
|
|
202
|
-
|
|
191
|
+
const delayBg = getDelayBgCanvas(origin, radiusDelay, getDelayColor(delay, cancelled));
|
|
203
192
|
ctx.drawImage(delayBg, 0, 0);
|
|
204
193
|
}
|
|
205
194
|
// Show delay if feature is hovered or if delay is above 5mins.
|
|
206
195
|
if (isDisplayStrokeAndDelay &&
|
|
207
196
|
(hover || delay >= delayDisplay || cancelled)) {
|
|
208
197
|
// Draw delay text
|
|
209
|
-
|
|
210
|
-
|
|
198
|
+
const fontSize = Math.max(cancelled ? 19 : 14, Math.min(cancelled ? 19 : 17, radius * 1.2)) * pixelRatio;
|
|
199
|
+
const text = getDelayText(delay, cancelled);
|
|
211
200
|
if (text) {
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
ctx.drawImage(delayText,
|
|
201
|
+
const textWidth = text.length * fontSize;
|
|
202
|
+
const delayText = getDelayTextCanvas(textWidth, text, fontSize, `bold ${fontSize}px arial, sans-serif`, getDelayColor(delay, cancelled, true), delayOutlineColor, pixelRatio);
|
|
203
|
+
ctx.drawImage(delayText, origin + radiusDelay + margin, origin - fontSize);
|
|
215
204
|
}
|
|
216
205
|
}
|
|
217
206
|
// Draw colored circle with black border
|
|
218
|
-
|
|
207
|
+
let circleFillColor;
|
|
219
208
|
if (useDelayStyle) {
|
|
220
209
|
circleFillColor = getDelayColor(delay, cancelled);
|
|
221
210
|
}
|
|
222
211
|
else {
|
|
223
212
|
circleFillColor = color || getBgColor(type);
|
|
224
213
|
}
|
|
225
|
-
|
|
226
|
-
|
|
214
|
+
const hasStroke = isDisplayStrokeAndDelay || hover || selected;
|
|
215
|
+
const hasDash = isDisplayStrokeAndDelay &&
|
|
227
216
|
useDelayStyle &&
|
|
228
217
|
delay === null &&
|
|
229
218
|
operatorProvidesRealtime === 'yes';
|
|
230
|
-
|
|
219
|
+
const circle = getCircleCanvas(origin, radius, circleFillColor, hasStroke, hasDash, pixelRatio);
|
|
231
220
|
ctx.drawImage(circle, 0, 0);
|
|
232
221
|
// Draw text in the circle
|
|
233
222
|
if (mustDrawText) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
223
|
+
const fontSize = Math.max(radius, 10);
|
|
224
|
+
const textSize = getTextSize(ctx, markerSize, name, fontSize);
|
|
225
|
+
const textColor2 = !useDelayStyle
|
|
237
226
|
? textColor || getTextColor(type)
|
|
238
227
|
: '#000000';
|
|
239
|
-
|
|
240
|
-
|
|
228
|
+
const hasStroke2 = useDelayStyle && delay === null && operatorProvidesRealtime === 'yes';
|
|
229
|
+
const text = getTextCanvas(name, origin, textSize, textColor2, circleFillColor, hasStroke2, pixelRatio);
|
|
241
230
|
ctx.drawImage(text, 0, 0);
|
|
242
231
|
}
|
|
243
232
|
cache[key] = canvas;
|
|
@@ -245,4 +234,4 @@ var realtimeDefaultStyle = function (trajectory, viewState, options) {
|
|
|
245
234
|
}
|
|
246
235
|
return cache[key];
|
|
247
236
|
};
|
|
248
|
-
|
|
237
|
+
export default realtimeDefaultStyle;
|
|
@@ -1,17 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
|
|
1
|
+
import realtimeDefaultStyle from './realtimeDefaultStyle';
|
|
15
2
|
/**
|
|
16
3
|
* A tracker style that display the delay as backgroundColor.
|
|
17
4
|
*
|
|
@@ -20,7 +7,7 @@ var realtimeDefaultStyle_1 = require("./realtimeDefaultStyle");
|
|
|
20
7
|
* @param {*} options Some options to change the rendering
|
|
21
8
|
* @return a canvas
|
|
22
9
|
*/
|
|
23
|
-
|
|
24
|
-
return (
|
|
10
|
+
const realtimeDelayStyle = (trajectory, viewState, options) => {
|
|
11
|
+
return realtimeDefaultStyle(trajectory, viewState, Object.assign(Object.assign({}, options), { useDelayStyle: true }));
|
|
25
12
|
};
|
|
26
|
-
|
|
13
|
+
export default realtimeDelayStyle;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* A very simple tracker style.
|
|
5
3
|
* Display blue point for each train.
|
|
6
4
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
let canvas;
|
|
6
|
+
const realtimeSimpleStyle = () => {
|
|
9
7
|
if (!canvas) {
|
|
10
|
-
document.createElement('canvas');
|
|
8
|
+
canvas = document.createElement('canvas');
|
|
11
9
|
canvas.width = 15;
|
|
12
10
|
canvas.height = 15;
|
|
13
|
-
|
|
11
|
+
const ctx = canvas.getContext('2d');
|
|
14
12
|
ctx.arc(8, 8, 5, 0, 2 * Math.PI, false);
|
|
15
13
|
ctx.fillStyle = '#8ED6FF';
|
|
16
14
|
ctx.fill();
|
|
@@ -21,4 +19,4 @@ var realtimeSimpleStyle = function () {
|
|
|
21
19
|
}
|
|
22
20
|
return canvas;
|
|
23
21
|
};
|
|
24
|
-
|
|
22
|
+
export default realtimeSimpleStyle;
|
package/common/typedefs.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Remove the delay from arrivalTime and departureTime
|
|
5
3
|
* @private
|
|
6
4
|
*/
|
|
7
|
-
|
|
5
|
+
const cleanStopTime = (content) => {
|
|
8
6
|
if (!content) {
|
|
9
7
|
return;
|
|
10
8
|
}
|
|
11
|
-
content.stations.forEach(
|
|
9
|
+
content.stations.forEach((station) => {
|
|
12
10
|
// eslint-disable-next-line no-param-reassign
|
|
13
11
|
station.arrivalTimeWithDelay = station.arrivalTime;
|
|
14
12
|
if (station.departureTime) {
|
|
@@ -27,4 +25,4 @@ var cleanStopTime = function (content) {
|
|
|
27
25
|
// eslint-disable-next-line consistent-return
|
|
28
26
|
return content;
|
|
29
27
|
};
|
|
30
|
-
|
|
28
|
+
export default cleanStopTime;
|
|
@@ -5,5 +5,5 @@ export default compareDepartures;
|
|
|
5
5
|
* @param {Object} b Second departure.
|
|
6
6
|
* @private
|
|
7
7
|
*/
|
|
8
|
-
declare function compareDepartures(a:
|
|
8
|
+
declare function compareDepartures(a: Object, b: Object, sortByMinArrivalTime?: boolean): number;
|
|
9
9
|
//# sourceMappingURL=compareDepartures.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compareDepartures.d.ts","sourceRoot":"","sources":["../../../src/common/utils/compareDepartures.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,
|
|
1
|
+
{"version":3,"file":"compareDepartures.d.ts","sourceRoot":"","sources":["../../../src/common/utils/compareDepartures.js"],"names":[],"mappings":";AAAA;;;;;GAKG;AACH,sCAJW,MAAM,KACN,MAAM,0CAiChB"}
|
|
@@ -1,17 +1,14 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Compare two given departures for sort alogithm,
|
|
5
3
|
* @param {Object} a First departure.
|
|
6
4
|
* @param {Object} b Second departure.
|
|
7
5
|
* @private
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
if (sortByMinArrivalTime === void 0) { sortByMinArrivalTime = false; }
|
|
7
|
+
const compareDepartures = (a, b, sortByMinArrivalTime = false) => {
|
|
11
8
|
// First LEAVING and HIDDEN, then BOARDING and then sorted by time.
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
9
|
+
const topStates = ['HIDDEN', 'LEAVING', 'BOARDING'];
|
|
10
|
+
const aTop = a.has_fzo && topStates.indexOf(a.state) > -1;
|
|
11
|
+
const bTop = b.has_fzo && topStates.indexOf(b.state) > -1;
|
|
15
12
|
if (aTop || bTop) {
|
|
16
13
|
if (aTop !== bTop) {
|
|
17
14
|
return aTop ? -1 : 1;
|
|
@@ -21,9 +18,9 @@ var compareDepartures = function (a, b, sortByMinArrivalTime) {
|
|
|
21
18
|
return topStates.indexOf(a.state) - topStates.indexOf(b.state);
|
|
22
19
|
}
|
|
23
20
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
let aDuration = null;
|
|
22
|
+
let bDuration = null;
|
|
23
|
+
const now = Date.now();
|
|
27
24
|
if (sortByMinArrivalTime) {
|
|
28
25
|
aDuration = new Date(a.min_arrival_time || a.time).getTime() - now;
|
|
29
26
|
bDuration = new Date(b.min_arrival_time || b.time).getTime() - now;
|
|
@@ -34,4 +31,4 @@ var compareDepartures = function (a, b, sortByMinArrivalTime) {
|
|
|
34
31
|
}
|
|
35
32
|
return aDuration - bDuration;
|
|
36
33
|
};
|
|
37
|
-
|
|
34
|
+
export default compareDepartures;
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* This function try to create a canvas element and return it.
|
|
5
3
|
* it uses document.createElement('canvas') if document is available
|
|
6
4
|
* or new OffscreenCanvas(width, height) if OffscreenCanvas is avalaible (for web worker)
|
|
7
5
|
* or it returns null if neither is available.
|
|
8
6
|
*/
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
const createCanvas = (width, height) => {
|
|
8
|
+
let canvas = null;
|
|
11
9
|
// Prevent SSR errors
|
|
12
10
|
if (typeof window === 'undefined') {
|
|
13
11
|
return null;
|
|
@@ -26,4 +24,4 @@ var createCanvas = function (width, height) {
|
|
|
26
24
|
}
|
|
27
25
|
return canvas;
|
|
28
26
|
};
|
|
29
|
-
|
|
27
|
+
export default createCanvas;
|
|
@@ -8,5 +8,5 @@ export default createFilters;
|
|
|
8
8
|
* @param {Regexp} regexLine - A regex aplly of vehcile's name.
|
|
9
9
|
* @private
|
|
10
10
|
*/
|
|
11
|
-
declare function createFilters(line: string | Array<string>, route: string | Array<string>, operator: string | Array<string>, regexLine: Regexp): (t: any) => boolean;
|
|
11
|
+
declare function createFilters(line: string | Array<string>, route: string | Array<string>, operator: string | Array<string>, regexLine: Regexp): ((t: any) => boolean) | null;
|
|
12
12
|
//# sourceMappingURL=createTrackerFilters.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createTrackerFilters.d.ts","sourceRoot":"","sources":["../../../src/common/utils/createTrackerFilters.js"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AACH,qCANW,MAAM,GAAC,MAAM,MAAM,CAAC,SACpB,MAAM,GAAC,MAAM,MAAM,CAAA,YACnB,MAAM,GAAC,MAAM,MAAM,CAAA,
|
|
1
|
+
{"version":3,"file":"createTrackerFilters.d.ts","sourceRoot":"","sources":["../../../src/common/utils/createTrackerFilters.js"],"names":[],"mappings":";AAAA;;;;;;;;GAQG;AACH,qCANW,MAAM,GAAC,MAAM,MAAM,CAAC,SACpB,MAAM,GAAC,MAAM,MAAM,CAAA,YACnB,MAAM,GAAC,MAAM,MAAM,CAAA,mDA+E7B"}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
1
|
/**
|
|
4
2
|
* Return a filter functions based on some parameters of a vehicle.
|
|
5
3
|
*
|
|
@@ -9,64 +7,56 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
9
7
|
* @param {Regexp} regexLine - A regex aplly of vehcile's name.
|
|
10
8
|
* @private
|
|
11
9
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const createFilters = (line, route, operator, regexLine) => {
|
|
11
|
+
const filterList = [];
|
|
14
12
|
if (!line && !route && !operator && !regexLine) {
|
|
15
13
|
return null;
|
|
16
14
|
}
|
|
17
15
|
if (regexLine) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
16
|
+
const regexLineList = typeof regexLine === 'string' ? [regexLine] : regexLine;
|
|
17
|
+
const lineFilter = (item) => {
|
|
18
|
+
const name = item.properties.name ||
|
|
21
19
|
(item.properties.line && item.properties.line.name) ||
|
|
22
20
|
'';
|
|
23
21
|
if (!name) {
|
|
24
22
|
return false;
|
|
25
23
|
}
|
|
26
|
-
return
|
|
27
|
-
return new RegExp(regexStr, 'i').test(name);
|
|
28
|
-
});
|
|
24
|
+
return regexLineList.some((regexStr) => new RegExp(regexStr, 'i').test(name));
|
|
29
25
|
};
|
|
30
26
|
filterList.push(lineFilter);
|
|
31
27
|
}
|
|
32
28
|
if (line) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
var _a = item.properties, linee = _a.line, name = _a.name;
|
|
39
|
-
var lineName = (name || (linee && linee.name) || '').toUpperCase();
|
|
29
|
+
const lineFiltersList = typeof line === 'string' ? line.split(',') : line;
|
|
30
|
+
const lineList = lineFiltersList.map((l) => l.replace(/\s+/g, '').toUpperCase());
|
|
31
|
+
const lineFilter = (item) => {
|
|
32
|
+
const { line: linee, name } = item.properties;
|
|
33
|
+
const lineName = (name || (linee && linee.name) || '').toUpperCase();
|
|
40
34
|
if (!lineName) {
|
|
41
35
|
return false;
|
|
42
36
|
}
|
|
43
|
-
return
|
|
37
|
+
return lineList.includes(lineName);
|
|
44
38
|
};
|
|
45
39
|
filterList.push(lineFilter);
|
|
46
40
|
}
|
|
47
41
|
if (route) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return
|
|
42
|
+
const routes = typeof route === 'string' ? route.split(',') : route;
|
|
43
|
+
const routeList = routes.map((item) => parseInt(item, 10));
|
|
44
|
+
const routeFilter = (item) => {
|
|
45
|
+
const routeId = parseInt(item.properties.routeIdentifier.split('.')[0], 10);
|
|
46
|
+
return routeList.includes(routeId);
|
|
53
47
|
};
|
|
54
48
|
filterList.push(routeFilter);
|
|
55
49
|
}
|
|
56
50
|
if (operator) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
return operatorList_1.some(function (op) {
|
|
60
|
-
return new RegExp(op, 'i').test(item.properties.operator);
|
|
61
|
-
});
|
|
62
|
-
};
|
|
51
|
+
const operatorList = typeof operator === 'string' ? [operator] : operator;
|
|
52
|
+
const operatorFilter = (item) => operatorList.some((op) => new RegExp(op, 'i').test(item.properties.operator));
|
|
63
53
|
filterList.push(operatorFilter);
|
|
64
54
|
}
|
|
65
55
|
if (!filterList.length) {
|
|
66
56
|
return null;
|
|
67
57
|
}
|
|
68
|
-
return
|
|
69
|
-
for (
|
|
58
|
+
return (t) => {
|
|
59
|
+
for (let i = 0; i < filterList.length; i += 1) {
|
|
70
60
|
if (!filterList[i](t)) {
|
|
71
61
|
return false;
|
|
72
62
|
}
|
|
@@ -74,4 +64,4 @@ var createFilters = function (line, route, operator, regexLine) {
|
|
|
74
64
|
return true;
|
|
75
65
|
};
|
|
76
66
|
};
|
|
77
|
-
|
|
67
|
+
export default createFilters;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createTrackerFilters.test.d.ts","sourceRoot":"","sources":["../../../src/common/utils/createTrackerFilters.test.js"],"names":[],"mappings":""}
|