Coverage for gws-app/gws/base/legend/__init__.py: 100%
1 statements
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
« prev ^ index » next coverage.py v7.16.2, created at 2026-10-05 13:35 +0200
1"""Base classes for layer legends.
3A legend belongs to a layer and renders an image that explains the layer's
4symbols. The base package provides the generic ``Object`` with the common
5``Config`` options (``cacheMaxAge``, ``options``) and ``combine_outputs``, which
6stacks several legend images vertically into one. Concrete legend types are
7plugins in ``gws.plugin.legend`` (``static``, ``remote``, ``html``,
8``combined``) and in other plugins such as ``gws.plugin.qgis``. A group layer
9without its own legend gets a ``combined`` legend of its children.
11Layers render their legends with ``Layer.render_legend``, the client fetches
12them with the ``mapGetLegend`` command.
14Submodules:
16- ``core``: the base ``Object``, ``Config``, ``Props`` and ``combine_outputs``.
18Example::
20 map.layers+ {
21 type "qgis"
22 provider.path "/data/projects/roads.qgs"
23 legend { type "static" path "/data/legends/roads.png" }
24 }
26A legend type in a plugin::
28 @gws.ext.object.legend('mylegend')
29 class Object(gws.base.legend.Object):
30 def render(self, args=None):
31 images = [gws.lib.image.from_path(p) for p in self.cfg('paths')]
32 lros = [gws.LegendRenderOutput(image=img, size=img.size()) for img in images]
33 return gws.base.legend.combine_outputs(lros, self.options)
34"""
36from .core import (
37 Config,
38 Object,
39 Props,
40 combine_outputs,
41)