-
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.
- Loading branch information
Showing
8 changed files
with
92 additions
and
0 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
invenio_previewer_geospatial/assets/semantic-ui/css/invenio_previewer_geospatial/gpx.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; | ||
} |
30 changes: 30 additions & 0 deletions
30
invenio_previewer_geospatial/assets/semantic-ui/js/invenio_previewer_geospatial/gpx.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,30 @@ | ||
import L from "leaflet" | ||
import 'leaflet-gpx'; | ||
import "leaflet/dist/leaflet.css"; | ||
|
||
document.addEventListener("DOMContentLoaded", () => { | ||
const mapElement = document.getElementById("map"); | ||
const gpxFileUri = mapElement.getAttribute("data-file-uri") | ||
const gpxUrl = new URL(gpxFileUri, window.location.href); | ||
|
||
const map = L.map('map').setView([0, 0], 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); | ||
|
||
new L.GPX(gpxUrl.href, { | ||
async: true, | ||
gpx_options: { | ||
parseElements: ['track', 'route'] | ||
}, | ||
markers: { | ||
// TODO: Figure out how to display stock images from leaflet-gpx | ||
startIcon: null, | ||
endIcon: null | ||
} | ||
}).on('loaded', (e) => { | ||
map.fitBounds(e.target.getBounds()); | ||
}).addTo(map); | ||
}); |
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,3 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Geospatial Previewers.""" |
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,21 @@ | ||
"""GPX Previewer.""" | ||
|
||
from flask import render_template | ||
from invenio_previewer.proxies import current_previewer | ||
|
||
previewable_extensions = ["gpx"] | ||
|
||
|
||
def can_preview(file): | ||
"""Check if file can be previewed.""" | ||
return file.is_local() and file.has_extensions(".gpx") | ||
|
||
|
||
def preview(file): | ||
"""Render the GPX template.""" | ||
return render_template( | ||
"invenio_previewer_geospatial/gpx.html", | ||
file=file, | ||
js_bundles=current_previewer.js_bundles + ["gpx_js.js"], | ||
css_bundles=current_previewer.css_bundles + ["gpx_css.css"], | ||
) |
5 changes: 5 additions & 0 deletions
5
invenio_previewer_geospatial/templates/semantic-ui/invenio_previewer_geospatial/gpx.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,5 @@ | ||
{%- extends config.PREVIEWER_ABSTRACT_TEMPLATE %} | ||
|
||
{% block panel %} | ||
<div id="map" data-file-uri="{{ file.uri }}"></div> | ||
{% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
"""JS/CSS Webpack bundles for Invenio Previewer Geospatial.""" | ||
|
||
from invenio_assets.webpack import WebpackThemeBundle | ||
|
||
theme = WebpackThemeBundle( | ||
__name__, | ||
"assets", | ||
default="semantic-ui", | ||
themes={ | ||
"semantic-ui": dict( | ||
entry={ | ||
"gpx_js": "./js/invenio_previewer_geospatial/gpx.js", | ||
"gpx_css": "./css/invenio_previewer_geospatial/gpx.css", | ||
}, | ||
dependencies={"leaflet": "^1.9.4", "leaflet-gpx": "^2.1.2"}, | ||
), | ||
}, | ||
) |
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