mirror of
https://gitlab.com/mrubli/hugo-mod-leaflet.git
synced 2025-10-08 10:34:28 +00:00
layouts: map: Make tracks downloadable
This commit is contained in:
@@ -8,7 +8,7 @@ Syntax summary:
|
|||||||
|
|
||||||
{{< leaflet-marker lat=FLOAT lon=FLOAT >}}
|
{{< leaflet-marker lat=FLOAT lon=FLOAT >}}
|
||||||
|
|
||||||
{{< leaflet-track path="URL" >}}
|
{{< leaflet-track path="URL" title="STRING" downloadable=BOOL >}}
|
||||||
|
|
||||||
{{< leaflet-scale >}}
|
{{< leaflet-scale >}}
|
||||||
|
|
||||||
@@ -81,6 +81,11 @@ Track options:
|
|||||||
|
|
||||||
path:
|
path:
|
||||||
Absolute or relative path of the .gpx file to render as a track.
|
Absolute or relative path of the .gpx file to render as a track.
|
||||||
|
title:
|
||||||
|
Name of the track, used e.g. to render the 'Download GPX' button when multiple tracks are present.
|
||||||
|
downloadable:
|
||||||
|
Boolean value indicating whether there should be a 'Download GPX' button for this track.
|
||||||
|
Optional, defaults to true.
|
||||||
|
|
||||||
Scale options:
|
Scale options:
|
||||||
|
|
||||||
@@ -126,6 +131,8 @@ Elevation profile options:
|
|||||||
<div id="map_backdrop_{{ $uniqueId }}" class="map-backdrop"></div>
|
<div id="map_backdrop_{{ $uniqueId }}" class="map-backdrop"></div>
|
||||||
<div id="map_attribution_{{ $uniqueId }}" class="map-attribution"></div>
|
<div id="map_attribution_{{ $uniqueId }}" class="map-attribution"></div>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="map_track_downloads_{{ $uniqueId }}">
|
||||||
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var map_options_{{ $uniqueId }} = {
|
var map_options_{{ $uniqueId }} = {
|
||||||
@@ -197,5 +204,26 @@ Elevation profile options:
|
|||||||
const backdrop = L.DomUtil.get('map_backdrop_{{ $uniqueId }}');
|
const backdrop = L.DomUtil.get('map_backdrop_{{ $uniqueId }}');
|
||||||
backdrop.addEventListener('click', ev => { map.restore(); });
|
backdrop.addEventListener('click', ev => { map.restore(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a download button for every downloadable track
|
||||||
|
for (const track of map_options_{{ $uniqueId }}.tracks)
|
||||||
|
{
|
||||||
|
if (!track.downloadable)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
const a = L.DomUtil.create(
|
||||||
|
'a',
|
||||||
|
'me-2 mb-2',
|
||||||
|
L.DomUtil.get('map_track_downloads_{{ $uniqueId }}')
|
||||||
|
);
|
||||||
|
a.setAttribute('href', track.source);
|
||||||
|
const button = L.DomUtil.create(
|
||||||
|
'button',
|
||||||
|
// Note that the following classes must be part of the safelist in hugo-theme-gallery-flex's tailwind.config.js:
|
||||||
|
'py-2.5 px-5 me-2 mb-2 text-sm font-medium rounded-lg border focus:outline-none focus:z-10 focus:ring-4 dark:focus:ring-gray-700 dark:bg-gray-800 dark:text-gray-400 dark:border-gray-600 dark:hover:text-white dark:hover:bg-gray-700',
|
||||||
|
a
|
||||||
|
);
|
||||||
|
button.innerHTML = track.title ? `Download GPX (${track.title})` : 'Download GPX';
|
||||||
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
@@ -9,5 +9,10 @@
|
|||||||
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
map_options_{{ $uniqueMapId }}.tracks.push({{ .Get "path" }})
|
map_options_{{ $uniqueMapId }}.tracks.push({
|
||||||
|
source: {{ .Get "path" }},
|
||||||
|
title: {{ .Get "title" | default ("null" | safeJS) }},
|
||||||
|
// Internal use, ignored by quip-maps
|
||||||
|
downloadable: {{ .Get "downloadable" | default "true" | safeJS }},
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user