feat(workbench): align v2 GIS and SCADA API
This commit is contained in:
@@ -12,7 +12,7 @@ import { SOURCE_LAYERS, type WaterNetworkSourceId } from "../map/sources";
|
||||
|
||||
export type MapFeatureInteractionState = {
|
||||
source: WaterNetworkSourceId;
|
||||
sourceLayer: string;
|
||||
sourceLayer?: string;
|
||||
id: string;
|
||||
hovered: boolean;
|
||||
selected: boolean;
|
||||
@@ -25,7 +25,9 @@ export function toMapFeatureReference(
|
||||
feature: Pick<DetailFeature, "id" | "layer"> | null
|
||||
): FeatureReference | null {
|
||||
if (!feature?.id) return null;
|
||||
return { source: feature.layer, sourceLayer: SOURCE_LAYERS[feature.layer], id: feature.id };
|
||||
return feature.layer === "scada"
|
||||
? { source: feature.layer, id: feature.id }
|
||||
: { source: feature.layer, sourceLayer: SOURCE_LAYERS[feature.layer], id: feature.id };
|
||||
}
|
||||
|
||||
export function setMapFeatureInteractionState(
|
||||
@@ -33,10 +35,7 @@ export function setMapFeatureInteractionState(
|
||||
feature: FeatureReference,
|
||||
state: Partial<Pick<MapFeatureInteractionState, "hovered" | "selected">>
|
||||
) {
|
||||
map.setFeatureState(
|
||||
{ source: feature.source, sourceLayer: feature.sourceLayer, id: feature.id },
|
||||
state
|
||||
);
|
||||
map.setFeatureState(toFeatureStateTarget(feature), state);
|
||||
}
|
||||
|
||||
export function clearMapFeatureInteractionState(
|
||||
@@ -44,10 +43,7 @@ export function clearMapFeatureInteractionState(
|
||||
feature: FeatureReference,
|
||||
key?: "hovered" | "selected"
|
||||
) {
|
||||
map.removeFeatureState(
|
||||
{ source: feature.source, sourceLayer: feature.sourceLayer, id: feature.id },
|
||||
key
|
||||
);
|
||||
map.removeFeatureState(toFeatureStateTarget(feature), key);
|
||||
}
|
||||
|
||||
type UseMapInteractionsOptions = {
|
||||
@@ -81,7 +77,9 @@ export function useMapInteractions({
|
||||
const id = feature && getFeatureId(feature);
|
||||
if (!source || !id) return;
|
||||
|
||||
const next = { source, sourceLayer: SOURCE_LAYERS[source], id };
|
||||
const next = source === "scada"
|
||||
? { source, id }
|
||||
: { source, sourceLayer: SOURCE_LAYERS[source], id };
|
||||
if (selectedFeature?.id === id && selectedFeature.layer === source) {
|
||||
clearHoveredFeature();
|
||||
return;
|
||||
@@ -127,3 +125,9 @@ export function useMapInteractions({
|
||||
};
|
||||
}, [mapReady, mapRef, selectedFeature]);
|
||||
}
|
||||
|
||||
function toFeatureStateTarget(feature: FeatureReference) {
|
||||
return feature.sourceLayer
|
||||
? { source: feature.source, sourceLayer: feature.sourceLayer, id: feature.id }
|
||||
: { source: feature.source, id: feature.id };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user