From 38fdaa74049790e79550f0c630b53a860811f776 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Wed, 7 Jul 2021 16:23:55 +0200 Subject: [PATCH] Trigger onStyleChange when leyers are toggled --- .../components/shared/mapbox/MapStyleControl.jsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/javascript/components/shared/mapbox/MapStyleControl.jsx b/app/javascript/components/shared/mapbox/MapStyleControl.jsx index a94c07aa7..f6bc98a04 100644 --- a/app/javascript/components/shared/mapbox/MapStyleControl.jsx +++ b/app/javascript/components/shared/mapbox/MapStyleControl.jsx @@ -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 }; }