Merge pull request #6331 from tchak/fix-cadastres-again

Trigger onStyleChange when leyers are toggled
This commit is contained in:
krichtof 2021-07-07 16:53:44 +02:00 committed by GitHub
commit 5000a09451
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,6 +48,9 @@ export function useMapStyle(
const enabledLayers = Object.entries(layers).filter(
([, { enabled }]) => enabled
);
const layerIds = enabledLayers.map(
([layer, { opacity }]) => `${layer}-${opacity}`
);
const style = useMemo(
() =>
getMapStyle(
@ -57,13 +60,10 @@ export function useMapStyle(
enabledLayers.map(([layer, { opacity }]) => [layer, opacity])
)
),
[
styleId,
enabledLayers.map(([layer, { opacity }]) => `${layer}-${opacity}`)
]
[styleId, layerIds]
);
useEffect(() => onStyleChange(), [styleId, cadastreEnabled]);
useEffect(() => onStyleChange(), [styleId, layerIds, cadastreEnabled]);
return { style, layers, setStyle, setLayerEnabled, setLayerOpacity };
}