def get_legend(self, query): if self.static: # prevent caching of static legends for different scales legend = Legend(id=self.identifier, scale=None) else: legend = Legend(id=self.identifier, scale=query.scale) if not self._cache.load(legend): legends = [] error_occured = False for client in self.clients: try: legends.append(client.get_legend(query)) except HTTPClientError as e: error_occured = True log.error(e.args[0]) except SourceError as e: error_occured = True # TODO errors? log.error(e.args[0]) format = split_mime_type(query.format)[1] legend = Legend(source=concat_legends(legends, format=format), id=self.identifier, scale=query.scale) if not error_occured: self._cache.store(legend) return legend.source
class WMSLegendSource(LegendSource): def __init__(self, clients, legend_cache): self.clients = clients self.identifier = legend_identifier([c.identifier for c in self.clients]) self._cache = legend_cache self._size = None @property def size(self): if not self._size: legend = self.get_legend(LegendQuery(format='image/png', scale=None)) # TODO image size without as_image? self._size = legend.as_image().size return self._size def get_legend(self, query): legend = Legend(id=self.identifier, scale=query.scale) if not self._cache.load(legend): legends = [] error_occured = False for client in self.clients: try: legends.append(client.get_legend(query)) except HTTPClientError, e: error_occured = True log.error(e.args[0]) except SourceError, e: error_occured = True # TODO errors? log.error(e.args[0]) format = split_mime_type(query.format)[1] legend = Legend(source=concat_legends(legends, format=format), id=self.identifier, scale=query.scale) if not error_occured: self._cache.store(legend)
def get_legend(self, query): if self.static: # prevent caching of static legends for different scales legend = Legend(id=self.identifier, scale=None) else: legend = Legend(id=self.identifier, scale=query.scale) if not self._cache.load(legend): legends = [] error_occured = False for client in self.clients: try: legends.append(client.get_legend(query)) except HTTPClientError, e: error_occured = True log.error(e.args[0]) except SourceError, e: error_occured = True # TODO errors? log.error(e.args[0])
def get_legend(self, query): legend = Legend(id=self.identifier, scale=query.scale) if not self._cache.load(legend): legends = [] error_occured = False for client in self.clients: try: legends.append(client.get_legend(query)) except HTTPClientError, e: error_occured = True log.error(e.args[0]) except SourceError, e: error_occured = True # TODO errors? log.error(e.args[0])