@geops/rvf-mobility-web-component 0.1.24-beta.0 → 0.1.24

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-beta.0",
5
+ "version": "0.1.24",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -55,7 +55,10 @@ 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 getBgColor from "../utils/getBgColor";
58
59
  import getFeatureInformationTitle from "../utils/getFeatureInformationTitle";
60
+ import { getRadius } from "../utils/getRadius";
61
+ import getTextColor from "../utils/getTextColor";
59
62
  import { I18nContext } from "../utils/hooks/useI18n";
60
63
  import useInitialLayersVisiblity from "../utils/hooks/useInitialLayersVisiblity";
61
64
  import { MapContext } from "../utils/hooks/useMapContext";
@@ -63,6 +66,7 @@ import { RvfContext } from "../utils/hooks/useRvfContext";
63
66
  import useUpdatePermalink from "../utils/hooks/useUpdatePermalink";
64
67
  import i18n from "../utils/i18n";
65
68
  import MobilityEvent from "../utils/MobilityEvent";
69
+ import realtimeRVFStyle from "../utils/realtimeRVFStyle";
66
70
  // @ts-expect-error bad type definition
67
71
  import style from "./index.css";
68
72
 
@@ -94,6 +98,12 @@ const realtimeLayerProps = {
94
98
  bboxParameters: {
95
99
  line_tags: "RVF",
96
100
  },
101
+ style: realtimeRVFStyle,
102
+ styleOptions: {
103
+ getBgColor: getBgColor,
104
+ getRadius: getRadius,
105
+ getTextColor: getTextColor,
106
+ },
97
107
  };
98
108
 
