diff --git a/lizmap_server/get_legend_graphic.py b/lizmap_server/get_legend_graphic.py index e6a03792..cd2c8e11 100644 --- a/lizmap_server/get_legend_graphic.py +++ b/lizmap_server/get_legend_graphic.py @@ -12,6 +12,8 @@ from typing import Optional from qgis.core import Qgis, QgsProject, QgsVectorLayer +from qgis.PyQt.QtCore import QBuffer, QIODevice +from qgis.PyQt.QtGui import QImage from qgis.server import QgsServerFilter from lizmap_server.core import find_vector_layer @@ -79,6 +81,22 @@ def responseComplete(self): logger.info("Skipping the layer '{}' because it's not a vector layer".format(layer_name)) return + if not layer.isValid(): + buffer = QBuffer() + buffer.open(QIODevice.WriteOnly) + qp = QImage(":/images/themes/default/mIconWarning.svg") + qp.save(buffer, "PNG") + json_data = { + 'title': '', + 'nodes': [{ + 'title': layer_name, + 'icon': buffer.data().toBase64(), + }] + } + handler.clearBody() + handler.appendBody(json.dumps(json_data).encode('utf8')) + return + try: current_style = layer.styleManager().currentStyle()