Skip to content

Commit

Permalink
fix(map): Prevent map from resetting to default layers
Browse files Browse the repository at this point in the history
SKY30-505
  • Loading branch information
clementprdhomme committed Oct 31, 2024
1 parent d43f0ee commit 1176c31
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions frontend/src/containers/map/content/map/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,18 @@ const MainMap: FCWithMessages = () => {
}
);

const previousDefaultLayersRef = useRef(defaultLayers);

// Once we have fetched from the CMS which layers are active by default, we set toggle them on, if
// there are already no layers in the URL
// there are already no layers in the URL and we've just fetched
// That last condition is important because we don't want to activate the default layers if the
// user manually remove all the layers from the map
useEffect(() => {
if (defaultLayers && mapLayers.length === 0) {
if (!previousDefaultLayersRef.current && defaultLayers && mapLayers.length === 0) {
setMapLayers(defaultLayers);
}

previousDefaultLayersRef.current = defaultLayers;
}, [mapLayers, setMapLayers, defaultLayers]);

const safelyResetFeatureState = useCallback(() => {
Expand Down

0 comments on commit 1176c31

Please sign in to comment.