99
109
  function RvfMobilityMap({
@@ -490,11 +500,11 @@ function RvfMobilityMap({
490
500
  {hasNotification && <NotificationLayer />}
491
501
  <RvfTarifZonenLayer title={RVF_LAYERS_TITLES.tarifzonen} />
492
502
  <RvfSellingPointsLayer
493
- isQueryable
503
+ isQueryable={false}
494
504
  title={RVF_LAYERS_TITLES.verkaufsstellen}
495
505
  />
496
506
  <RvfLineNetworkPlanLayer
497
- isQueryable
507
+ isQueryable={false}
498
508
  minZoom={10}
499
509
  title={RVF_LAYERS_TITLES.liniennetz}
500
510
  />
@@ -35,7 +35,6 @@ function SingleClickListener() {
35
35
  feature.setStyle(null);
36
36
  layer.getSource().addFeature(feature);
37
37
  if (vectorTileFeature) {
38
- console.log(vectorTileFeature);
39
38
  baseLayer?.mapLibreMap.setFeatureState(vectorTileFeature, {
40
39
  hover: true,
41
40
  });
@@ -243,7 +243,6 @@ function RvfSharedMobilityLayerGroup2(props: GroupOptions) {
243
243
  extent,
244
244
  abortController,
245
245
  );
246
- // console.log("scooterData", scooterData);
247
246
  setScooterData(scooterData);
248
247
  };
249
248
 
@@ -483,6 +482,7 @@ function RvfSharedMobilityLayerGroup2(props: GroupOptions) {
483
482
  sources: {
484
483
  [BIKE_FRELO_SOURCE_ID]: {
485
484
  data: { features: [], type: "FeatureCollection" },
485
+ // data: "https://api.mobidata-bw.de/geoserver/MobiData-BW/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=MobiData-BW%3Asharing_stations_bicycle&maxFeatures=20000&outputFormat=application/json",
486
486
  promoteId: "id",
487
487
  type: "geojson",
488
488
  },
@@ -16,7 +16,6 @@ export const RVF_EXTENT_3857 = transformExtent(
16
16
  "EPSG:4326",
17
17
  "EPSG:3857",
18
18
  );
19
- console.log(fromLonLat([7.844388, 47.991351]));
20
19
 
21
20
  // @ts-expect-error - testsdsd sd
22
21
  window.fromLonLat = fromLonLat;
@@ -155,3 +154,11 @@ export const PROVIDER_LOGOS_BY_FEED_ID = {
155
154
  yoio_freiburg: yoioLogo,
156
155
  zeus_freiburg: zeusLogo,
157
156
  };
157
+
158
+ export const LINE_COLOR_BY_NAME = {
159
+ "1": "#E8001B",
160
+ "2": "#13A538",
161
+ "3": "#F59E00",
162
+ "4": "#EA5297",
163
+ "5": "#008BC5",
164
+ };
@@ -1,3 +1,18 @@
1
1
  import { realtimeConfig } from "mobility-toolbox-js/ol";
2
2
 
3
- export default realtimeConfig.getBgColor;
3
+ import { LINE_COLOR_BY_NAME } from "./constants";
4
+
5
+ const getBgColor = (type, line) => {
6
+ if (type === "bus") {
7
+ return "#646363";
8
+ }
9
+ if (type === "tram") {
10
+ const lineColor = LINE_COLOR_BY_NAME[line?.name];
11
+ if (lineColor) {
12
+ return lineColor;
13
+ }
14
+ }
15
+ return realtimeConfig.getBgColor(type);
16
+ };
17
+
18
+ export default getBgColor;
@@ -2,18 +2,19 @@ import getDelayColor from "./getDelayColor";
2
2
 
3
3
  describe("getDelayColor", () => {
4
4
  it("returns green", () => {
5
- expect(getDelayColor(0)).toBe("#16a34a");
6
- expect(getDelayColor(2.49 * 60 * 1000)).toBe("#16a34a");
7
- });
8
- it("returns yellow", () => {
9
- expect(getDelayColor(3 * 60 * 1000)).toBe("#ca8a04");
10
- expect(getDelayColor(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
5
+ expect(getDelayColor(0)).toBe("transparent");
11
6
  });
7
+ // it("returns yellow", () => {
8
+ // expect(getDelayColor(3 * 60 * 1000)).toBe("#ca8a04");
9
+ // expect(getDelayColor(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
10
+ // });
12
11
  it("returns orange", () => {
12
+ expect(getDelayColor(0.5 * 60 * 1000)).toBe("#ea580c");
13
+ expect(getDelayColor(2.49 * 60 * 1000)).toBe("#ea580c");
13
14
  expect(getDelayColor(5 * 60 * 1000)).toBe("#ea580c");
14
- expect(getDelayColor(9.49 * 60 * 1000 - 1)).toBe("#ea580c");
15
15
  });
16
16
  it("returns red", () => {
17
+ expect(getDelayColor(9.49 * 60 * 1000 - 1)).toBe("#dc2626");
17
18
  expect(getDelayColor(10 * 60 * 1000)).toBe("#dc2626");
18
19
  expect(getDelayColor(180 * 60 * 1000)).toBe("#dc2626");
19
20
  });
@@ -2,22 +2,22 @@
2
2
  * Returns a color class to display the delay.
3
3
  * @param {Number} time Delay time in milliseconds.
4
4
  */
5
- const getDelayColor = (timeInMs: number) => {
5
+ const getDelayColor = (timeInMs: number, isText = false) => {
6
6
  // we use rounded value to fit the getDelayString method.
7
7
  const minutes = Math.round(timeInMs / 1000 / 60);
8
8
  // if (minutes >= 60) {
9
9
  // }
10
- if (minutes >= 10) {
10
+ if (minutes > 5) {
11
11
  return "#dc2626"; // "text-red-600";
12
12
  }
13
- if (minutes >= 5) {
13
+ if (minutes >= 1) {
14
14
  return "#ea580c"; // "text-orange-600";
15
15
  // return "#d97706"; // "text-amber-600";
16
16
  }
17
- if (minutes >= 3) {
18
- return "#ca8a04"; // "text-yellow-600";
19
- }
20
- return "#16a34a"; // "text-green-600";
17
+ // if (minutes >= 3) {
18
+ // return "#ca8a04"; // "text-yellow-600";
19
+ // }
20
+ return isText ? "#16a34a" : "transparent"; // "text-green-600";
21
21
  };
22
22
 
23
23
  export default getDelayColor;
@@ -6,22 +6,29 @@ describe("getDelayColorForVehicle", () => {
6
6
  expect(getDelayColorForVehicle(0, true, false)).toBe("#a0a0a0");
7
7
  });
8
8
  it("returns null delay (no realtime train) color", () => {
9
- expect(getDelayColorForVehicle(null)).toBe("#a0a0a0");
9
+ expect(getDelayColorForVehicle(null)).toBe("transparent");
10
10
  });
11
11
 
12
- it("returns green", () => {
13
- expect(getDelayColorForVehicle(0)).toBe("#16a34a");
14
- expect(getDelayColorForVehicle(2.49 * 60 * 1000)).toBe("#16a34a");
15
- });
16
- it("returns yellow", () => {
17
- expect(getDelayColorForVehicle(3 * 60 * 1000)).toBe("#ca8a04");
18
- expect(getDelayColorForVehicle(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
12
+ it("returns transparent", () => {
13
+ expect(getDelayColorForVehicle(0)).toBe("transparent");
14
+ expect(getDelayColorForVehicle(0.4 * 60 * 1000)).toBe("transparent");
19
15
  });
16
+ // it("returns green", () => {
17
+ // expect(getDelayColorForVehicle(0)).toBe("#16a34a");
18
+ // expect(getDelayColorForVehicle(2.49 * 60 * 1000)).toBe("#16a34a");
19
+ // });
20
+ // it("returns yellow", () => {
21
+ // expect(getDelayColorForVehicle(3 * 60 * 1000)).toBe("#ca8a04");
22
+ // expect(getDelayColorForVehicle(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
23
+ // });
20
24
  it("returns orange", () => {
25
+ expect(getDelayColorForVehicle(1 * 60 * 1000)).toBe("#ea580c");
26
+ expect(getDelayColorForVehicle(3 * 60 * 1000)).toBe("#ea580c");
27
+ expect(getDelayColorForVehicle(4.49 * 60 * 1000 - 1)).toBe("#ea580c");
21
28
  expect(getDelayColorForVehicle(5 * 60 * 1000)).toBe("#ea580c");
22
- expect(getDelayColorForVehicle(9.49 * 60 * 1000 - 1)).toBe("#ea580c");
23
29
  });
24
30
  it("returns red", () => {
31
+ expect(getDelayColorForVehicle(9.49 * 60 * 1000 - 1)).toBe("#dc2626");
25
32
  expect(getDelayColorForVehicle(10 * 60 * 1000)).toBe("#dc2626");
26
33
  expect(getDelayColorForVehicle(180 * 60 * 1000)).toBe("#dc2626");
27
34
  });
@@ -17,9 +17,9 @@ const getDelayColorForVehicle = (
17
17
  : "#a0a0a0"; // gray
18
18
  }
19
19
  if (delayInMs === null) {
20
- return "#a0a0a0";
20
+ return "transparent";
21
21
  }
22
- return getDelayColor(delayInMs);
22
+ return getDelayColor(delayInMs, isDelayText);
23
23
  };
24
24
 
25
25
  export default getDelayColorForVehicle;
@@ -10,12 +10,13 @@ import getBgColor from "./getBgColor";
10
10
 
11
11
  // This function returns the main color of a line using a line, trajectory, stopsequence or departure object.
12
12
  const getMainColorForVehicle = (object: unknown = null): string => {
13
- let color =
14
- (object as RealtimeTrajectory)?.properties?.line?.color ||
13
+ const line =
14
+ (object as RealtimeTrajectory)?.properties?.line ||
15
15
  // @ts-expect-error bad type definition
16
- (object as RealtimeStopSequence)?.line?.color ||
17
- (object as RealtimeLine)?.color;
16
+ (object as RealtimeStopSequence)?.line ||
17
+ (object as RealtimeLine);
18
18
 
19
+ let color = line?.color;
19
20
  if (!color) {
20
21
  let type: RealtimeMot =
21
22
  (object as RealtimeTrajectory)?.properties?.type ||
@@ -34,7 +35,7 @@ const getMainColorForVehicle = (object: unknown = null): string => {
34
35
  type = "rail";
35
36
  }
36
37
  }
37
- color = getBgColor(type) || getBgColor("rail");
38
+ color = getBgColor(type, line);
38
39
  }
39
40
 
40
41
  if (color && color[0] !== "#") {
@@ -0,0 +1,39 @@
1
+ import { realtimeConfig } from "mobility-toolbox-js/ol";
2
+
3
+ // mobility-portal config
4
+ // const trackerRadiusMapping = {
5
+ // 0: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 4, 4, 6, 7, 7, 7],
6
+ // 1: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 4, 4, 6, 7, 7, 7],
7
+ // 2: [0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 6, 7, 7, 7, 12, 12, 15],
8
+ // 3: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6],
9
+ // 4: [0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 6, 7, 7, 7, 12, 12, 15],
10
+ // 5: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 4, 4, 4, 7, 7, 7],
11
+ // 6: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 4, 4, 4, 7, 7, 7],
12
+ // 7: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 4, 4, 4, 7, 7, 7],
13
+ // 8: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 2, 2, 4, 6, 6, 6],
14
+ // 9: [0, 0, 0, 0, 0, 2, 2, 4, 4, 6, 6, 7, 7, 7, 12, 12, 15],
15
+ // };
16
+
17
+ const radiusMapping: number[][] = [
18
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
19
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
20
+ [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 7, 7, 7, 12, 12, 15], // [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 12, 15, 15, 15, 15, 15],
21
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
22
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
23
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
24
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
25
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
26
+ [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
27
+ [0, 0, 0, 0, 0, 2, 2, 3, 7, 7, 7, 7, 7, 7, 12, 12, 15],
28
+ ];
29
+
30
+ export const getRadius = (type = 0, zoom = 0, cancelled = false) => {
31
+ try {
32
+ // @ts-expect-error - bad type definition
33
+ const typeIdx = realtimeConfig.getTypeIndex(type);
34
+ return radiusMapping[typeIdx][zoom] * (cancelled ? 2 : 1);
35
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
36
+ } catch (e) {
37
+ return 1;
38
+ }
39
+ };
@@ -0,0 +1,10 @@
1
+ import { realtimeConfig } from "mobility-toolbox-js/ol";
2
+
3
+ const getTextColor = (type) => {
4
+ if (type === "bus" || type === "tram") {
5
+ return "#fff";
6
+ }
7
+ return realtimeConfig.getTextColor(type);
8
+ };
9
+
10
+ export default getTextColor;