fix: map in locations view

This commit is contained in:
Ben Goldsworthy 2025-02-20 01:23:36 +01:00
parent 16e7d6ef83
commit 312c4ed725
Signed by: Rumperuu
SSH key fingerprint: SHA256:v3uompaUiPqV2w1/AIRWBSQOxr2dntH9Xs/y8fDnUPU
3 changed files with 68 additions and 57 deletions

View file

@ -1,13 +1,20 @@
{{ define "title" }} {{ define "title" }}
Locations | {{ .Site.Title }} Locations |
{{ .Site.Title }}
{{ end }} {{ end }}
{{ define "main-class" }}--section location-map{{ end }} {{ define "main-class" }}--section location-map{{ end }}
{{ define "header-scripts" }} {{ define "header-scripts" }}
<!-- Leaflet --> <!-- Leaflet -->
<link rel="stylesheet" href="/css/leaflet/leaflet.css" /> <link
<link rel="stylesheet" href="/js/leaflet-fullscreen/leaflet.fullscreen.css" /> rel="stylesheet"
href="/css/leaflet/leaflet.css"
/>
<link
rel="stylesheet"
href="/js/leaflet-fullscreen/leaflet.fullscreen.css"
/>
{{ end }} {{ end }}
{{ define "footer-scripts" }} {{ define "footer-scripts" }}
@ -20,9 +27,7 @@
<!-- Leaflet Fullscreen --> <!-- Leaflet Fullscreen -->
<script src="/js/leaflet-fullscreen/leaflet.fullscreen.min.js"></script> <script src="/js/leaflet-fullscreen/leaflet.fullscreen.min.js"></script>
<script> {{- partial "cv/locations/heatmap.js" ( dict "all_pages" $.Site.AllPages "locations" $.Site.Data.locations ) -}}
{{- partial "cv/locations/heatmap.js" ( dict "all_pages" $.Site.AllPages ) -}}
</script>
{{ end }} {{ end }}
{{ define "main-header" }} {{ define "main-header" }}
@ -33,13 +38,16 @@
{{ end }} {{ end }}
{{ define "main-body" }} {{ define "main-body" }}
<article class="site-content__body site-content__body--chart"> <article class="site-content__body site-content__body--chart">
<div id="map" style="width: 100%; height: 500px; margin: 0; display: block;"></div> <div
id="map"
style="width: 100%; height: 500px; margin: 0; display: block;"
></div>
{{- with ( partial "util/render_recursive_list.html" ( dict "sc" $ "pc" . "items" $.Site.Data.locations "schemaType" "Place" ) ) -}} {{- with ( partial "util/render_recursive_list.html" ( dict "sc" $ "pc" . "items" $.Site.Data.locations "schemaType" "Place" ) ) -}}
<section style="grid-area: section-content"> <section style="grid-area: section-content">
{{- . -}} {{- . -}}
</section> </section>
{{- end -}} {{- end -}}
</article> </article>
{{ end }} {{ end }}

View file

@ -1,23 +1,25 @@
/* {{/*
Recursively render an ordered or unordered list from a set of arbitrarily- Recursively render an ordered or unordered list from a set of arbitrarily-
deeply-nested items. deeply-nested items.
@params all_pages All site pages @params all_pages All site pages
*/ @params locations All locations
*/}}
var map = L.map('map', { <script>
var map = L.map('map', {
fullscreenControl: true fullscreenControl: true
}).setView([55, -3], 3); }).setView([55, -3], 3);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', { L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
maxZoom: 19, maxZoom: 19,
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>' attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
}).addTo(map); }).addTo(map);
{{- $locations := partialCached "util/get_location_leaf_nodes.html" $.Site.Data.locations -}} {{- $locations := partialCached "util/get_location_leaf_nodes.html" .locations -}}
{{/* {{/*
{{- range .Site.AllPages -}} {{- range .Site.AllPages -}}
{{- with .Params.locations -}} {{- with .Params.locations -}}
{{- range . -}} {{- range . -}}
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}} {{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
@ -25,10 +27,10 @@ L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
{{- end -}} {{- end -}}
*/}} */}}
L.heatLayer( L.heatLayer(
[ [
{{- range .all_pages -}} {{- range .all_pages -}}
{{- with .Params.locations -}} {{- with .Params.locations -}}
@ -44,4 +46,5 @@ L.heatLayer(
minOpacity: 0.5, minOpacity: 0.5,
gradient: {0.1: 'blue', 0.3: 'lime', 0.8: 'orange', 1: 'red'} gradient: {0.1: 'blue', 0.3: 'lime', 0.8: 'orange', 1: 'red'}
} }
).addTo(map); ).addTo(map);
</script>