diff --git a/README.rst b/README.rst index 0141888..c88d7c5 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,8 @@ package: :: PREVIEWER_PREVIEWERS_ORDER = [ - "invenio_previewer.extensions.geoserver", + "invenio_previewer.extensions.shapefile_geoserver", + "invenio_previewer.extensions.geotiff_geoserver", "invenio_previewer.extensions.gpx", "invenio_previewer.extensions.csv_papaparsejs", "invenio_previewer.extensions.json_prismjs", @@ -46,7 +47,8 @@ package: ] PREVIEWER_PREFERENCE = [ - "geoserver", + "shapefile_geoserver", + "geotiff_geoserver", "gpx", "csv_papaparsejs", "json_prismjs", diff --git a/invenio_previewer_geospatial/extensions/geotiff_geoserver.py b/invenio_previewer_geospatial/extensions/geotiff_geoserver.py new file mode 100644 index 0000000..8be42a0 --- /dev/null +++ b/invenio_previewer_geospatial/extensions/geotiff_geoserver.py @@ -0,0 +1,32 @@ +"""GeoTIFF previews via GeoServer.""" + +from flask import current_app, render_template +from invenio_previewer.proxies import current_previewer +from invenio_previewer.utils import dotted_exts + +previewable_extensions = ["tif", "tiff", "gtiff"] + + +def can_preview(file): + """Check if file can be previewed.""" + return file.is_local() and file.has_extensions(*dotted_exts(previewable_extensions)) + + +def preview(file): + """Render the Geoserver template.""" + return render_template( + "invenio_previewer_geospatial/geoserver.html", + record=file.record, + wms_url_field=( + current_app.config.get( + "PREVIEWER_GEOSPATIAL_CUSTOM_FIELDS_GEOSERVER_WMS_URL" + ) + ), + layer_name_field=( + current_app.config.get( + "PREVIEWER_GEOSPATIAL_CUSTOM_FIELDS_GEOSERVER_LAYER_NAME" + ) + ), + js_bundles=current_previewer.js_bundles + ["geoserver_js.js"], + css_bundles=current_previewer.css_bundles + ["geoserver_css.css"], + ) diff --git a/invenio_previewer_geospatial/extensions/geoserver.py b/invenio_previewer_geospatial/extensions/shapefile_geoserver.py similarity index 82% rename from invenio_previewer_geospatial/extensions/geoserver.py rename to invenio_previewer_geospatial/extensions/shapefile_geoserver.py index b1e67b7..1145e1c 100644 --- a/invenio_previewer_geospatial/extensions/geoserver.py +++ b/invenio_previewer_geospatial/extensions/shapefile_geoserver.py @@ -1,21 +1,21 @@ -"""GeoServer Previewer.""" +"""Shapefile previews via GeoServer.""" from flask import current_app, render_template from invenio_previewer.proxies import current_previewer +from invenio_previewer.utils import dotted_exts previewable_extensions = ["shp"] def can_preview(file): """Check if file can be previewed.""" - return file.is_local() and file.has_extensions(".shp") + return file.is_local() and file.has_extensions(*dotted_exts(previewable_extensions)) def preview(file): """Render the Geoserver template.""" return render_template( "invenio_previewer_geospatial/geoserver.html", - file=file, record=file.record, wms_url_field=( current_app.config.get( diff --git a/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html b/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html index 155575d..9600aac 100644 --- a/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html +++ b/invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html @@ -7,6 +7,6 @@ data-layer-name="{{ record.custom_fields[layer_name_field] }}" > {% else %} -

Sorry, this Shapefile has no associated GeoServer layer.

+

Sorry, this file has no associated GeoServer layer.

{% endif %} {% endblock %} diff --git a/setup.cfg b/setup.cfg index 824c5ba..373bf07 100644 --- a/setup.cfg +++ b/setup.cfg @@ -49,7 +49,8 @@ invenio_assets.webpack = invenio_previewer_geospatial = invenio_previewer_geospatial.webpack:theme invenio_previewer.previewers = gpx = invenio_previewer_geospatial.extensions.gpx - geoserver = invenio_previewer_geospatial.extensions.geoserver + shapefile_geoserver = invenio_previewer_geospatial.extensions.shapefile_geoserver + geotiff_geoserver = invenio_previewer_geospatial.extensions.geotiff_geoserver [build_sphinx] source-dir = docs/