Skip to content

Commit

Permalink
chore(web): fix the layer delete behavior (#666)
Browse files Browse the repository at this point in the history
  • Loading branch information
keiya01 authored Sep 7, 2023
1 parent df854f8 commit e91a249
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions web/src/beta/lib/core/Map/Layers/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,7 @@ export default function useHooks({
],
);

const prevLayers = useRef<Layer[] | undefined>([]);
useLayoutEffect(() => {
const ids = new Set<string>();

Expand All @@ -556,14 +557,16 @@ export default function useHooks({
layerMap.set(l.id, l);
});

const deleted = Array.from(atomMap.keys()).filter(k => !ids.has(k));
deleted.forEach(k => {
const deleted = prevLayers.current?.filter(l => !ids.has(l.id)).map(l => l.id);
deleted?.forEach(k => {
atomMap.delete(k);
layerMap.delete(k);
lazyLayerMap.delete(k);
showLayer(k);
});
setOverridenLayers(layers => layers.filter(l => !deleted.includes(l.id)));
setOverridenLayers(layers => layers.filter(l => !deleted?.includes(l.id)));

prevLayers.current = layers;
}, [atomMap, layers, layerMap, lazyLayerMap, setOverridenLayers, showLayer]);

useEffect(() => {
Expand Down

0 comments on commit e91a249

Please sign in to comment.