@geops/rvf-mobility-web-component 0.1.24 → 0.1.25
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/CHANGELOG.md +8 -0
- package/index.js +55 -55
- package/package.json +1 -1
- package/src/RvfMobilityMap/RvfMobilityMap.tsx +4 -2
- package/src/utils/fullTrajectoryStyle.ts +57 -0
- package/src/utils/getDelayColor.test.ts +3 -2
- package/src/utils/getDelayColor.ts +1 -1
- package/src/utils/getDelayColorForVehicle.test.ts +1 -1
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@geops/rvf-mobility-web-component",
|
|
3
3
|
"license": "UNLICENSED",
|
|
4
4
|
"description": "Web components for rvf in the domains of mobility and logistics.",
|
|
5
|
-
"version": "0.1.
|
|
5
|
+
"version": "0.1.25",
|
|
6
6
|
"homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
|
|
7
7
|
"type": "module",
|
|
8
8
|
"main": "index.js",
|
|
@@ -55,6 +55,7 @@ import StationsLayer from "../StationsLayer";
|
|
|
55
55
|
// @ts-expect-error bad type definition
|
|
56
56
|
import tailwind from "../style.css";
|
|
57
57
|
import { RVF_EXTENT_3857, RVF_LAYERS_TITLES } from "../utils/constants";
|
|
58
|
+
import fullTrajectoryStyle from "../utils/fullTrajectoryStyle";
|
|
58
59
|
import getBgColor from "../utils/getBgColor";
|
|
59
60
|
import getFeatureInformationTitle from "../utils/getFeatureInformationTitle";
|
|
60
61
|
import { getRadius } from "../utils/getRadius";
|
|
@@ -98,6 +99,7 @@ const realtimeLayerProps = {
|
|
|
98
99
|
bboxParameters: {
|
|
99
100
|
line_tags: "RVF",
|
|
100
101
|
},
|
|
102
|
+
fullTrajectoryStyle: fullTrajectoryStyle,
|
|
101
103
|
style: realtimeRVFStyle,
|
|
102
104
|
styleOptions: {
|
|
103
105
|
getBgColor: getBgColor,
|
|
@@ -513,10 +515,10 @@ function RvfMobilityMap({
|
|
|
513
515
|
title={RVF_LAYERS_TITLES.sharedMobility}
|
|
514
516
|
/>
|
|
515
517
|
|
|
516
|
-
<div className="absolute inset-x-2 bottom-2 z-10 flex items-end justify-between gap-2 text-[10px]">
|
|
518
|
+
<div className="pointer-events-none absolute inset-x-2 bottom-2 z-10 flex items-end justify-between gap-2 text-[10px]">
|
|
517
519
|
<ScaleLine className="bg-slate-50/70" />
|
|
518
520
|
<Copyright
|
|
519
|
-
className="bg-slate-50/70"
|
|
521
|
+
className="pointer-events-auto bg-slate-50/70"
|
|
520
522
|
options={copyrightOptions}
|
|
521
523
|
/>
|
|
522
524
|
</div>
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { FeatureLike } from "ol/Feature";
|
|
2
|
+
|
|
3
|
+
import { Circle, Fill, Stroke, Style } from "ol/style";
|
|
4
|
+
|
|
5
|
+
const borderStyle = new Style({
|
|
6
|
+
image: new Circle({
|
|
7
|
+
fill: new Fill({
|
|
8
|
+
color: "#000000",
|
|
9
|
+
}),
|
|
10
|
+
radius: 5,
|
|
11
|
+
}),
|
|
12
|
+
stroke: new Stroke({
|
|
13
|
+
color: "#000000",
|
|
14
|
+
width: 6,
|
|
15
|
+
}),
|
|
16
|
+
zIndex: 2,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const fullTrajectoryStyle = (
|
|
20
|
+
feature: FeatureLike,
|
|
21
|
+
resolution: number,
|
|
22
|
+
options: { getBgColor: (type: string, line: { name: string }) => string },
|
|
23
|
+
): Style[] => {
|
|
24
|
+
let lineColor = "#ffffff"; // white
|
|
25
|
+
|
|
26
|
+
const type = feature.get("type");
|
|
27
|
+
let stroke = feature.get("stroke");
|
|
28
|
+
|
|
29
|
+
if (stroke && stroke[0] !== "#") {
|
|
30
|
+
stroke = `#${stroke}`;
|
|
31
|
+
}
|
|
32
|
+
console.log(feature.getProperties());
|
|
33
|
+
lineColor =
|
|
34
|
+
stroke || options?.getBgColor(type, { name: feature.get("line_name") });
|
|
35
|
+
|
|
36
|
+
// Don't allow white lines, use red instead.
|
|
37
|
+
lineColor = /#ffffff/i.test(lineColor) ? "#ff0000" : lineColor;
|
|
38
|
+
|
|
39
|
+
const style = [
|
|
40
|
+
borderStyle,
|
|
41
|
+
new Style({
|
|
42
|
+
image: new Circle({
|
|
43
|
+
fill: new Fill({
|
|
44
|
+
color: lineColor,
|
|
45
|
+
}),
|
|
46
|
+
radius: 4,
|
|
47
|
+
}),
|
|
48
|
+
stroke: new Stroke({
|
|
49
|
+
color: lineColor,
|
|
50
|
+
width: 4,
|
|
51
|
+
}),
|
|
52
|
+
zIndex: 3,
|
|
53
|
+
}),
|
|
54
|
+
];
|
|
55
|
+
return style;
|
|
56
|
+
};
|
|
57
|
+
export default fullTrajectoryStyle;
|
|
@@ -2,6 +2,8 @@ import getDelayColor from "./getDelayColor";
|
|
|
2
2
|
|
|
3
3
|
describe("getDelayColor", () => {
|
|
4
4
|
it("returns green", () => {
|
|
5
|
+
expect(getDelayColor(0.5 * 60 * 1000)).toBe("transparent");
|
|
6
|
+
expect(getDelayColor(2.49 * 60 * 1000)).toBe("transparent");
|
|
5
7
|
expect(getDelayColor(0)).toBe("transparent");
|
|
6
8
|
});
|
|
7
9
|
// it("returns yellow", () => {
|
|
@@ -9,8 +11,7 @@ describe("getDelayColor", () => {
|
|
|
9
11
|
// expect(getDelayColor(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
|
|
10
12
|
// });
|
|
11
13
|
it("returns orange", () => {
|
|
12
|
-
expect(getDelayColor(
|
|
13
|
-
expect(getDelayColor(2.49 * 60 * 1000)).toBe("#ea580c");
|
|
14
|
+
expect(getDelayColor(3 * 60 * 1000)).toBe("#ea580c");
|
|
14
15
|
expect(getDelayColor(5 * 60 * 1000)).toBe("#ea580c");
|
|
15
16
|
});
|
|
16
17
|
it("returns red", () => {
|
|
@@ -10,7 +10,7 @@ const getDelayColor = (timeInMs: number, isText = false) => {
|
|
|
10
10
|
if (minutes > 5) {
|
|
11
11
|
return "#dc2626"; // "text-red-600";
|
|
12
12
|
}
|
|
13
|
-
if (minutes >=
|
|
13
|
+
if (minutes >= 3) {
|
|
14
14
|
return "#ea580c"; // "text-orange-600";
|
|
15
15
|
// return "#d97706"; // "text-amber-600";
|
|
16
16
|
}
|
|
@@ -11,6 +11,7 @@ describe("getDelayColorForVehicle", () => {
|
|
|
11
11
|
|
|
12
12
|
it("returns transparent", () => {
|
|
13
13
|
expect(getDelayColorForVehicle(0)).toBe("transparent");
|
|
14
|
+
expect(getDelayColorForVehicle(1 * 60 * 1000)).toBe("transparent");
|
|
14
15
|
expect(getDelayColorForVehicle(0.4 * 60 * 1000)).toBe("transparent");
|
|
15
16
|
});
|
|
16
17
|
// it("returns green", () => {
|
|
@@ -22,7 +23,6 @@ describe("getDelayColorForVehicle", () => {
|
|
|
22
23
|
// expect(getDelayColorForVehicle(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
|
|
23
24
|
// });
|
|
24
25
|
it("returns orange", () => {
|
|
25
|
-
expect(getDelayColorForVehicle(1 * 60 * 1000)).toBe("#ea580c");
|
|
26
26
|
expect(getDelayColorForVehicle(3 * 60 * 1000)).toBe("#ea580c");
|
|
27
27
|
expect(getDelayColorForVehicle(4.49 * 60 * 1000 - 1)).toBe("#ea580c");
|
|
28
28
|
expect(getDelayColorForVehicle(5 * 60 * 1000)).toBe("#ea580c");
|