Create DataLayer.renderLegend

This commit is contained in:
Yohan Boniface 2023-06-20 20:32:18 +02:00
parent 615498d3bf
commit 1620c0567b

View file

@ -594,6 +594,11 @@ L.U.DataLayersControl = L.Control.extend({
}) })
L.U.DataLayer.include({ L.U.DataLayer.include({
renderLegend: function (container) {
const color = L.DomUtil.create('span', 'datalayer-color', container)
color.style.backgroundColor = this.getColor()
},
renderToolbox: function (container) { renderToolbox: function (container) {
const toggle = L.DomUtil.create('i', 'layer-toggle', container), const toggle = L.DomUtil.create('i', 'layer-toggle', container),
zoomTo = L.DomUtil.create('i', 'layer-zoom_to', 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) const datalayerContainer = L.DomUtil.create('div', 'datalayer-container', container)
this.eachVisibleDataLayer((datalayer) => { this.eachVisibleDataLayer((datalayer) => {
const p = L.DomUtil.create('p', '', datalayerContainer), const p = L.DomUtil.create('p', 'datalayer-legend', datalayerContainer),
color = L.DomUtil.create('span', 'datalayer-color', p), legend = L.DomUtil.create('span', '', p),
headline = L.DomUtil.create('strong', '', p), headline = L.DomUtil.create('strong', '', p),
description = L.DomUtil.create('span', '', p) description = L.DomUtil.create('span', '', p)
datalayer.onceLoaded(function () { datalayer.onceLoaded(function () {
color.style.backgroundColor = this.getColor() datalayer.renderLegend(legend)
if (datalayer.options.description) { if (datalayer.options.description) {
description.innerHTML = L.Util.toHTML(datalayer.options.description) description.innerHTML = L.Util.toHTML(datalayer.options.description)
} }