From 1620c0567bfbd46d9703c2c09d6dd803c376ea1d Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Tue, 20 Jun 2023 20:32:18 +0200 Subject: [PATCH] Create DataLayer.renderLegend --- umap/static/umap/js/umap.controls.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 0cd0bb73..76f6e837 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -594,6 +594,11 @@ L.U.DataLayersControl = L.Control.extend({ }) L.U.DataLayer.include({ + renderLegend: function (container) { + const color = L.DomUtil.create('span', 'datalayer-color', container) + color.style.backgroundColor = this.getColor() + }, + renderToolbox: function (container) { const toggle = L.DomUtil.create('i', 'layer-toggle', container), zoomTo = L.DomUtil.create('i', 'layer-zoom_to', container), @@ -939,12 +944,12 @@ L.U.Map.include({ } const datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container) this.eachVisibleDataLayer((datalayer) => { - const p = L.DomUtil.create('p', '', datalayerContainer), - color = L.DomUtil.create('span', 'datalayer-color', p), + const p = L.DomUtil.create('p', 'datalayer-legend', datalayerContainer), + legend = L.DomUtil.create('span', '', p), headline = L.DomUtil.create('strong', '', p), description = L.DomUtil.create('span', '', p) datalayer.onceLoaded(function () { - color.style.backgroundColor = this.getColor() + datalayer.renderLegend(legend) if (datalayer.options.description) { description.innerHTML = L.Util.toHTML(datalayer.options.description) }