@geops/rvf-mobility-web-component 0.1.24-beta.0 → 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/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.25",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -55,7 +55,11 @@ 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";
59
+ import getBgColor from "../utils/getBgColor";
58
60
  import getFeatureInformationTitle from "../utils/getFeatureInformationTitle";
61
+ import { getRadius } from "../utils/getRadius";
62
+ import getTextColor from "../utils/getTextColor";
59
63
  import { I18nContext } from "../utils/hooks/useI18n";
60
64
  import useInitialLayersVisiblity from "../utils/hooks/useInitialLayersVisiblity";
61
65
  import { MapContext } from "../utils/hooks/useMapContext";
@@ -63,6 +67,7 @@ import { RvfContext } from "../utils/hooks/useRvfContext";
63
67
  import useUpdatePermalink from "../utils/hooks/useUpdatePermalink";
64
68
  import i18n from "../utils/i18n";
65
69
  import MobilityEvent from "../utils/MobilityEvent";
70
+ import realtimeRVFStyle from "../utils/realtimeRVFStyle";
66
71
  // @ts-expect-error bad type definition
67
72
  import style from "./index.css";
68
73
 
@@ -94,6 +99,13 @@ const realtimeLayerProps = {
94
99
  bboxParameters: {
95
100
  line_tags: "RVF",
96
101
  },
102
+ fullTrajectoryStyle: fullTrajectoryStyle,
103
+ style: realtimeRVFStyle,
104
+ styleOptions: {
105
+ getBgColor: getBgColor,
106
+ getRadius: getRadius,
107
+ getTextColor: getTextColor,
108
+ },
97
109
  };
98
110
 
99
111
  function RvfMobilityMap({
@@ -490,11 +502,11 @@ function RvfMobilityMap({
490
502
  {hasNotification && <NotificationLayer />}
491
503
  <RvfTarifZonenLayer title={RVF_LAYERS_TITLES.tarifzonen} />
492
504
  <RvfSellingPointsLayer
493
- isQueryable
505
+ isQueryable={false}
494
506
  title={RVF_LAYERS_TITLES.verkaufsstellen}
495
507
  />
496
508
  <RvfLineNetworkPlanLayer
497
- isQueryable
509
+ isQueryable={false}
498
510
  minZoom={10}
499
511
  title={RVF_LAYERS_TITLES.liniennetz}
500
512
  />
@@ -503,10 +515,10 @@ function RvfMobilityMap({
503
515
  title={RVF_LAYERS_TITLES.sharedMobility}
504
516
  />
505
517
 
506
- <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]">
507
519
  <ScaleLine className="bg-slate-50/70" />
508
520
  <Copyright
509
- className="bg-slate-50/70"
521
+ className="pointer-events-auto bg-slate-50/70"
510
522
  options={copyrightOptions}
511
523
  />
512
524
  </div>
@@ -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
+ };
@@ -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;
@@ -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,20 @@ 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.5 * 60 * 1000)).toBe("transparent");
6
+ expect(getDelayColor(2.49 * 60 * 1000)).toBe("transparent");
7
+ expect(getDelayColor(0)).toBe("transparent");
11
8
  });
9
+ // it("returns yellow", () => {
10
+ // expect(getDelayColor(3 * 60 * 1000)).toBe("#ca8a04");
11
+ // expect(getDelayColor(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
12
+ // });
12
13
  it("returns orange", () => {
14
+ expect(getDelayColor(3 * 60 * 1000)).toBe("#ea580c");
13
15
  expect(getDelayColor(5 * 60 * 1000)).toBe("#ea580c");
14
- expect(getDelayColor(9.49 * 60 * 1000 - 1)).toBe("#ea580c");
15
16
  });
16
17
  it("returns red", () => {
18
+ expect(getDelayColor(9.49 * 60 * 1000 - 1)).toBe("#dc2626");
17
19
  expect(getDelayColor(10 * 60 * 1000)).toBe("#dc2626");
18
20
  expect(getDelayColor(180 * 60 * 1000)).toBe("#dc2626");
19
21
  });
@@ -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 >= 3) {
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(1 * 60 * 1000)).toBe("transparent");
15
+ expect(getDelayColorForVehicle(0.4 * 60 * 1000)).toBe("transparent");
19
16
  });
17
+ // it("returns green", () => {
18
+ // expect(getDelayColorForVehicle(0)).toBe("#16a34a");
19
+ // expect(getDelayColorForVehicle(2.49 * 60 * 1000)).toBe("#16a34a");
20
+ // });
21
+ // it("returns yellow", () => {
22
+ // expect(getDelayColorForVehicle(3 * 60 * 1000)).toBe("#ca8a04");
23
+ // expect(getDelayColorForVehicle(4.49 * 60 * 1000 - 1)).toBe("#ca8a04");
24
+ // });
20
25
  it("returns orange", () => {
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;