From 48aad70993d4896aa0cf60ec1dc27e2a47ff57b6 Mon Sep 17 00:00:00 2001 From: EpicKiwi Date: Sun, 7 Jun 2026 17:45:21 +0200 Subject: [PATCH] Ajout des legendes --- css/style.css | 16 +++++- js/components/feature-legend.js | 72 +++++++++++++++++++++++++++ js/components/feature-short-header.js | 11 ++++ 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 js/components/feature-legend.js diff --git a/css/style.css b/css/style.css index c61fd99..f6fd981 100644 --- a/css/style.css +++ b/css/style.css @@ -182,7 +182,15 @@ body > hr { camp-feature-short-header { display: grid; grid-template-rows: 1fr min-content; - grid-template-columns: 1fr; + grid-template-columns: 3em 1fr; + gap: 0.5ex 0.5em; + vertical-align: center; +} + +camp-feature-short-header .feature-legend { + grid-row: 1 / 3; + height: 3em; + align-self: flex-start; } camp-feature-short-header h2 { @@ -215,3 +223,9 @@ camp-feature-short-header .feature-location { text-decoration: none; color: inherit; } + +/* FEATURE */ + +camp-feature { + min-height: 25vh; +} diff --git a/js/components/feature-legend.js b/js/components/feature-legend.js new file mode 100644 index 0000000..03ddb78 --- /dev/null +++ b/js/components/feature-legend.js @@ -0,0 +1,72 @@ +const TEMPLATE = document.createElement("template") +TEMPLATE.innerHTML = ` + +
+ +
+` + +export class FeatureLegendElement extends HTMLElement { + + feature + + connectedCallback(){ + if(!this.shadow){ + this.shadow = this.attachShadow({mode: "open"}) + this.shadow.append(TEMPLATE.content.cloneNode(true)) + } + this.updateContent() + } + + updateContent(){ + let container = this.shadow.getElementById("legend-container") + let marker = this.shadow.getElementById("marker-icon") + container.hidden = !this.feature + if(this.feature){ + let symbol = this.feature.mapSymbol + container.style.backgroundColor = symbol.backgroundColor || "transparent" + container.style.backgroundImage = symbol.backgroundUrl ? `url(${symbol.backgroundUrl})` : "none" + container.style.borderColor = symbol.borderColor || "transparent" + if(symbol.markerUrl){ + marker.src = symbol.markerUrl + } else { + marker.removeAttribute("src") + } + } + } + +} + +customElements.define("camp-feature-legend", FeatureLegendElement) diff --git a/js/components/feature-short-header.js b/js/components/feature-short-header.js index 4dda14f..e40adec 100644 --- a/js/components/feature-short-header.js +++ b/js/components/feature-short-header.js @@ -1,5 +1,8 @@ +import "./feature-legend.js" + const TEMPLATE = document.createElement("template") TEMPLATE.innerHTML = ` +

` @@ -14,6 +17,9 @@ export class FeatureShortHeaderElement extends HTMLElement { set feature(value){ this.#feature = value + let legend = this.querySelector(".feature-legend") + if(legend) + legend.feature = value } connectedCallback(){ @@ -24,7 +30,12 @@ export class FeatureShortHeaderElement extends HTMLElement { if(!this.feature){ this.replaceChildren() } else { + this.replaceChildren(TEMPLATE.content.cloneNode(true)) + + this.querySelector(".feature-legend").feature = this.feature + this.querySelector(".feature-legend").updateContent() + this.querySelector(".feature-name").textContent = this.feature?.properties?.name || this.feature.mapSymbol.genericName ||