From 190e5f0939c3e89eca1d2dcd16f79cd867fba3a9 Mon Sep 17 00:00:00 2001 From: NAGGINDA MARTHA Date: Thu, 22 Apr 2021 11:34:39 -0400 Subject: [PATCH] Fix default layer style url (#7368) Co-authored-by: Alessio Fabiani --- geonode/maps/models.py | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/geonode/maps/models.py b/geonode/maps/models.py index 1c38e05d50d..a07e9f45973 100644 --- a/geonode/maps/models.py +++ b/geonode/maps/models.py @@ -584,19 +584,13 @@ def get_legend(self): layer_params = json.loads(self.layer_params) capability = layer_params.get('capability', {}) - style_name = capability.get('style') - if style_name: - if ':' in style_name: - style_name = style_name.split(':')[1] - href = Layer.objects.filter(title=self.layer_title).first().get_legend_url(style_name=style_name) - return {style_name: href} - else: - # use the default style on layer - layer_obj = Layer.objects.filter(alternate=self.name).first() - if layer_obj: - default_style_name = layer_obj.default_style.name - legend_url = layer_obj.get_legend_url(style_name=default_style_name) - return {default_style_name: legend_url} + # Use '' to represent default layer style + style_name = capability.get('style', '') + layer_obj = Layer.objects.filter(alternate=self.name).first() + if ':' in style_name: + style_name = style_name.split(':')[1] + href = layer_obj.get_legend_url(style_name=style_name) + return {style_name: href} except Exception as e: logger.exception(e) return None