Exemplo n.º 1
0
 def configure_legend(self):
     if not super().configure_legend():
         legend_layers = [la for la in self.layers if la.has_legend]
         if legend_layers:
             self.legend = gws.Legend(enabled=True,
                                      layers=legend_layers,
                                      options=self.var('legend.options',
                                                       default={}))
             return True
Exemplo n.º 2
0
 def configure_legend(self):
     if not super().configure_legend():
         if self.source_layer.legend_url:
             self.legend = gws.Legend(
                 enabled=True,
                 urls=[self.source_layer.legend_url],
                 cache_max_age=self.var('legend.cacheMaxAge', default=0),
                 options=self.var('legend.options', default={}))
             return True
Exemplo n.º 3
0
 def configure_legend(self):
     if not super().configure_legend():
         self.legend = gws.Legend(enabled=True,
                                  urls=[
                                      self.provider.legend_url(
                                          self.source_layers,
                                          self.var('legend.options'))
                                  ])
         return True
Exemplo n.º 4
0
 def handle_getlegendgraphic(self, rd: core.Request):
     lcs = self.layer_caps_list_from_request(rd, ['layer', 'layers'],
                                             self.SCOPE_LEAF)
     if not lcs:
         raise gws.base.web.error.NotFound('No layers found')
     out = gws.gis.legend.render(
         gws.Legend(layers=[lc.layer for lc in lcs if lc.has_legend]))
     return gws.ContentResponse(mime='image/png',
                                content=gws.gis.legend.to_bytes(out)
                                or gws.lib.image.PIXEL_PNG8)
Exemplo n.º 5
0
    def handle_getlegendgraphic(self, rd: core.Request):
        # https://docs.geoserver.org/stable/en/user/services/wms/get_legend_graphic/index.html
        # @TODO currently only support 'layer'

        lcs = self.layer_caps_list_from_request(rd, ['layer', 'layers'], self.SCOPE_LAYER)
        if not lcs:
            raise gws.base.web.error.NotFound('No layers found')

        out = gws.gis.legend.render(gws.Legend(layers=[lc.layer for lc in lcs if lc.has_legend]))
        return gws.ContentResponse(
            mime=gws.lib.mime.PNG,
            content=gws.gis.legend.to_bytes(out) or gws.lib.image.PIXEL_PNG8)
Exemplo n.º 6
0
    def _render_legend(self, kwargs):
        layers = self._legend_layers(kwargs)
        if not layers:
            raise gws.Error('no legend layers')

        lro = gws.gis.legend.render(gws.Legend(layers=layers))
        if not lro:
            raise gws.Error('no legend output')

        img_path = gws.gis.legend.to_image_path(lro)
        if not img_path:
            raise gws.Error('no legend image path')

        self.legend_count += 1
        return f'<img src="{img_path}"/>'