@geops/rvf-mobility-web-component 0.1.24 → 0.1.26

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/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.24",
5
+ "version": "0.1.26",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -7,6 +7,7 @@ import {
7
7
  import { JSX, PreactDOMAttributes } from "preact";
8
8
 
9
9
  import getMainColorForVehicle from "../utils/getMainColorForVehicle";
10
+ import getTextColor from "../utils/getTextColor";
10
11
  import getTextFontForVehicle from "../utils/getTextFontForVehicle";
11
12
  import getTextForVehicle from "../utils/getTextForVehicle";
12
13
 
@@ -32,10 +33,11 @@ function RouteIcon({
32
33
  departure?.line ||
33
34
  stopSequence?.line ||
34
35
  trajectory?.properties?.line;
36
+ const type = stopSequence?.type || trajectory?.type;
35
37
  const backgroundColor = getMainColorForVehicle(
36
38
  line || departure || stopSequence || trajectory,
37
39
  );
38
- const color = lineToUse?.text_color || "black";
40
+ const color = lineToUse?.text_color || getTextColor(type);
39
41
  let borderColor = lineToUse?.stroke || "black";
40
42
  const text = getTextForVehicle(
41
43
  line || departure || stopSequence || trajectory,
@@ -50,7 +52,7 @@ function RouteIcon({
50
52
 
51
53
  return (
52
54
  <span
53
- className="flex h-[40px] min-w-[40px] items-center justify-center rounded-full border-2 px-1"
55
+ className="flex h-[40px] min-w-[40px] items-center justify-center rounded-full border px-1"
54
56
  style={{
55
57
  backgroundColor,
56
58
  borderColor,
@@ -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(0.5 * 60 * 1000)).toBe("#ea580c");
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 >= 1) {
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");