@geops/rvf-mobility-web-component 0.1.72 → 0.1.74

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.72",
5
+ "version": "0.1.74",
6
6
  "homepage": "https://rvf-mobility-web-component-geops.vercel.app/",
7
7
  "type": "module",
8
8
  "main": "index.js",
@@ -12,7 +12,7 @@
12
12
  "jspdf": "^3.0.3",
13
13
  "lodash.debounce": "^4.0.8",
14
14
  "maplibre-gl": "^5.9.0",
15
- "mobility-toolbox-js": "3.4.4",
15
+ "mobility-toolbox-js": "3.4.5",
16
16
  "ol": "^10.6.1",
17
17
  "preact": "^10.27.2",
18
18
  "preact-custom-element": "^4.5.1",
@@ -28,6 +28,11 @@ function MobilityNotifications({
28
28
  const [situations, setSituations] = useState<SituationType[]>([]);
29
29
 
30
30
  useEffect(() => {
31
+ // Rounded to minutes for caching purposes
32
+ const now = new Date();
33
+ now.setMilliseconds(0);
34
+ now.setSeconds(0);
35
+
31
36
  new MocoAPI({
32
37
  apiKey: apikey || undefined,
33
38
  tenant: notificationtenant,
@@ -35,10 +40,10 @@ function MobilityNotifications({
35
40
  })
36
41
  .export({
37
42
  contentMedium: true,
38
- graph:
39
- "np_topo4,np_topo5,np_topo6,np_topo7,np_topo8,np_topo9,np_topo10,np_topo11,np_topo12,np_topo13,np_topo14,np_topo15,osm",
40
- hasGeoms: true,
41
- publicAt: new Date().toISOString(),
43
+ includeGeoms: false,
44
+ includeLines: true,
45
+ includeStops: true,
46
+ publicAt: now.toISOString(),
42
47
  })
43
48
  .then((data) => {
44
49
  if (data?.paginatedSituations?.results) {
@@ -85,7 +85,6 @@ function LinesNetworkPlanDetails({
85
85
  ),
86
86
  ]
87
87
  .filter((id) => {
88
- // console.log("ID", id, lineInfos);
89
88
  return !!id && !!lineInfos?.[id];
90
89
  })
91
90
  .forEach((id) => {
@@ -129,7 +128,6 @@ function LinesNetworkPlanDetails({
129
128
  return byLineId;
130
129
  }, [features]);
131
130
 
132
- // console.log("ICI", features, lineInfos, lineInfosByOperator);
133
131
  if (!features?.length || !lineInfos) {
134
132
  return null;
135
133
  }
@@ -237,7 +237,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
237
237
  layerTreeTitle: (title) => {
238
238
  return (
239
239
  <div className="flex items-center justify-between gap-2">
240
- {t(title)}
240
+ {t(title) || title}
241
241
  <Bicycle />
242
242
  </div>
243
243
  );
@@ -254,7 +254,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
254
254
  layerTreeTitle: (title) => {
255
255
  return (
256
256
  <div className="flex items-center justify-between gap-2">
257
- {t(title)}
257
+ {t(title) || title}
258
258
  <Bicycle />
259
259
  </div>
260
260
  );
@@ -274,7 +274,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
274
274
  layerTreeTitle: (title) => {
275
275
  return (
276
276
  <div className="flex items-center justify-between gap-2">
277
- {t(title)}
277
+ {t(title) || title}
278
278
  <CargoBike />
279
279
  </div>
280
280
  );
@@ -291,7 +291,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
291
291
  layerTreeTitle: (title) => {
292
292
  return (
293
293
  <div className="flex items-center justify-between gap-2">
294
- {t(title)}
294
+ {t(title) || title}
295
295
  <CargoBike />
296
296
  </div>
297
297
  );
@@ -308,7 +308,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
308
308
  layerTreeTitle: (title) => {
309
309
  return (
310
310
  <div className="flex items-center justify-between gap-2">
311
- {t(title)}
311
+ {t(title) || title}
312
312
  <Car />
313
313
  </div>
314
314
  );
@@ -325,7 +325,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
325
325
  layerTreeTitle: (title) => {
326
326
  return (
327
327
  <div className="flex items-center justify-between gap-2">
328
- {t(title)}
328
+ {t(title) || title}
329
329
  <Car />
330
330
  </div>
331
331
  );
@@ -342,7 +342,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
342
342
  layerTreeTitle: (title) => {
343
343
  return (
344
344
  <div className="flex items-center justify-between gap-2">
345
- {t(title)}
345
+ {t(title) || title}
346
346
  <Car />
347
347
  </div>
348
348
  );
@@ -359,7 +359,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
359
359
  layerTreeTitle: (title) => {
360
360
  return (
361
361
  <div className="flex items-center justify-between gap-2">
362
- {t(title)}
362
+ {t(title) || title}
363
363
  <Scooter />
364
364
  </div>
365
365
  );
@@ -376,7 +376,7 @@ function RvfSharedMobilityLayerGroup(props: GroupOptions) {
376
376
  layerTreeTitle: (title) => {
377
377
  return (
378
378
  <div className="flex items-center justify-between gap-2">
379
- {t(title)}
379
+ {t(title) || title}
380
380
  <Ride />
381
381
  </div>
382
382
  );
@@ -154,7 +154,6 @@ function SingleClickListener({ eventNode }: { eventNode: HTMLElement }) {
154
154
  return f.features;
155
155
  });
156
156
 
157
- console.log(features);
158
157
  // Append more infos about the features
159
158
  for (const feature of features) {
160
159
  const clusterId = feature.get("cluster_id");
@@ -166,7 +165,6 @@ function SingleClickListener({ eventNode }: { eventNode: HTMLElement }) {
166
165
  .getSource<GeoJSONSource>(sourceId)
167
166
  ?.getClusterLeaves(clusterId, 1000, 0)) || [];
168
167
 
169
- console.log(leaves);
170
168
  feature.set(
171
169
  "clusterLeaves",
172
170
  leaves.map((l) => {
@@ -248,6 +248,7 @@ function SituationDetails({
248
248
  return (
249
249
  <img
250
250
  alt={label}
251
+ className={"h-fit"}
251
252
  key={absoluteUrl + label}
252
253
  src={absoluteUrl}
253
254
  title={label}
@@ -2,19 +2,19 @@ import { realtimeConfig } from "mobility-toolbox-js/ol";
2
2
 
3
3
  // mobility-portal config
4
4
  const trackerRadiusMapping = {
5
- 0: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 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3, 3, 4, 6, 7, 7], // Funicular
13
+ 8: [0, 0, 0, 0, 0, 2, 2, 2, 2, 2, 2, 3, 3, 4, 6, 6, 6], // Long distance bus
14
+ 9: [0, 0, 0, 0, 0, 2, 2, 2, 2, 3, 3, 4, 4, 6, 7, 12, 15], // Rail
15
15
  };
16
16
 
17
- const radiusMapping: number[][] = trackerRadiusMapping;
17
+ const radiusMapping: Record<number, number[]> = trackerRadiusMapping;
18
18
  // [
19
19
  // [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
20
20
  // [0, 0, 0, 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7],
@@ -14,7 +14,7 @@ const useInitialPermalink = (
14
14
  const { permalinktemplate } = useMapContext();
15
15
  const props = useMemo(() => {
16
16
  const template = permalinkTemplate || permalinktemplate;
17
- console.log("template", template);
17
+
18
18
  if (!template) {
19
19
  return null;
20
20
  }
@@ -0,0 +1,97 @@
1
+ import { useEffect, useMemo } from "preact/hooks";
2
+
3
+ import { LNP_MD_LINES, LNP_MD_STOPS, LNP_SOURCE_ID } from "../constants";
4
+
5
+ import useMapContext from "./useMapContext";
6
+
7
+ import type { VectorTileSource } from "maplibre-gl";
8
+
9
+ export interface LineInfo {
10
+ color: string;
11
+ external_id: string;
12
+ id: string;
13
+ long_name: string;
14
+ mot: string;
15
+ operator_name: string;
16
+ runs: number;
17
+ short_name: string;
18
+ text_color: string;
19
+ }
20
+
21
+ export interface StopInfo {
22
+ external_id: string;
23
+ importance: number;
24
+ long_name: string;
25
+ short_name: string;
26
+ visibility_level: number;
27
+ }
28
+
29
+ export type LinesInfos = Record<string, LineInfo>;
30
+ export type StopsInfos = Record<string, StopInfo>;
31
+
32
+ let cacheLnpSourceInfo: {
33
+ [LNP_MD_LINES]: LinesInfos;
34
+ [LNP_MD_STOPS]: StopsInfos;
35
+ } = null;
36
+
37
+ export function useLnpSourceInfos() {
38
+ const { baseLayer } = useMapContext();
39
+
40
+ const sourceUrl = useMemo(() => {
41
+ return baseLayer?.mapLibreMap?.getSource<VectorTileSource>(LNP_SOURCE_ID)
42
+ ?.url;
43
+ }, [baseLayer]);
44
+
45
+ useEffect(() => {
46
+ const abortController = new AbortController();
47
+ const fetchInfos = async (url) => {
48
+ if (!cacheLnpSourceInfo) {
49
+ const response = await fetch(url, { signal: abortController.signal });
50
+ const data = await response.json();
51
+ cacheLnpSourceInfo = data;
52
+ }
53
+ };
54
+ if (sourceUrl) {
55
+ void fetchInfos(sourceUrl);
56
+ }
57
+ return () => {
58
+ abortController?.abort();
59
+ };
60
+ }, [sourceUrl]);
61
+
62
+ return cacheLnpSourceInfo;
63
+ }
64
+
65
+ export function useLnpLinesInfos(): LinesInfos {
66
+ const infos = useLnpSourceInfos();
67
+ return infos?.[LNP_MD_LINES];
68
+ }
69
+
70
+ export function useLnpStopsInfos(): StopsInfos {
71
+ const infos = useLnpSourceInfos();
72
+ return infos?.[LNP_MD_STOPS];
73
+ }
74
+
75
+ /**
76
+ * This hook search lines informations from lnp data. It takes a string in
77
+ * parameter then it will search if there is a property that exactly match this value.
78
+ */
79
+ function useLnpLineInfo(text: string): LineInfo {
80
+ const linesInfos = useLnpLinesInfos();
81
+
82
+ if (!linesInfos) {
83
+ return null;
84
+ }
85
+
86
+ if (linesInfos[text]) {
87
+ return linesInfos[text];
88
+ }
89
+
90
+ return Object.values(linesInfos).find((info) => {
91
+ return ["id", "external_id", "short_name", "long_name"].find((key) => {
92
+ return info[key] === text;
93
+ });
94
+ });
95
+ }
96
+
97
+ export default useLnpLineInfo;
@@ -385,7 +385,7 @@ const realtimeRVFStyle: RealtimeStyleFunction = (
385
385
  delayText = getDelayTextCanvas(
386
386
  text,
387
387
  fontSize,
388
- getDelayFont(fontSize, text),
388
+ getDelayFont(hover || viewState.zoom >= 13 ? fontSize : 0, text), // Only display delay labels on zoom 13+
389
389
  getDelayColor(delay, cancelled, true),
390
390
  delayOutlineColor,
391
391
  pixelRatio,