Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: global layer exclusivity #1249

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions elements/layercontrol/src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export class EOxLayerControl extends LitElement {
addExternalLayers: { attribute: false },
unstyled: { type: Boolean },
styleOverride: { type: String },
isGloballyExclusive: { type: Boolean },
};

/**
Expand Down Expand Up @@ -133,6 +134,13 @@ export class EOxLayerControl extends LitElement {
* @type {String}
*/
this.styleOverride = "";

/**
* Enable global exclusivity for layers that is not restricted to a group
*
* @type {Boolean}
*/
this.isGloballyExclusive = false;
}

/**
Expand Down
37 changes: 37 additions & 0 deletions elements/layercontrol/src/methods/layer/input-click.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
const inputClickMethod = (evt, EOxLayerControlLayer) => {
const layer = EOxLayerControlLayer.layer; // The layer instance associated with the control.

console.log(layer);

// Set the visibility of the layer based on the input's checked state.
layer.setVisible(evt.target.checked);

Expand All @@ -31,6 +33,41 @@ const inputClickMethod = (evt, EOxLayerControlLayer) => {
});
}

//console.log(document.querySelector("eox-layercontrol").isGloballyExclusive);

// Handle globally exclusive layers
let layerControl = document.querySelector("eox-layercontrol");

if (evt.target.checked
&& layer.get("layerControlExclusive")
&& layerControl.isGloballyExclusive) {
console.log("Globally exclusive layer");
// *:has(> .layers > ul) { /* styles to apply to the tag */ }

// Find all exclusive layers across all groups
const allLayers = layerControl
.shadowRoot
.querySelectorAll("eox-layercontrol-layer");

const allExclusiveLayers = Array.from(allLayers)
.filter((layer) => layer.layer.get("layerControlExclusive"));

console.log("allExclusiveLayers", allExclusiveLayers);

/*allExclusiveLayers.forEach((exclusiveLayerElement) => {
const exclusiveLayer = exclusiveLayerElement.layer;

console.log("exclusiveLayer", exclusiveLayer);

// Ensure we don't hide the currently checked layer
if (exclusiveLayer !== layer) {
exclusiveLayer.setVisible(false);
exclusiveLayerElement.closest("eox-layercontrol-layer").requestUpdate();
}
});*/
}


// Dispatch a 'changed' event to signal a change in the layer's state.
EOxLayerControlLayer.dispatchEvent(
new CustomEvent("changed", { bubbles: true, detail: layer })
Expand Down
57 changes: 56 additions & 1 deletion elements/layercontrol/stories/primary.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,59 @@
import { html } from "lit";
import { STORIES_MAIN_MAP_LAYERS, STORIES_MAP_STYLE } from "../src/enums";
import {
/*STORIES_MAIN_MAP_LAYERS,*/
STORIES_MAP_STYLE,
STORIES_LAYER_SENTINEL_HUB,
STORIES_LAYER_REGION,
STORIES_LAYER_S2,
STORIES_LAYER_OSM,
} from "../src/enums";

const STORIES_MAIN_MAP_LAYERS = [
{
type: "Group",
properties: {
id: "group3",
title: "Data Layers",
layerControlExpand: true,
layerControlExclusive: true,
description: "# Hello world",
},
layers: [
{ ...STORIES_LAYER_SENTINEL_HUB.wind, layerControlGloballyExclusive: true },
],
},
{
type: "Group",
properties: {
id: "group2",
title: "Data Layers",
layerControlExpand: true,
layerControlExclusive: true,
description: "# Hello world",
},
layers: [
//{ ...STORIES_LAYER_SENTINEL_HUB.wind, layerControlGloballyExclusive: true },
{ ...STORIES_LAYER_SENTINEL_HUB.no2, layerControlGloballyExclusive: true },
STORIES_LAYER_REGION,
],
},
{
type: "Group",
properties: {
id: "group1",
title: "Background Layers",
//layerControlExclusive: true,
},
layers: [
{ ...STORIES_LAYER_S2, layerControlGloballyExclusive: true },
STORIES_LAYER_OSM,
],
},
];



// layerControlExclusive

export const Primary = {
args: {
Expand All @@ -13,6 +67,7 @@ export const Primary = {
.idProperty=${args.idProperty}
.titleProperty=${args.titleProperty}
.unstyled=${args.unstyled}
.isGloballyExclusive=${true}
for="eox-map"
></eox-layercontrol>
<eox-map
Expand Down
Loading