fix: hide unavailable GeoServer layers
This commit is contained in:
@@ -3,6 +3,7 @@ import type { Map as MapLibreMap } from "maplibre-gl";
|
||||
import type { ScadaDevice } from "../api/scada-client";
|
||||
import { useEffect, useRef, useSyncExternalStore, type RefObject } from "react";
|
||||
import { getResponsiveWorkbenchPadding } from "../map/camera";
|
||||
import type { WaterNetworkSourceId } from "../map/sources";
|
||||
import { WorkbenchMapController } from "../map/workbench-map-controller";
|
||||
|
||||
export function useWorkbenchMapController({
|
||||
@@ -12,7 +13,8 @@ export function useWorkbenchMapController({
|
||||
rightPanelOpen,
|
||||
conditionPanelExpanded = false,
|
||||
agentPanelWidth,
|
||||
getScadaFeatures
|
||||
getScadaFeatures,
|
||||
availableSourceIds
|
||||
}: {
|
||||
mapRef: RefObject<MapLibreMap | null>;
|
||||
mapReady: boolean;
|
||||
@@ -21,6 +23,7 @@ export function useWorkbenchMapController({
|
||||
conditionPanelExpanded?: boolean;
|
||||
agentPanelWidth?: number;
|
||||
getScadaFeatures?: (deviceIds?: string[], signal?: AbortSignal) => Promise<FeatureCollection<Point, ScadaDevice>>;
|
||||
availableSourceIds?: readonly WaterNetworkSourceId[];
|
||||
}) {
|
||||
const valuesRef = useRef({
|
||||
mapReady,
|
||||
@@ -63,6 +66,12 @@ export function useWorkbenchMapController({
|
||||
controller.getSnapshot,
|
||||
controller.getSnapshot
|
||||
);
|
||||
useEffect(() => {
|
||||
const target = state.target;
|
||||
if (target && availableSourceIds && !availableSourceIds.includes(target.sourceId)) {
|
||||
controller.clearHighlight();
|
||||
}
|
||||
}, [availableSourceIds, controller, state.target]);
|
||||
useEffect(() => () => controller.destroy(), [controller]);
|
||||
return { controller, state };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user