mobility-toolbox-js 2.0.0-beta.32 → 2.0.0-beta.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api/RealtimeAPI.d.ts +268 -0
- package/api/RealtimeAPI.d.ts.map +1 -0
- package/api/RoutingAPI.d.ts +33 -0
- package/api/RoutingAPI.d.ts.map +1 -0
- package/api/StopsAPI.d.ts +36 -0
- package/api/StopsAPI.d.ts.map +1 -0
- package/api/index.d.ts +5 -0
- package/api/index.d.ts.map +1 -0
- package/api/typedefs.d.ts +105 -0
- package/api/typedefs.d.ts.map +1 -0
- package/common/api/HttpAPI.d.ts +31 -0
- package/common/api/HttpAPI.d.ts.map +1 -0
- package/common/api/WebSocketAPI.d.ts +95 -0
- package/common/api/WebSocketAPI.d.ts.map +1 -0
- package/common/controls/Control.d.ts +74 -0
- package/common/controls/Control.d.ts.map +1 -0
- package/common/{index.js → index.d.ts} +1 -0
- package/common/index.d.ts.map +1 -0
- package/common/layers/Layer.d.ts +80 -0
- package/common/layers/Layer.d.ts.map +1 -0
- package/common/mixins/CopyrightMixin.d.ts +22 -0
- package/common/mixins/CopyrightMixin.d.ts.map +1 -0
- package/common/mixins/MapboxLayerMixin.d.ts +27 -0
- package/common/mixins/MapboxLayerMixin.d.ts.map +1 -0
- package/common/mixins/RealtimeLayerMixin.d.ts +58 -0
- package/common/mixins/RealtimeLayerMixin.d.ts.map +1 -0
- package/common/mixins/StopFinderMixin.d.ts +40 -0
- package/common/mixins/StopFinderMixin.d.ts.map +1 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts +42 -0
- package/common/mixins/UserInteractionsLayerMixin.d.ts.map +1 -0
- package/common/styles/{index.js → index.d.ts} +1 -0
- package/common/styles/index.d.ts.map +1 -0
- package/common/styles/realtimeDefaultStyle.d.ts +15 -0
- package/common/styles/realtimeDefaultStyle.d.ts.map +1 -0
- package/common/styles/realtimeDelayStyle.d.ts +11 -0
- package/common/styles/realtimeDelayStyle.d.ts.map +1 -0
- package/common/styles/realtimeSimpleStyle.d.ts +3 -0
- package/common/styles/realtimeSimpleStyle.d.ts.map +1 -0
- package/common/typedefs.d.ts +50 -0
- package/common/typedefs.d.ts.map +1 -0
- package/common/utils/cleanStopTime.d.ts +7 -0
- package/common/utils/cleanStopTime.d.ts.map +1 -0
- package/common/utils/compareDepartures.d.ts +9 -0
- package/common/utils/compareDepartures.d.ts.map +1 -0
- package/common/utils/createCanvas.d.ts +9 -0
- package/common/utils/createCanvas.d.ts.map +1 -0
- package/common/utils/createTrackerFilters.d.ts +12 -0
- package/common/utils/createTrackerFilters.d.ts.map +1 -0
- package/common/utils/getLayersAsFlatArray.d.ts +3 -0
- package/common/utils/getLayersAsFlatArray.d.ts.map +1 -0
- package/common/utils/getMapboxMapCopyrights.d.ts +8 -0
- package/common/utils/getMapboxMapCopyrights.d.ts.map +1 -0
- package/common/utils/getMapboxRender.d.ts +5 -0
- package/common/utils/getMapboxRender.d.ts.map +1 -0
- package/common/utils/getMaplibreRender.d.ts +5 -0
- package/common/utils/getMaplibreRender.d.ts.map +1 -0
- package/common/utils/getRealtimeModeSuffix.d.ts +8 -0
- package/common/utils/getRealtimeModeSuffix.d.ts.map +1 -0
- package/common/utils/getUrlWithParams.d.ts +9 -0
- package/common/utils/getUrlWithParams.d.ts.map +1 -0
- package/common/utils/getVehiclePosition.d.ts +14 -0
- package/common/utils/getVehiclePosition.d.ts.map +1 -0
- package/common/utils/{index.js → index.d.ts} +3 -0
- package/common/utils/index.d.ts.map +1 -0
- package/common/utils/removeDuplicate.d.ts +10 -0
- package/common/utils/removeDuplicate.d.ts.map +1 -0
- package/common/utils/renderTrajectories.d.ts +20 -0
- package/common/utils/renderTrajectories.d.ts.map +1 -0
- package/common/utils/sortByDelay.d.ts +3 -0
- package/common/utils/sortByDelay.d.ts.map +1 -0
- package/common/utils/timeUtils.d.ts +5 -0
- package/common/utils/timeUtils.d.ts.map +1 -0
- package/common/utils/trackerConfig.d.ts +24 -0
- package/common/utils/trackerConfig.d.ts.map +1 -0
- package/iife.d.ts +3 -0
- package/iife.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/index.d.ts.map +1 -0
- package/mapbox/controls/CopyrightControl.d.ts +32 -0
- package/mapbox/controls/CopyrightControl.d.ts.map +1 -0
- package/mapbox/controls/{index.js → index.d.ts} +1 -0
- package/mapbox/controls/index.d.ts.map +1 -0
- package/mapbox/{index.js → index.d.ts} +1 -0
- package/mapbox/index.d.ts.map +1 -0
- package/mapbox/layers/Layer.d.ts +47 -0
- package/mapbox/layers/Layer.d.ts.map +1 -0
- package/mapbox/layers/RealtimeLayer.d.ts +118 -0
- package/mapbox/layers/RealtimeLayer.d.ts.map +1 -0
- package/mapbox/layers/{index.js → index.d.ts} +1 -0
- package/mapbox/layers/index.d.ts.map +1 -0
- package/mapbox/utils.d.ts +8 -0
- package/mapbox/utils.d.ts.map +1 -0
- package/mbt.js +2049 -2106
- package/mbt.js.map +3 -3
- package/mbt.min.js +18 -18
- package/mbt.min.js.map +3 -3
- package/ol/controls/CopyrightControl.d.ts +31 -0
- package/ol/controls/CopyrightControl.d.ts.map +1 -0
- package/ol/controls/RoutingControl.d.ts +180 -0
- package/ol/controls/RoutingControl.d.ts.map +1 -0
- package/ol/controls/StopFinderControl.d.ts +32 -0
- package/ol/controls/StopFinderControl.d.ts.map +1 -0
- package/ol/controls/{index.js → index.d.ts} +1 -0
- package/ol/controls/index.d.ts.map +1 -0
- package/ol/{index.js → index.d.ts} +1 -0
- package/ol/index.d.ts.map +1 -0
- package/ol/layers/Layer.d.ts +49 -0
- package/ol/layers/Layer.d.ts.map +1 -0
- package/ol/layers/MapboxLayer.d.ts +42 -0
- package/ol/layers/MapboxLayer.d.ts.map +1 -0
- package/ol/layers/MapboxStyleLayer.d.ts +146 -0
- package/ol/layers/MapboxStyleLayer.d.ts.map +1 -0
- package/ol/layers/MaplibreLayer.d.ts +27 -0
- package/ol/layers/MaplibreLayer.d.ts.map +1 -0
- package/ol/layers/RealtimeLayer.d.ts +119 -0
- package/ol/layers/RealtimeLayer.d.ts.map +1 -0
- package/ol/layers/RoutingLayer.d.ts +24 -0
- package/ol/layers/RoutingLayer.d.ts.map +1 -0
- package/ol/layers/VectorLayer.d.ts +23 -0
- package/ol/layers/VectorLayer.d.ts.map +1 -0
- package/ol/layers/WMSLayer.d.ts +38 -0
- package/ol/layers/WMSLayer.d.ts.map +1 -0
- package/ol/layers/{index.js → index.d.ts} +1 -0
- package/ol/layers/index.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryDelayStyle.d.ts.map +1 -0
- package/ol/styles/fullTrajectoryStyle.d.ts +4 -0
- package/ol/styles/fullTrajectoryStyle.d.ts.map +1 -0
- package/ol/styles/{index.js → index.d.ts} +1 -0
- package/ol/styles/index.d.ts.map +1 -0
- package/package.json +14 -36
- package/setupTests.d.ts +2 -0
- package/setupTests.d.ts.map +1 -0
- package/types/index.d.ts +7 -6
- package/types/routing.d.ts +25 -25
- package/types/stops.d.ts +19 -19
- package/api/RealtimeAPI.js +0 -357
- package/api/RealtimeAPI.test.js +0 -67
- package/api/RoutingAPI.js +0 -15
- package/api/RoutingAPI.test.js +0 -25
- package/api/StopsAPI.js +0 -12
- package/api/StopsAPI.test.js +0 -22
- package/api/index.js +0 -3
- package/api/typedefs.js +0 -0
- package/common/api/HttpAPI.js +0 -32
- package/common/api/HttpAPI.test.js +0 -50
- package/common/api/WebSocketAPI.js +0 -175
- package/common/api/WebSocketAPI.test.js +0 -311
- package/common/controls/Control.js +0 -81
- package/common/controls/Control.test.js +0 -87
- package/common/layers/Layer.js +0 -140
- package/common/layers/Layer.test.js +0 -134
- package/common/mixins/CopyrightMixin.js +0 -24
- package/common/mixins/RealtimeLayerMixin.js +0 -436
- package/common/mixins/StopFinderMixin.js +0 -110
- package/common/mixins/UserInteractionsLayerMixin.js +0 -124
- package/common/mixins/UserInteractionsLayerMixin.test.js +0 -199
- package/common/styles/realtimeDefaultStyle.js +0 -202
- package/common/styles/realtimeDelayStyle.js +0 -8
- package/common/styles/realtimeSimpleStyle.js +0 -18
- package/common/typedefs.js +0 -0
- package/common/utils/cleanStopTime.js +0 -19
- package/common/utils/compareDepartures.js +0 -25
- package/common/utils/createCanvas.js +0 -17
- package/common/utils/createTrackerFilters.js +0 -56
- package/common/utils/createTrackerFilters.test.js +0 -79
- package/common/utils/getLayersAsFlatArray.js +0 -14
- package/common/utils/getMapboxMapCopyrights.js +0 -19
- package/common/utils/getMapboxMapCopyrights.test.js +0 -40
- package/common/utils/getRealtimeModeSuffix.js +0 -2
- package/common/utils/getUrlWithParams.js +0 -11
- package/common/utils/getVehiclePosition.js +0 -42
- package/common/utils/removeDuplicate.js +0 -8
- package/common/utils/removeDuplicate.test.js +0 -19
- package/common/utils/renderTrajectories.js +0 -86
- package/common/utils/sortByDelay.js +0 -18
- package/common/utils/timeUtils.js +0 -20
- package/common/utils/timeUtils.test.js +0 -10
- package/common/utils/trackerConfig.js +0 -129
- package/common/utils/trackerConfig.test.js +0 -23
- package/index.js +0 -8
- package/mapbox/controls/CopyrightControl.js +0 -29
- package/mapbox/layers/Layer.js +0 -56
- package/mapbox/layers/Layer.test.js +0 -182
- package/mapbox/layers/RealtimeLayer.js +0 -185
- package/mapbox/layers/RealtimeLayer.test.js +0 -10
- package/mapbox/utils.js +0 -32
- package/ol/controls/CopyrightControl.js +0 -42
- package/ol/controls/CopyrightControl.test.js +0 -165
- package/ol/controls/RoutingControl.js +0 -388
- package/ol/controls/RoutingControl.test.js +0 -146
- package/ol/controls/StopFinderControl.js +0 -10
- package/ol/controls/StopFinderControl.test.js +0 -48
- package/ol/layers/Layer.js +0 -83
- package/ol/layers/Layer.test.js +0 -175
- package/ol/layers/MapboxLayer.js +0 -204
- package/ol/layers/MapboxLayer.test.js +0 -160
- package/ol/layers/MapboxStyleLayer.js +0 -187
- package/ol/layers/MapboxStyleLayer.test.js +0 -226
- package/ol/layers/MaplibreLayer.js +0 -140
- package/ol/layers/RealtimeLayer.js +0 -187
- package/ol/layers/RealtimeLayer.test.js +0 -67
- package/ol/layers/RoutingLayer.js +0 -61
- package/ol/layers/RoutingLayer.test.js +0 -39
- package/ol/layers/VectorLayer.js +0 -22
- package/ol/layers/VectorLayer.test.js +0 -76
- package/ol/layers/WMSLayer.js +0 -38
- package/ol/layers/WMSLayer.test.js +0 -57
- package/ol/styles/fullTrajectoryDelayStyle.js +0 -31
- package/ol/styles/fullTrajectoryStyle.js +0 -42
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import getMapboxMapCopyrights from "./getMapboxMapCopyrights";
|
|
2
|
-
describe("getMapboxMapCopyrights()", () => {
|
|
3
|
-
test("returns an empty array if map is not defined", () => {
|
|
4
|
-
expect(getMapboxMapCopyrights().length).toBe(0);
|
|
5
|
-
});
|
|
6
|
-
test("returns an empty array if map.style is not defined", () => {
|
|
7
|
-
expect(getMapboxMapCopyrights({}).length).toBe(0);
|
|
8
|
-
});
|
|
9
|
-
test("returns non depluicated copyrights in an array", () => {
|
|
10
|
-
expect(getMapboxMapCopyrights({
|
|
11
|
-
style: {
|
|
12
|
-
sourceCaches: {
|
|
13
|
-
used: {
|
|
14
|
-
used: true,
|
|
15
|
-
getSource() {
|
|
16
|
-
return {
|
|
17
|
-
attribution: '<a href="https://www.openmaptiles.org/" target="_blank">\xA9 OpenMapTiles</a> <a href="https://www.openstreetmap.org/about/" target="_blank">© OpenStreetMap contributors</a>'
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
},
|
|
21
|
-
"not used": {
|
|
22
|
-
used: false
|
|
23
|
-
},
|
|
24
|
-
"also used": {
|
|
25
|
-
used: true,
|
|
26
|
-
getSource() {
|
|
27
|
-
return {
|
|
28
|
-
attribution: '<a href="https://www.openmaptiles.org/" target="_blank">© OpenMapTiles</a> <a href="https://www.imagico.de/" target="_blank">© imagico</a>'
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
})).toEqual([
|
|
35
|
-
'<a href="https://www.openmaptiles.org/" target="_blank">\xA9 OpenMapTiles</a>',
|
|
36
|
-
'<a href="https://www.openstreetmap.org/about/" target="_blank">\xA9 OpenStreetMap contributors</a>',
|
|
37
|
-
'<a href="https://www.imagico.de/" target="_blank">\xA9 imagico</a>'
|
|
38
|
-
]);
|
|
39
|
-
});
|
|
40
|
-
});
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
const getUrlWithParams = (url, params) => {
|
|
2
|
-
const newUrl = new URL(url);
|
|
3
|
-
const searchParams = params || {};
|
|
4
|
-
Object.entries(searchParams).forEach(([key, value]) => {
|
|
5
|
-
if (value !== void 0 && value !== null) {
|
|
6
|
-
newUrl.searchParams.set(key, value);
|
|
7
|
-
}
|
|
8
|
-
});
|
|
9
|
-
return newUrl;
|
|
10
|
-
};
|
|
11
|
-
export default getUrlWithParams;
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import GeomType from "ol/geom/GeometryType";
|
|
2
|
-
const getVehiclePosition = (now, trajectory, noInterpolate) => {
|
|
3
|
-
const {
|
|
4
|
-
time_intervals: timeIntervals,
|
|
5
|
-
olGeometry: geometry,
|
|
6
|
-
coordinate
|
|
7
|
-
} = trajectory.properties;
|
|
8
|
-
let coord;
|
|
9
|
-
let rotation;
|
|
10
|
-
if (noInterpolate && coordinate) {
|
|
11
|
-
coord = coordinate;
|
|
12
|
-
} else if (geometry.getType() === GeomType.POINT) {
|
|
13
|
-
coord = geometry.getCoordinates();
|
|
14
|
-
} else if (geometry.getType() === GeomType.LINE_STRING) {
|
|
15
|
-
const intervals = timeIntervals || [[]];
|
|
16
|
-
const firstInterval = intervals[0];
|
|
17
|
-
const lastInterval = intervals[intervals.length - 1];
|
|
18
|
-
if (now < firstInterval[0]) {
|
|
19
|
-
[, , rotation] = firstInterval;
|
|
20
|
-
coord = geometry.getFirstCoordinate();
|
|
21
|
-
} else if (now > lastInterval[0]) {
|
|
22
|
-
[, , rotation] = lastInterval;
|
|
23
|
-
coord = geometry.getLastCoordinate();
|
|
24
|
-
} else {
|
|
25
|
-
for (let j = 0; j < intervals.length - 1; j += 1) {
|
|
26
|
-
const [start, startFrac] = intervals[j];
|
|
27
|
-
const [end, endFrac] = intervals[j + 1];
|
|
28
|
-
if (start <= now && now <= end) {
|
|
29
|
-
const timeFrac = Math.min((now - start) / (end - start), 1);
|
|
30
|
-
const geomFrac = timeFrac * (endFrac - startFrac) + startFrac;
|
|
31
|
-
coord = geometry.getCoordinateAt(geomFrac);
|
|
32
|
-
[, , rotation] = intervals[j];
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
} else {
|
|
38
|
-
console.error("This geometry type is not supported. Only Point or LineString are. Current geometry: ", geometry);
|
|
39
|
-
}
|
|
40
|
-
return { coord, rotation };
|
|
41
|
-
};
|
|
42
|
-
export default getVehiclePosition;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
const removeDuplicate = (array) => {
|
|
2
|
-
const arrWithoutEmptyValues = array.filter((val) => val !== void 0 && val !== null && val.trim && val.trim());
|
|
3
|
-
const lowerCasesValues = arrWithoutEmptyValues.map((str) => str.toLowerCase());
|
|
4
|
-
const uniqueLowerCaseValues = [...new Set(lowerCasesValues)];
|
|
5
|
-
const uniqueValues = uniqueLowerCaseValues.map((uniqueStr) => arrWithoutEmptyValues.find((str) => str.toLowerCase() === uniqueStr));
|
|
6
|
-
return uniqueValues;
|
|
7
|
-
};
|
|
8
|
-
export default removeDuplicate;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import removeDuplicate from "./removeDuplicate";
|
|
2
|
-
describe("removeDuplicate()", () => {
|
|
3
|
-
test("removes duplicates", () => {
|
|
4
|
-
expect(removeDuplicate([
|
|
5
|
-
"a",
|
|
6
|
-
" ",
|
|
7
|
-
" ",
|
|
8
|
-
"b",
|
|
9
|
-
"a",
|
|
10
|
-
void 0,
|
|
11
|
-
null,
|
|
12
|
-
"A",
|
|
13
|
-
0,
|
|
14
|
-
"c",
|
|
15
|
-
"b",
|
|
16
|
-
"B"
|
|
17
|
-
])).toEqual(["a", "b", "c"]);
|
|
18
|
-
});
|
|
19
|
-
});
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { compose, apply, create } from "ol/transform";
|
|
2
|
-
import getVehiclePosition from "./getVehiclePosition";
|
|
3
|
-
const renderTrajectories = (canvas, trajectories, style, viewState, options) => {
|
|
4
|
-
if (!canvas) {
|
|
5
|
-
return {};
|
|
6
|
-
}
|
|
7
|
-
const {
|
|
8
|
-
time = Date.now(),
|
|
9
|
-
size = [],
|
|
10
|
-
center,
|
|
11
|
-
resolution,
|
|
12
|
-
rotation = 0,
|
|
13
|
-
pixelRatio
|
|
14
|
-
} = viewState;
|
|
15
|
-
const { noInterpolate = false, hoverVehicleId, selectedVehicleId } = options;
|
|
16
|
-
const context = canvas.getContext("2d");
|
|
17
|
-
context.clearRect(0, 0, canvas.width, canvas.height);
|
|
18
|
-
const [width, height] = size;
|
|
19
|
-
if (width && height && (canvas.width !== width || canvas.height !== height)) {
|
|
20
|
-
[canvas.width, canvas.height] = [width * pixelRatio, height * pixelRatio];
|
|
21
|
-
}
|
|
22
|
-
const coordinateToPixelTransform = compose(create(), size[0] / 2, size[1] / 2, 1 / resolution, -1 / resolution, -rotation, -center[0], -center[1]);
|
|
23
|
-
if (canvas.style) {
|
|
24
|
-
canvas.style.width = `${canvas.width / pixelRatio}px`;
|
|
25
|
-
canvas.style.height = `${canvas.height / pixelRatio}px`;
|
|
26
|
-
}
|
|
27
|
-
let hoverVehicleImg;
|
|
28
|
-
let hoverVehiclePx;
|
|
29
|
-
let hoverVehicleWidth;
|
|
30
|
-
let hoverVehicleHeight;
|
|
31
|
-
let selectedVehicleImg;
|
|
32
|
-
let selectedVehiclePx;
|
|
33
|
-
let selectedVehicleWidth;
|
|
34
|
-
let selectedVehicleHeight;
|
|
35
|
-
const renderedTrajectories = [];
|
|
36
|
-
for (let i = trajectories.length - 1; i >= 0; i -= 1) {
|
|
37
|
-
const trajectory = trajectories[i];
|
|
38
|
-
const { train_id: id, timeOffset } = trajectory.properties;
|
|
39
|
-
const { coord, rotation: rotationIcon } = getVehiclePosition(time - (timeOffset || 0), trajectory, noInterpolate);
|
|
40
|
-
trajectories[i].properties.coordinate = coord;
|
|
41
|
-
trajectories[i].properties.rotation = rotationIcon;
|
|
42
|
-
if (!coord) {
|
|
43
|
-
continue;
|
|
44
|
-
}
|
|
45
|
-
let px = apply(coordinateToPixelTransform, [...coord]);
|
|
46
|
-
if (!px) {
|
|
47
|
-
continue;
|
|
48
|
-
}
|
|
49
|
-
px = px.map((p) => p * pixelRatio);
|
|
50
|
-
if (px[0] < 0 || px[0] > canvas.width || px[1] < 0 || px[1] > canvas.height) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
const vehicleImg = style(trajectory, viewState, options);
|
|
54
|
-
if (!vehicleImg) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
const imgWidth = vehicleImg.width;
|
|
58
|
-
const imgHeight = vehicleImg.height;
|
|
59
|
-
if (hoverVehicleId !== id && selectedVehicleId !== id) {
|
|
60
|
-
context.drawImage(vehicleImg, px[0] - imgWidth / 2, px[1] - imgHeight / 2, imgWidth, imgHeight);
|
|
61
|
-
}
|
|
62
|
-
if (hoverVehicleId && hoverVehicleId === id) {
|
|
63
|
-
hoverVehicleImg = vehicleImg;
|
|
64
|
-
hoverVehiclePx = px;
|
|
65
|
-
hoverVehicleWidth = imgWidth;
|
|
66
|
-
hoverVehicleHeight = imgHeight;
|
|
67
|
-
}
|
|
68
|
-
if (selectedVehicleId && selectedVehicleId === id) {
|
|
69
|
-
selectedVehicleImg = vehicleImg;
|
|
70
|
-
selectedVehiclePx = px;
|
|
71
|
-
selectedVehicleWidth = imgWidth;
|
|
72
|
-
selectedVehicleHeight = imgHeight;
|
|
73
|
-
}
|
|
74
|
-
renderedTrajectories.push(trajectory);
|
|
75
|
-
}
|
|
76
|
-
if (selectedVehicleImg) {
|
|
77
|
-
context.drawImage(selectedVehicleImg, selectedVehiclePx[0] - selectedVehicleWidth / 2, selectedVehiclePx[1] - selectedVehicleHeight / 2, selectedVehicleWidth, selectedVehicleHeight);
|
|
78
|
-
}
|
|
79
|
-
if (hoverVehicleImg) {
|
|
80
|
-
context.drawImage(hoverVehicleImg, hoverVehiclePx[0] - hoverVehicleWidth / 2, hoverVehiclePx[1] - hoverVehicleHeight / 2, hoverVehicleWidth, hoverVehicleHeight);
|
|
81
|
-
}
|
|
82
|
-
return {
|
|
83
|
-
renderedTrajectories
|
|
84
|
-
};
|
|
85
|
-
};
|
|
86
|
-
export default renderTrajectories;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
const sortByDelay = (traj1, traj2) => {
|
|
2
|
-
const props1 = traj1.properties;
|
|
3
|
-
const props2 = traj2.properties;
|
|
4
|
-
if (props1.delay === null && props2.delay !== null) {
|
|
5
|
-
return 1;
|
|
6
|
-
}
|
|
7
|
-
if (props2.delay === null && props1.delay !== null) {
|
|
8
|
-
return -1;
|
|
9
|
-
}
|
|
10
|
-
if (props1.cancelled && !props2.cancelled) {
|
|
11
|
-
return props2.delay < 18e4 ? -1 : 1;
|
|
12
|
-
}
|
|
13
|
-
if (props2.cancelled && !props1.cancelled) {
|
|
14
|
-
return props1.delay < 18e4 ? 1 : -1;
|
|
15
|
-
}
|
|
16
|
-
return props2.delay - props1.delay;
|
|
17
|
-
};
|
|
18
|
-
export default sortByDelay;
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
export const getUTCDateString = (now = new Date()) => {
|
|
2
|
-
let month = (now.getUTCMonth() + 1).toString();
|
|
3
|
-
month = month.length === 1 ? `0${month}` : month;
|
|
4
|
-
let day = now.getUTCDate().toString();
|
|
5
|
-
day = day.length === 1 ? `0${day}` : day;
|
|
6
|
-
return [now.getUTCFullYear(), month, day].join("");
|
|
7
|
-
};
|
|
8
|
-
export const getUTCTimeString = (date) => [
|
|
9
|
-
date.getUTCHours(),
|
|
10
|
-
date.getUTCMinutes(),
|
|
11
|
-
`${date.getUTCSeconds()}.${date.getUTCMilliseconds()}`
|
|
12
|
-
].join(":");
|
|
13
|
-
export const pad = (integer) => integer < 10 ? `0${integer}` : integer;
|
|
14
|
-
export const getHoursAndMinutes = (timeInMs) => {
|
|
15
|
-
if (!timeInMs || timeInMs <= 0) {
|
|
16
|
-
return "";
|
|
17
|
-
}
|
|
18
|
-
const date = new Date(timeInMs);
|
|
19
|
-
return `${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
20
|
-
};
|
|
@@ -1,10 +0,0 @@
|
|
|
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,129 +0,0 @@
|
|
|
1
|
-
const trackerRadiusMapping = {
|
|
2
|
-
0: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
3
|
-
1: [0, 0, 0, 0, 0, 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],
|
|
5
|
-
3: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
6
|
-
4: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
7
|
-
5: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
8
|
-
6: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
9
|
-
7: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
10
|
-
8: [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
|
|
11
|
-
9: [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15]
|
|
12
|
-
};
|
|
13
|
-
export const types = [
|
|
14
|
-
/^Tram/i,
|
|
15
|
-
/^Subway( \/ Metro \/ S-Bahn)?/i,
|
|
16
|
-
/^Train/i,
|
|
17
|
-
/^Bus/i,
|
|
18
|
-
/^Ferry/i,
|
|
19
|
-
/^Cable ?Car/i,
|
|
20
|
-
/^Gondola/i,
|
|
21
|
-
/^Funicular/i,
|
|
22
|
-
/^(Long distance bus|coach)/i,
|
|
23
|
-
/^Rail/i
|
|
24
|
-
];
|
|
25
|
-
export const bgColors = [
|
|
26
|
-
"#ffb400",
|
|
27
|
-
"#ff5400",
|
|
28
|
-
"#ff8080",
|
|
29
|
-
"#ea0000",
|
|
30
|
-
"#3000ff",
|
|
31
|
-
"#ffb400",
|
|
32
|
-
"#41a27b",
|
|
33
|
-
"#00d237",
|
|
34
|
-
"#b5b5b5",
|
|
35
|
-
"#ff8080"
|
|
36
|
-
];
|
|
37
|
-
export const textColors = [
|
|
38
|
-
"#000000",
|
|
39
|
-
"#ffffff",
|
|
40
|
-
"#000000",
|
|
41
|
-
"#ffffff",
|
|
42
|
-
"#ffffff",
|
|
43
|
-
"#000000",
|
|
44
|
-
"#ffffff",
|
|
45
|
-
"#000000",
|
|
46
|
-
"#000000",
|
|
47
|
-
"#000000"
|
|
48
|
-
];
|
|
49
|
-
export const getTypeIndex = (type) => {
|
|
50
|
-
if (typeof type === "string") {
|
|
51
|
-
return types.findIndex((t) => t.test(type));
|
|
52
|
-
}
|
|
53
|
-
return type;
|
|
54
|
-
};
|
|
55
|
-
export const getRadius = (type, zoom) => {
|
|
56
|
-
try {
|
|
57
|
-
const typeIdx = getTypeIndex(type || 0);
|
|
58
|
-
return trackerRadiusMapping[typeIdx][zoom];
|
|
59
|
-
} catch (e) {
|
|
60
|
-
return 1;
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
export const getBgColor = (type = 0) => {
|
|
64
|
-
try {
|
|
65
|
-
const typeIdx = getTypeIndex(type);
|
|
66
|
-
return bgColors[typeIdx];
|
|
67
|
-
} catch (e) {
|
|
68
|
-
return 1;
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
export const getTextColor = (type = 0) => {
|
|
72
|
-
try {
|
|
73
|
-
const typeIdx = getTypeIndex(type);
|
|
74
|
-
return textColors[typeIdx];
|
|
75
|
-
} catch (e) {
|
|
76
|
-
return 1;
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
export const getTextSize = (ctx, markerSize, text, fontSize) => {
|
|
80
|
-
ctx.font = `bold ${fontSize}px Arial`;
|
|
81
|
-
let newText = ctx.measureText(text);
|
|
82
|
-
const maxiter = 25;
|
|
83
|
-
let i = 0;
|
|
84
|
-
while (newText.width > markerSize - 6 && i < maxiter) {
|
|
85
|
-
fontSize -= 0.5;
|
|
86
|
-
ctx.font = `bold ${fontSize}px arial, sans-serif`;
|
|
87
|
-
newText = ctx.measureText(text);
|
|
88
|
-
i += 1;
|
|
89
|
-
}
|
|
90
|
-
return fontSize;
|
|
91
|
-
};
|
|
92
|
-
export const getDelayColor = (delayInMs, cancelled, isDelayText) => {
|
|
93
|
-
if (cancelled) {
|
|
94
|
-
return isDelayText ? "#ff0000" : "#a0a0a0";
|
|
95
|
-
}
|
|
96
|
-
if (delayInMs >= 36e5) {
|
|
97
|
-
return "#ed004c";
|
|
98
|
-
}
|
|
99
|
-
if (delayInMs >= 5e5) {
|
|
100
|
-
return "#e80000";
|
|
101
|
-
}
|
|
102
|
-
if (delayInMs >= 3e5) {
|
|
103
|
-
return "#ff4a00";
|
|
104
|
-
}
|
|
105
|
-
if (delayInMs >= 18e4) {
|
|
106
|
-
return "#f7bf00";
|
|
107
|
-
}
|
|
108
|
-
if (delayInMs === null) {
|
|
109
|
-
return "#a0a0a0";
|
|
110
|
-
}
|
|
111
|
-
return "#00a00c";
|
|
112
|
-
};
|
|
113
|
-
export const getDelayText = (delayInMs, cancelled) => {
|
|
114
|
-
if (cancelled) {
|
|
115
|
-
return String.fromCodePoint(215);
|
|
116
|
-
}
|
|
117
|
-
if (delayInMs > 36e5) {
|
|
118
|
-
const rounded = Math.round(delayInMs / 36e5);
|
|
119
|
-
return `+${rounded}h`;
|
|
120
|
-
}
|
|
121
|
-
if (delayInMs > 59e3) {
|
|
122
|
-
const rounded = Math.round(delayInMs / 6e4);
|
|
123
|
-
return `+${rounded}m`;
|
|
124
|
-
}
|
|
125
|
-
if (delayInMs > 0) {
|
|
126
|
-
return `+${delayInMs}s`;
|
|
127
|
-
}
|
|
128
|
-
return "";
|
|
129
|
-
};
|
|
@@ -1,23 +0,0 @@
|
|
|
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(void 0)).toBe(void 0);
|
|
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/index.js
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import Control from "../../common/controls/Control";
|
|
2
|
-
import mixin from "../../common/mixins/CopyrightMixin";
|
|
3
|
-
import { getMapboxMapCopyrights } from "../../common/utils";
|
|
4
|
-
class CopyrightControl extends mixin(Control) {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super(options);
|
|
7
|
-
this.render = this.render.bind(this);
|
|
8
|
-
}
|
|
9
|
-
activate() {
|
|
10
|
-
super.activate();
|
|
11
|
-
if (this.map) {
|
|
12
|
-
this.map.on("sourcedata", this.render);
|
|
13
|
-
this.map.on("styledata", this.render);
|
|
14
|
-
this.map.on("idle", this.render);
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
deactivate() {
|
|
18
|
-
if (this.map) {
|
|
19
|
-
this.map.off("sourcedata", this.render);
|
|
20
|
-
this.map.off("styledata", this.render);
|
|
21
|
-
this.map.off("idle", this.render);
|
|
22
|
-
}
|
|
23
|
-
super.deactivate();
|
|
24
|
-
}
|
|
25
|
-
getCopyrights() {
|
|
26
|
-
return getMapboxMapCopyrights(this.map);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export default CopyrightControl;
|
package/mapbox/layers/Layer.js
DELETED
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { unByKey } from "ol/Observable";
|
|
2
|
-
import { transformExtent } from "ol/proj";
|
|
3
|
-
import LayerCommon from "../../common/layers/Layer";
|
|
4
|
-
import userInteractionsMixin from "../../common/mixins/UserInteractionsLayerMixin";
|
|
5
|
-
class Layer extends userInteractionsMixin(LayerCommon) {
|
|
6
|
-
attachToMap(map) {
|
|
7
|
-
super.attachToMap(map);
|
|
8
|
-
if (!this.map) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
if (this.userInteractions) {
|
|
12
|
-
this.toggleVisibleListeners();
|
|
13
|
-
this.onChangeVisibleKey = this.on("change:visible", this.toggleVisibleListeners);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
detachFromMap() {
|
|
17
|
-
if (this.map) {
|
|
18
|
-
this.deactivateUserInteractions();
|
|
19
|
-
unByKey(this.onChangeVisibleKey);
|
|
20
|
-
}
|
|
21
|
-
super.detachFromMap();
|
|
22
|
-
}
|
|
23
|
-
activateUserInteractions() {
|
|
24
|
-
this.deactivateUserInteractions();
|
|
25
|
-
if (this.map && this.userInteractions && this.userClickInteractions && this.userClickCallbacks.length) {
|
|
26
|
-
this.map.on("click", this.onUserClickCallback);
|
|
27
|
-
}
|
|
28
|
-
if (this.map && this.userInteractions && this.userHoverInteractions && this.userHoverCallbacks.length) {
|
|
29
|
-
this.map.on("mousemove", this.onUserMoveCallback);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
deactivateUserInteractions() {
|
|
33
|
-
if (this.map) {
|
|
34
|
-
this.map.off("mousemove", this.onUserMoveCallback);
|
|
35
|
-
this.map.off("click", this.onUserClickCallback);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
toggleVisibleListeners() {
|
|
39
|
-
if (this.visible) {
|
|
40
|
-
this.activateUserInteractions();
|
|
41
|
-
} else {
|
|
42
|
-
this.deactivateUserInteractions();
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
getMercatorExtent() {
|
|
46
|
-
const bounds = this.map.getBounds().toArray();
|
|
47
|
-
return transformExtent([...bounds[0], ...bounds[1]], "EPSG:4326", "EPSG:3857");
|
|
48
|
-
}
|
|
49
|
-
getOlZoom() {
|
|
50
|
-
return this.map.getZoom() + 1;
|
|
51
|
-
}
|
|
52
|
-
clone(newOptions) {
|
|
53
|
-
return new Layer({ ...this.options, ...newOptions });
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
export default Layer;
|