diff --git a/cubedash/_filters.py b/cubedash/_filters.py index f28c9b369..54c9c97cf 100644 --- a/cubedash/_filters.py +++ b/cubedash/_filters.py @@ -121,6 +121,17 @@ def _dataset_created(dataset: Dataset): def _dataset_file_paths(dataset: Dataset): return utils.get_dataset_file_offsets(dataset) +@bp.app_template_filter("dataset_thumbnail_url") +def _dataset_thumbnail_url(dataset: Dataset): + file_paths = _dataset_file_paths(dataset) + if "thumbnail:nbart" in file_paths: + offset = file_paths['thumbnail:nbart'] + elif "thumbnail" in file_paths: + offset = file_paths['thumbnail'] + else: + return "" + return _to_remote_url(offset, dataset.uris[0]) + @bp.app_template_filter("resolve_remote_url") def _to_remote_url(offset: str, base_uri: str = None): diff --git a/cubedash/templates/dataset.html b/cubedash/templates/dataset.html index f0c394a52..603b655be 100644 --- a/cubedash/templates/dataset.html +++ b/cubedash/templates/dataset.html @@ -3,7 +3,7 @@ {% block title %}{{ dataset | printable_dataset }}{% endblock %} {% set extent_geojson = dataset_footprint.__geo_interface__ %} -{% set thumbnail_url = [] %} +{% set thumbnail_url = dataset | dataset_thumbnail_url %} {% block head %} {{ super() }} @@ -144,15 +144,9 @@

- {% set offset_url = offset | resolve_remote_url(uri) %} - {{ offset }} - {% if 'thumbnail:nbart' == name or 'thumbnail' == name %} - {# workaround for jinja preventing global varaibles from being updated inside - for loops and if/else statements #} - {% set _ = thumbnail_url.append(offset_url) %} - {% endif %} @@ -229,9 +223,8 @@

}); L.control.zoom({position: "bottomright"}).addTo(map); map.fitBounds(dataset_data.getBounds(), {animate: false, maxZoom: 5}); - const has_thumbnail = '{{ thumbnail_url|length >= 1 }}'; - if (has_thumbnail === "True") { - L.imageOverlay("{{ thumbnail_url[0]|e }}", dataset_data.getBounds()).addTo(map); + if ("{{ thumbnail_url }}") { + L.imageOverlay("{{ thumbnail_url }}", dataset_data.getBounds()).addTo(map); } window.MAP = map;