Open brentfraser opened 4 years ago
Thanks for reporting this. I'll take a look later. Also, feel free to submit a PR if you have a fix for it.
The first part of the issue is intentional. If you want to legend with a single entry and no label to be collapsible, you can set collapseSimple
to true in its options.
As for the second part, I couldn't reproduce the issue. Can you provide an example for it? Thanks.
Simply remove/rename the "name" key from the legends list and the item is no longer collapsible. Below is an edit of the Example to show this. Note the name is not shown (as expected), but there is no ability to collapse the elements (a problem):
`
var htmlLegend1and2 = L.control.htmllegend({
position: 'bottomright',
legends: [{
nameTEST: 'Layer 1',
layer: layer1,
elements: [{
label: 'Rectangle',
html: '',
style: {
'background-color': 'red',
'width': '10px',
'height': '10px'
}
}, {
label: 'Triangle',
html: '',
style: {
'background-color': 'green',
'width': '10px',
'height': '10px'
}
}]
}],
collapseSimple: true,
detectStretched: true,
collapsedOnInit: true,
defaultOpacity: 0.7,
visibleIcon: 'icon icon-eye',
hiddenIcon: 'icon icon-eye-slash'
})
map.addControl(htmlLegend1and2)
`
One work-around is to use
name: ' ',
As for the "undefined", it appears when the html key is not included (not the label key as I originally reported above)
Thanks for clarifying this. I looked at the first case again and the current behavior is intentional because right now I don't see an elegant way of having a collapsible legend without a label. I fixed the second part in #13.
Currently if the legend entry does not have a label value , the entry is not collapsible. And a missing label key causes "undefined" to be shown on the legend.