Skip to content

Commit

Permalink
Merge pull request #4110 from LukasLohoff/layervisibility-callback
Browse files Browse the repository at this point in the history
Add optional layer visibility change callback
  • Loading branch information
LukasLohoff authored Nov 7, 2024
2 parents 2bef78c + 7323b86 commit 4a8185f
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/LayerTree/LayerTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ interface OwnProps {
* the layer instance of the current tree node.
*/
nodeTitleRenderer?: (layer: OlLayerBase) => React.ReactNode;

/**
* Callback function that will be called if the selection changes.
*/
onLayerVisibilityChanged?: (layer: OlLayerBase, checked: boolean) => void;
}

const defaultClassName = `${CSS_PREFIX}layertree`;
Expand All @@ -57,6 +62,7 @@ const LayerTree: React.FC<LayerTreeProps> = ({
layerGroup,
nodeTitleRenderer,
filterFunction,
onLayerVisibilityChanged,
checkable = true,
draggable = true,
...passThroughProps
Expand Down Expand Up @@ -245,7 +251,11 @@ const LayerTree: React.FC<LayerTreeProps> = ({
}

setLayerVisibility(layer, checked);
}, [map, setLayerVisibility]);

if (_isFunction(onLayerVisibilityChanged)) {
onLayerVisibilityChanged(layer, checked);
}
}, [map, setLayerVisibility, onLayerVisibilityChanged]);

const onDrop = useCallback((info: NodeDragEventParams<DataNode> & {
dragNode: EventDataNode<DataNode>;
Expand Down

0 comments on commit 4a8185f

Please sign in to comment.