Skip to content

Missing displayInLayerSwitcher prop in layers and layergroup #412

Closed
@ravsdev

Description

@ravsdev

Describe the bug
There is no way to hide layers from Layer Switcher Control. Add property displayInLayerSwitcher="false" to the layer component does nothing.

Stackblitz Fork

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions