diff --git a/apps/web/components/map/panels/toolbox/tools/catchment-area/CatchmentArea.tsx b/apps/web/components/map/panels/toolbox/tools/catchment-area/CatchmentArea.tsx index 64a468a..5e9a35e 100644 --- a/apps/web/components/map/panels/toolbox/tools/catchment-area/CatchmentArea.tsx +++ b/apps/web/components/map/panels/toolbox/tools/catchment-area/CatchmentArea.tsx @@ -13,6 +13,7 @@ import { computePTCatchmentArea, } from "@/lib/api/catchmentArea"; import { useJobs } from "@/lib/api/jobs"; +import { useProjectLayers } from "@/lib/api/projects"; import { STREET_NETWORK_LAYER_ID } from "@/lib/constants"; import { setRunningJobIds } from "@/lib/store/jobs/slice"; import { @@ -71,6 +72,8 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => { const runningJobIds = useAppSelector((state) => state.jobs.runningJobIds); const [isBusy, setIsBusy] = useState(false); + const { layers: projectLayers } = useProjectLayers((projectId as string) || ""); + // Routing const { routingTypes, selectedRouting, setSelectedRouting } = useRoutingTypes(); @@ -216,6 +219,12 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => { // Scenario const { scenarioItems } = useScenarioItems(projectId as string); const [selectedScenario, setSelectedScenario] = useState(undefined); + const scenarioNetworkSystemLayer = useMemo(() => { + if (projectLayers) { + return projectLayers.find((layer) => layer.layer_id === STREET_NETWORK_LAYER_ID); + } + return undefined; + }, [projectLayers]); const handleReset = () => { dispatch(setMaskLayer(undefined)); @@ -230,14 +239,13 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => { const payload = { catchment_area_type: catchmentAreaShapeType.value, }; - if (selectedScenario?.value) { payload["scenario_id"] = selectedScenario?.value; // todo: Set street network layer for scenario. // At the moment this is hardcoded. // Eventually, users should be able to upload their own street network layer which can be used for scenarios. payload["street_network"] = { - edge_layer_project_id: STREET_NETWORK_LAYER_ID, + edge_layer_project_id: scenarioNetworkSystemLayer?.id, }; } @@ -555,7 +563,7 @@ const CatchmentArea = ({ onBack, onClose }: IndicatorBaseProps) => { /> {/* SCENARIO */} { baseOptions={ <> { setSelectedScenario(item as SelectorItem); diff --git a/apps/web/components/map/panels/toolbox/tools/nearby-stations/NearbyStations.tsx b/apps/web/components/map/panels/toolbox/tools/nearby-stations/NearbyStations.tsx index 2c4e2c0..169a46e 100644 --- a/apps/web/components/map/panels/toolbox/tools/nearby-stations/NearbyStations.tsx +++ b/apps/web/components/map/panels/toolbox/tools/nearby-stations/NearbyStations.tsx @@ -8,6 +8,7 @@ import { ICON_NAME } from "@p4b/ui/components/Icon"; import { useTranslation } from "@/i18n/client"; import { useJobs } from "@/lib/api/jobs"; +import { useProjectLayers } from "@/lib/api/projects"; import { computeNearbyStations } from "@/lib/api/tools"; import { STREET_NETWORK_LAYER_ID } from "@/lib/constants"; import { setRunningJobIds } from "@/lib/store/jobs/slice"; @@ -52,6 +53,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => { const startingPoints = useAppSelector((state) => state.map.toolboxStartingPoints); const runningJobIds = useAppSelector((state) => state.jobs.runningJobIds); const { projectId } = useParams(); + const { layers: projectLayers } = useProjectLayers((projectId as string) || ""); useEffect(() => { if (projectId) { @@ -121,6 +123,12 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => { // Scenario const { scenarioItems } = useScenarioItems(projectId as string); const [selectedScenario, setSelectedScenario] = useState(undefined); + const scenarioNetworkSystemLayer = useMemo(() => { + if (projectLayers) { + return projectLayers.find((layer) => layer.layer_id === STREET_NETWORK_LAYER_ID); + } + return undefined; + }, [projectLayers]); const handleRun = async () => { const payload = { @@ -140,7 +148,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => { // At the moment this is hardcoded. // Eventually, users should be able to upload their own street network layer which can be used for scenarios. payload["street_network"] = { - edge_layer_project_id: STREET_NETWORK_LAYER_ID, + edge_layer_project_id: scenarioNetworkSystemLayer?.id, }; } if (startingPointMethod.value === "map") { @@ -321,7 +329,7 @@ const NearbyStations = ({ onBack, onClose }: IndicatorBaseProps) => { {/* SCENARIO */} { <> { setSelectedScenario(item as SelectorItem); }}