@geops/rvf-mobility-web-component 0.1.73 → 0.1.75
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 +28 -0
- package/README.md +17 -55
- package/docutils.js +1 -1
- package/index.html +9 -1
- package/index.js +115 -108
- package/package.json +2 -2
- package/src/FeatureDetails/FeatureDetails.tsx +9 -18
- package/src/LayerTreeMenu/LayerTreeMenu.tsx +1 -1
- package/src/LayoutState/LayoutState.tsx +14 -1
- package/src/LinesNetworkPlanDetails/LinesNetworkPlanDetails.tsx +37 -68
- package/src/LinesNetworkPlanLayerHighlight/LinesNetworkPlanLayerHighlight.tsx +1 -1
- package/src/MobilityMap/MobilityMap.tsx +1 -5
- package/src/MobilityMap/MobilityMapAttributes.ts +9 -5
- package/src/MobilityNotifications/MobilityNotifications.tsx +4 -4
- package/src/OverlayContent/OverlayContent.tsx +1 -2
- package/src/OverlayDetails/OverlayDetails.tsx +23 -2
- package/src/OverlayDetailsHeader/OverlayDetailsHeader.tsx +3 -0
- package/src/OverlayHeader/OverlayHeader.tsx +1 -1
- package/src/RvfFeatureDetails/RvfFeatureDetails.tsx +5 -4
- package/src/RvfFeatureDetails/RvfLineNetworkDetails/RvfLineNetworkDetails.tsx +0 -2
- package/src/RvfFeatureDetails/RvfSellingPointDetails/RvfSellingPointDetails.tsx +1 -1
- package/src/SituationDetails/SituationDetails.tsx +1 -0
- package/src/utils/constants.ts +2 -1
- package/src/utils/hooks/useInitialPermalink.tsx +1 -1
- package/src/utils/hooks/useLayersConfig.tsx +3 -0
- package/src/utils/hooks/useLnp.tsx +112 -0
- package/src/utils/hooks/useMapContext.tsx +4 -0
- package/src/RvfSingleClickListener/RvfSingleClickListener.tsx +0 -240
- package/src/RvfSingleClickListener/index.tsx +0 -1
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { useEffect, useState } 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
|
+
const [sourceUrl, setSourceUrl] = useState<string>(null);
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
const url =
|
|
43
|
+
baseLayer?.mapLibreMap?.getSource<VectorTileSource>(LNP_SOURCE_ID)?.url;
|
|
44
|
+
const onSourceData = (e) => {
|
|
45
|
+
if (e.sourceId === LNP_SOURCE_ID && e.isSourceLoaded) {
|
|
46
|
+
setSourceUrl(e.source?.url);
|
|
47
|
+
baseLayer?.mapLibreMap?.off("sourcedata", onSourceData);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
if (!url) {
|
|
51
|
+
baseLayer?.mapLibreMap?.on("sourcedata", onSourceData);
|
|
52
|
+
} else {
|
|
53
|
+
setSourceUrl(url);
|
|
54
|
+
}
|
|
55
|
+
return () => {
|
|
56
|
+
baseLayer?.mapLibreMap?.off("sourcedata", onSourceData);
|
|
57
|
+
};
|
|
58
|
+
}, [baseLayer?.mapLibreMap]);
|
|
59
|
+
|
|
60
|
+
useEffect(() => {
|
|
61
|
+
const abortController = new AbortController();
|
|
62
|
+
const fetchInfos = async (url: string) => {
|
|
63
|
+
if (!cacheLnpSourceInfo) {
|
|
64
|
+
const response = await fetch(url, { signal: abortController.signal });
|
|
65
|
+
const data = await response.json();
|
|
66
|
+
cacheLnpSourceInfo = data;
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
if (sourceUrl) {
|
|
70
|
+
void fetchInfos(sourceUrl);
|
|
71
|
+
}
|
|
72
|
+
return () => {
|
|
73
|
+
abortController?.abort();
|
|
74
|
+
};
|
|
75
|
+
}, [sourceUrl]);
|
|
76
|
+
|
|
77
|
+
return cacheLnpSourceInfo;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function useLnpLinesInfos(): LinesInfos {
|
|
81
|
+
const infos = useLnpSourceInfos();
|
|
82
|
+
return infos?.[LNP_MD_LINES];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function useLnpStopsInfos(): StopsInfos {
|
|
86
|
+
const infos = useLnpSourceInfos();
|
|
87
|
+
return infos?.[LNP_MD_STOPS];
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* This hook search line informations from lnp data. It takes a string in
|
|
92
|
+
* parameter then it will search if there is a property that exactly match this value.
|
|
93
|
+
*/
|
|
94
|
+
function useLnpLineInfo(text: string): LineInfo {
|
|
95
|
+
const linesInfos = useLnpLinesInfos();
|
|
96
|
+
|
|
97
|
+
if (!linesInfos || !text) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (linesInfos[text]) {
|
|
102
|
+
return linesInfos[text];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return Object.values(linesInfos).find((info) => {
|
|
106
|
+
return ["id", "external_id", "short_name", "long_name"].find((key) => {
|
|
107
|
+
return !!info[key] && info[key] === text;
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export default useLnpLineInfo;
|
|
@@ -50,6 +50,7 @@ export type MapContextType = {
|
|
|
50
50
|
linesNetworkPlanLayer: MaplibreStyleLayer;
|
|
51
51
|
map: Map;
|
|
52
52
|
mapsetLayer?: MapsetLayer;
|
|
53
|
+
notificationId?: string;
|
|
53
54
|
notificationsLayer?: MocoLayer;
|
|
54
55
|
permalinkUrlSearchParams: URLSearchParams;
|
|
55
56
|
previewNotifications?: SituationType[];
|
|
@@ -86,6 +87,7 @@ export type MapContextType = {
|
|
|
86
87
|
setLinesNetworkPlanLayer: (layer?: MaplibreStyleLayer) => void;
|
|
87
88
|
setMap: (map?: Map) => void;
|
|
88
89
|
setMapsetLayer: (mapsetLayer?: MapsetLayer) => void;
|
|
90
|
+
setNotificationId: (notificationId?: string) => void;
|
|
89
91
|
setNotificationsLayer: (notificationsLayer?: MocoLayer) => void;
|
|
90
92
|
setPermalinkUrlSearchParams: (
|
|
91
93
|
setPermalinkUrlSearchParams: URLSearchParams,
|
|
@@ -132,9 +134,11 @@ export const MapContext = createContext<MapContextType>({
|
|
|
132
134
|
setBaseLayer: (baseLayer?: MaplibreLayer) => {},
|
|
133
135
|
setIsFollowing: (isFollowing: boolean) => {},
|
|
134
136
|
setIsTracking: (isTracking: boolean) => {},
|
|
137
|
+
setLinesIds: (linesIds: string[]) => {},
|
|
135
138
|
setLinesNetworkPlanLayer: (linesNetworkPlanLayer: MaplibreStyleLayer) => {},
|
|
136
139
|
setMap: (map?: Map) => {},
|
|
137
140
|
setMapsetLayer: (mapsetLayer?: MapsetLayer) => {},
|
|
141
|
+
setNotificationId: (notificationId?: string) => {},
|
|
138
142
|
setNotificationsLayer: (notificationsLayer?: MocoLayer) => {},
|
|
139
143
|
setPermalinkUrlSearchParams: (
|
|
140
144
|
permalinkUrlSearchParams: URLSearchParams,
|
|
@@ -1,240 +0,0 @@
|
|
|
1
|
-
import { getFeatureInfoAtCoordinate } from "mobility-toolbox-js/ol";
|
|
2
|
-
import { GeoJSON } from "ol/format";
|
|
3
|
-
import { unByKey } from "ol/Observable";
|
|
4
|
-
import { useCallback, useEffect } from "preact/hooks";
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
LAYER_NAME_REALTIME,
|
|
8
|
-
LAYER_NAME_STATIONS,
|
|
9
|
-
PROVIDER_LOGOS_BY_FEED_ID,
|
|
10
|
-
} from "../utils/constants";
|
|
11
|
-
import useMapContext from "../utils/hooks/useMapContext";
|
|
12
|
-
import useRvfContext from "../utils/hooks/useRvfContext";
|
|
13
|
-
import MobilityEvent from "../utils/MobilityEvent";
|
|
14
|
-
import { fetchSharingStation } from "../utils/sharingGraphqlUtils";
|
|
15
|
-
|
|
16
|
-
import type { GeoJSONSource } from "maplibre-gl";
|
|
17
|
-
import type { Feature, MapBrowserEvent } from "ol";
|
|
18
|
-
|
|
19
|
-
const geojson = new GeoJSON();
|
|
20
|
-
|
|
21
|
-
function SingleClickListener({ eventNode }: { eventNode: HTMLElement }) {
|
|
22
|
-
const {
|
|
23
|
-
baseLayer,
|
|
24
|
-
map,
|
|
25
|
-
queryablelayers,
|
|
26
|
-
realtimeLayer,
|
|
27
|
-
setStationId,
|
|
28
|
-
setTrainId,
|
|
29
|
-
stationId,
|
|
30
|
-
stationsLayer,
|
|
31
|
-
tenant,
|
|
32
|
-
trainId,
|
|
33
|
-
} = useMapContext();
|
|
34
|
-
const { selectedFeature, setSelectedFeature, setSelectedFeatures } =
|
|
35
|
-
useRvfContext();
|
|
36
|
-
|
|
37
|
-
// Send the selctedFEature to the parent window
|
|
38
|
-
useEffect(() => {
|
|
39
|
-
eventNode?.dispatchEvent(
|
|
40
|
-
new MobilityEvent("mwc:selectedfeature", {
|
|
41
|
-
feature: selectedFeature
|
|
42
|
-
? geojson.writeFeatureObject(selectedFeature)
|
|
43
|
-
: null,
|
|
44
|
-
}),
|
|
45
|
-
);
|
|
46
|
-
}, [eventNode, selectedFeature]);
|
|
47
|
-
|
|
48
|
-
const onPointerMove = useCallback(
|
|
49
|
-
(evt: MapBrowserEvent<PointerEvent>) => {
|
|
50
|
-
const [realtimeFeature] = evt.map.getFeaturesAtPixel(evt.pixel, {
|
|
51
|
-
hitTolerance: 5,
|
|
52
|
-
layerFilter: (l) => {
|
|
53
|
-
return l === realtimeLayer;
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
realtimeLayer?.highlight(realtimeFeature as Feature);
|
|
57
|
-
|
|
58
|
-
const stationsFeatures = evt.map.getFeaturesAtPixel(evt.pixel, {
|
|
59
|
-
layerFilter: (l) => {
|
|
60
|
-
return l === stationsLayer;
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
const [stationFeature] = stationsFeatures.filter((feat) => {
|
|
65
|
-
return feat.get("tralis_network")?.includes(tenant);
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Send all the features under the cursor
|
|
69
|
-
const features = evt.map.getFeaturesAtPixel(evt.pixel, {
|
|
70
|
-
layerFilter: (l) => {
|
|
71
|
-
return queryablelayers
|
|
72
|
-
? queryablelayers.split(",").includes(l.get("name"))
|
|
73
|
-
: l.get("isQueryable");
|
|
74
|
-
},
|
|
75
|
-
}) as Feature[];
|
|
76
|
-
|
|
77
|
-
evt.map.getTargetElement().style.cursor =
|
|
78
|
-
realtimeFeature || stationFeature || features?.length
|
|
79
|
-
? "pointer"
|
|
80
|
-
: "default";
|
|
81
|
-
},
|
|
82
|
-
[queryablelayers, realtimeLayer, stationsLayer, tenant],
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const onSingleClick = useCallback(
|
|
86
|
-
async (evt: MapBrowserEvent<PointerEvent>) => {
|
|
87
|
-
if (!baseLayer?.mapLibreMap) {
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
const [realtimeFeature] = evt.map.getFeaturesAtPixel(evt.pixel, {
|
|
91
|
-
hitTolerance: 5,
|
|
92
|
-
layerFilter: (l) => {
|
|
93
|
-
return l === realtimeLayer;
|
|
94
|
-
},
|
|
95
|
-
}) as Feature[];
|
|
96
|
-
realtimeFeature?.set("layerName", LAYER_NAME_REALTIME);
|
|
97
|
-
|
|
98
|
-
const stationsFeatures = evt.map.getFeaturesAtPixel(evt.pixel, {
|
|
99
|
-
layerFilter: (l) => {
|
|
100
|
-
return l === stationsLayer;
|
|
101
|
-
},
|
|
102
|
-
});
|
|
103
|
-
const [stationFeature] = stationsFeatures.filter((feat) => {
|
|
104
|
-
return feat.get("tralis_network")?.includes(tenant);
|
|
105
|
-
}) as Feature[];
|
|
106
|
-
stationFeature?.set("layerName", LAYER_NAME_STATIONS);
|
|
107
|
-
|
|
108
|
-
const newStationId = stationFeature?.get("uid");
|
|
109
|
-
|
|
110
|
-
const newTrainId = realtimeFeature?.get("train_id");
|
|
111
|
-
|
|
112
|
-
if (newStationId && stationId !== newStationId) {
|
|
113
|
-
setStationId(newStationId);
|
|
114
|
-
setTrainId(null);
|
|
115
|
-
} else if (newTrainId && newTrainId !== trainId) {
|
|
116
|
-
setTrainId(realtimeFeature.get("train_id"));
|
|
117
|
-
setStationId(null);
|
|
118
|
-
} else {
|
|
119
|
-
setTrainId(null);
|
|
120
|
-
setStationId(null);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
// Send all the features under the cursor
|
|
124
|
-
// const features = evt.map.getFeaturesAtPixel(evt.pixel, {
|
|
125
|
-
// hitTolerance: 5,
|
|
126
|
-
// layerFilter: (l) => {
|
|
127
|
-
// console.log(queryablelayers);
|
|
128
|
-
// return queryablelayers
|
|
129
|
-
// ? queryablelayers.split(",").includes(l.get("name"))
|
|
130
|
-
// : l.get("isQueryable");
|
|
131
|
-
// },
|
|
132
|
-
// }) as Feature[];
|
|
133
|
-
|
|
134
|
-
const queryableLayers = evt.map.getAllLayers().filter((l) => {
|
|
135
|
-
return queryablelayers
|
|
136
|
-
? queryablelayers.split(",").includes(l.get("name"))
|
|
137
|
-
: l.get("isQueryable");
|
|
138
|
-
});
|
|
139
|
-
const featuresInfos = await getFeatureInfoAtCoordinate(
|
|
140
|
-
evt.coordinate,
|
|
141
|
-
queryableLayers,
|
|
142
|
-
5,
|
|
143
|
-
true,
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
// Set the layerName as property of the feature
|
|
147
|
-
featuresInfos.forEach((f) => {
|
|
148
|
-
f.features.forEach((feat) => {
|
|
149
|
-
feat.set("layerName", f.layer.get("name"));
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
const features = featuresInfos.flatMap((f) => {
|
|
154
|
-
return f.features;
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
console.log(features);
|
|
158
|
-
// Append more infos about the features
|
|
159
|
-
for (const feature of features) {
|
|
160
|
-
const clusterId = feature.get("cluster_id");
|
|
161
|
-
if (clusterId) {
|
|
162
|
-
const vtFeat = feature.get("vectorTileFeature");
|
|
163
|
-
const sourceId = vtFeat.layer.source;
|
|
164
|
-
const leaves =
|
|
165
|
-
(await baseLayer.mapLibreMap
|
|
166
|
-
.getSource<GeoJSONSource>(sourceId)
|
|
167
|
-
?.getClusterLeaves(clusterId, 1000, 0)) || [];
|
|
168
|
-
|
|
169
|
-
console.log(leaves);
|
|
170
|
-
feature.set(
|
|
171
|
-
"clusterLeaves",
|
|
172
|
-
leaves.map((l) => {
|
|
173
|
-
return geojson.readFeature(l);
|
|
174
|
-
}),
|
|
175
|
-
);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
// Sharing station
|
|
179
|
-
const sharingStationId = selectedFeature?.get("station_id");
|
|
180
|
-
if (sharingStationId) {
|
|
181
|
-
const sharingStationInfo =
|
|
182
|
-
await fetchSharingStation(sharingStationId);
|
|
183
|
-
selectedFeature.setProperties(sharingStationInfo);
|
|
184
|
-
selectedFeature.set(
|
|
185
|
-
"provider_logo",
|
|
186
|
-
PROVIDER_LOGOS_BY_FEED_ID[selectedFeature?.get("feed_id")],
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
if (newStationId || newTrainId || !features.length) {
|
|
192
|
-
setSelectedFeature(null);
|
|
193
|
-
setSelectedFeatures([]);
|
|
194
|
-
} else {
|
|
195
|
-
setSelectedFeatures(features);
|
|
196
|
-
|
|
197
|
-
// We prioritize some layers like the notification one over the others
|
|
198
|
-
const notificationFeature = features.find((feat) => {
|
|
199
|
-
return feat.get("situation");
|
|
200
|
-
});
|
|
201
|
-
if (notificationFeature) {
|
|
202
|
-
setSelectedFeature(notificationFeature);
|
|
203
|
-
} else {
|
|
204
|
-
setSelectedFeature(features[0]);
|
|
205
|
-
}
|
|
206
|
-
}
|
|
207
|
-
},
|
|
208
|
-
[
|
|
209
|
-
baseLayer?.mapLibreMap,
|
|
210
|
-
stationId,
|
|
211
|
-
trainId,
|
|
212
|
-
realtimeLayer,
|
|
213
|
-
stationsLayer,
|
|
214
|
-
tenant,
|
|
215
|
-
setStationId,
|
|
216
|
-
setTrainId,
|
|
217
|
-
queryablelayers,
|
|
218
|
-
selectedFeature,
|
|
219
|
-
setSelectedFeature,
|
|
220
|
-
setSelectedFeatures,
|
|
221
|
-
],
|
|
222
|
-
);
|
|
223
|
-
|
|
224
|
-
useEffect(() => {
|
|
225
|
-
const key = map?.on("singleclick", onSingleClick);
|
|
226
|
-
return () => {
|
|
227
|
-
unByKey(key);
|
|
228
|
-
};
|
|
229
|
-
}, [map, onSingleClick]);
|
|
230
|
-
|
|
231
|
-
useEffect(() => {
|
|
232
|
-
const key = map?.on("pointermove", onPointerMove);
|
|
233
|
-
return () => {
|
|
234
|
-
unByKey(key);
|
|
235
|
-
};
|
|
236
|
-
}, [map, onPointerMove]);
|
|
237
|
-
|
|
238
|
-
return null;
|
|
239
|
-
}
|
|
240
|
-
export default SingleClickListener;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { default } from "./RvfSingleClickListener";
|