Trigger onStyleChange when leyers are toggled
This commit is contained in:
parent
ad819d9141
commit
38fdaa7404
1 changed files with 5 additions and 5 deletions
|
@ -48,6 +48,9 @@ export function useMapStyle(
|
||||||
const enabledLayers = Object.entries(layers).filter(
|
const enabledLayers = Object.entries(layers).filter(
|
||||||
([, { enabled }]) => enabled
|
([, { enabled }]) => enabled
|
||||||
);
|
);
|
||||||
|
const layerIds = enabledLayers.map(
|
||||||
|
([layer, { opacity }]) => `${layer}-${opacity}`
|
||||||
|
);
|
||||||
const style = useMemo(
|
const style = useMemo(
|
||||||
() =>
|
() =>
|
||||||
getMapStyle(
|
getMapStyle(
|
||||||
|
@ -57,13 +60,10 @@ export function useMapStyle(
|
||||||
enabledLayers.map(([layer, { opacity }]) => [layer, opacity])
|
enabledLayers.map(([layer, { opacity }]) => [layer, opacity])
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
[
|
[styleId, layerIds]
|
||||||
styleId,
|
|
||||||
enabledLayers.map(([layer, { opacity }]) => `${layer}-${opacity}`)
|
|
||||||
]
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => onStyleChange(), [styleId, cadastreEnabled]);
|
useEffect(() => onStyleChange(), [styleId, layerIds, cadastreEnabled]);
|
||||||
|
|
||||||
return { style, layers, setStyle, setLayerEnabled, setLayerOpacity };
|
return { style, layers, setStyle, setLayerEnabled, setLayerOpacity };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue