enter image description here

How can I show legend / classified features in my layer switcher legend in OpenLayers from qgis2web similar to how the Leaflet option exports it? Openlayers shows legend items fine as a single style but if the layer has subclasses only the main layer name shows in the layer switcher legend.

2 Answers 2


Yes, I can confirm that it is the symbology with rules that is not exported correctly. It is only a legend problem because the themes can be seen correctly on the map. You can solve by manually editing the "title" in the layer you are interested in in the layer.js file


title: 'Pai Esondazioni agg 2016<br />\
    <img src="styles/legend/PaiEsondazioniagg2016_11_0.png" /> R1<br />\
    <img src="styles/legend/PaiEsondazioniagg2016_11_1.png" /> R2<br />\
    <img src="styles/legend/PaiEsondazioniagg2016_11_2.png" /> R3<br />\
    <img src="styles/legend/PaiEsondazioniagg2016_11_3.png" /> R4<br />'

Unfortunately you will have to create the png icons by hand and then recall them


In my legend, OpenLayers are visible:


Set up like this in QGIS:


  • Well thanks but not quite! That is how my layers are set up in QGIS, the only difference is I have used "Rule Based" criteria instead of "Categorized". Is it the "Rule Based" that OpenLayers doesn't like? (See new image above.)
    – Mikeoramma
    Commented Feb 22, 2022 at 16:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.