Skip to content

Commit

Permalink
feat: add optional layer visibility change callback
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasLohoff committed Nov 7, 2024
1 parent a7554b2 commit 1cf736c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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,6 +251,10 @@ const LayerTree: React.FC<LayerTreeProps> = ({
}

setLayerVisibility(layer, checked);

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

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

0 comments on commit 1cf736c

Please sign in to comment.