-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nyudlts/geoserver-previewer
Shapefile previews via GeoServer
- Loading branch information
Showing
8 changed files
with
155 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
...io_previewer_geospatial/assets/semantic-ui/css/invenio_previewer_geospatial/geoserver.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
@import "leaflet/dist/leaflet.css"; | ||
|
||
#map { | ||
width: 100%; | ||
height: 480px; | ||
} |
28 changes: 28 additions & 0 deletions
28
invenio_previewer_geospatial/assets/semantic-ui/js/invenio_previewer_geospatial/geoserver.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import L from "leaflet" | ||
import "leaflet/dist/leaflet.css"; | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const mapElement = document.getElementById("map"); | ||
const baseUrl = mapElement.getAttribute("data-base-url") | ||
const layerName = mapElement.getAttribute("data-layer-name") | ||
|
||
const map = L.map('map').setView([51.505, -0.09], 13); | ||
|
||
L.tileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png', { | ||
maxZoom: 19, | ||
attribution: '© <a href="http://www.openstreetmap.org/copyright">OpenStreetMap</a>' | ||
}).addTo(map); | ||
|
||
const wmsLayer = L.tileLayer.wms(baseUrl, { | ||
layers: layerName, | ||
format: 'image/png', | ||
transparent: true | ||
}); | ||
|
||
wmsLayer.addTo(map); | ||
wmsLayer.setOpacity(0.75); | ||
map.fitBounds([ | ||
[17.881242, -179.14734], | ||
[71.390482, 179.778465] | ||
]) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""GeoServer Previewer.""" | ||
|
||
from flask import current_app, render_template | ||
from invenio_previewer.proxies import current_previewer | ||
|
||
previewable_extensions = ["shp"] | ||
|
||
|
||
def can_preview(file): | ||
"""Check if file can be previewed.""" | ||
return file.is_local() and file.has_extensions(".shp") | ||
|
||
|
||
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( | ||
"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"], | ||
) |
12 changes: 12 additions & 0 deletions
12
...io_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/geoserver.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %} | ||
|
||
{% block panel %} | ||
{% if record.custom_fields[wms_url_field] and record.custom_fields[layer_name_field] %} | ||
<div id="map" | ||
data-base-url="{{ record.custom_fields[wms_url_field] }}" | ||
data-layer-name="{{ record.custom_fields[layer_name_field] }}" | ||
></div> | ||
{% else %} | ||
<p>Sorry, this Shapefile has no associated GeoServer layer.</p> | ||
{% endif %} | ||
{% endblock %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters