Skip to content

Commit

Permalink
WMS GetLegendGraphic JSON: Provide Warning icon for invalid layers
Browse files Browse the repository at this point in the history
  • Loading branch information
rldhont committed Apr 23, 2024
1 parent d98b19c commit 3c11c8a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lizmap_server/get_legend_graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Optional

from qgis.core import Qgis, QgsProject, QgsVectorLayer
from qgis.PyQt.QtCore import QBuffer, QImage, QIODevice
from qgis.server import QgsServerFilter

from lizmap_server.core import find_vector_layer
Expand Down Expand Up @@ -79,6 +80,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()

Expand Down

0 comments on commit 3c11c8a

Please sign in to comment.