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 b63484f
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lizmap_server/get_legend_graphic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit b63484f

Please sign in to comment.