Closed
Description
Describe the bug
There is no way to hide layers from Layer Switcher Control. Add property displayInLayerSwitcher="false" to the layer component does nothing.
Affected version(s)
├── [email protected]
├── [email protected]
├── [email protected]
├── [email protected]
└── [email protected]
Fix
Add prop to src/types.ts file:
export type LayerSwitcherOptions = {
openInLayerSwitcher?: boolean;
title?: string;
name?: string;
allwaysOnTop?: boolean; // typo in original code, see https://github.com/Viglino/ol-ext/issues/1128
baseLayer?: boolean;
displayInLayerSwitcher: boolean; //Added prop
};
That change makes all layers displayInLayerSwitcher to false, so they won't display unless the property is indicated on the layer, so src/components/layers/LayersCommonProps.ts may be modified to:
export const layersCommonDefaultProps: Options<Source> & LayerSwitcherOptions =
{
className: "ol-layer",
opacity: 1,
visible: true,
displayInLayerSwitcher: true, //Added default value
};
And src/components/layers/OlLayerGroup.vue:
type Props = Options & LayerSwitcherOptions;
const props = withDefaults(defineProps<Props>(), {
opacity: 1,
visible: true,
displayInLayerSwitcher: true, //Added default value
properties: () => ({}),
});
Not sure if it's the best fix, but it works as expected.
Temporal Fix
Add property to layer on mounted component, see code in the StackBlitz fork:
Stackblitz Fork