@geops/rvf-mobility-web-component 0.1.73 → 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/.vscode/settings.json +2 -0
- package/.yarnrc.yml +1 -0
- package/CHANGELOG.md +7 -0
- package/index.js +7 -4
- package/package.json +2 -2
- package/src/MobilityNotifications/MobilityNotifications.tsx +9 -4
- package/src/RvfFeatureDetails/RvfLineNetworkDetails/RvfLineNetworkDetails.tsx +0 -2
- package/src/RvfSingleClickListener/RvfSingleClickListener.tsx +0 -2
- package/src/SituationDetails/SituationDetails.tsx +1 -0
- package/src/utils/hooks/useInitialPermalink.tsx +1 -1
- package/src/utils/hooks/useLnpLineInfo.tsx +97 -0
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.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.
|
|
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
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
publicAt:
|
|
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
|
}
|
|
@@ -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) => {
|
|
@@ -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;
|