move heatmap code into partial
This commit is contained in:
parent
c7cfdcdb5b
commit
0167884748
2 changed files with 48 additions and 40 deletions
|
@ -21,46 +21,7 @@
|
||||||
<script src="/js/leaflet-fullscreen/leaflet.fullscreen.min.js"></script>
|
<script src="/js/leaflet-fullscreen/leaflet.fullscreen.min.js"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var map = L.map('map', {
|
{{- partial "cv/locations/heatmap.js" ( dict "all_pages" $.Site.AllPages ) -}}
|
||||||
fullscreenControl: true
|
|
||||||
}).setView([55, -3], 3);
|
|
||||||
|
|
||||||
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
||||||
maxZoom: 19,
|
|
||||||
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
|
||||||
}).addTo(map);
|
|
||||||
|
|
||||||
{{- $locations := partialCached "util/get_location_leaf_nodes.html" $.Site.Data.locations -}}
|
|
||||||
|
|
||||||
{{/*
|
|
||||||
{{- range .Site.AllPages -}}
|
|
||||||
{{- with .Params.locations -}}
|
|
||||||
{{- range . -}}
|
|
||||||
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
|
|
||||||
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
*/}}
|
|
||||||
|
|
||||||
L.heatLayer(
|
|
||||||
[
|
|
||||||
{{- range .Site.AllPages -}}
|
|
||||||
{{- with .Params.locations -}}
|
|
||||||
{{- range . -}}
|
|
||||||
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
|
|
||||||
[ {{ .lat }}, {{ .lon }} ],
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
{{- end -}}
|
|
||||||
],
|
|
||||||
{
|
|
||||||
minOpacity: 0.5,
|
|
||||||
gradient: {0.1: 'blue', 0.3: 'lime', 0.8: 'orange', 1: 'red'}
|
|
||||||
}
|
|
||||||
).addTo(map);
|
|
||||||
</script>
|
</script>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
|
47
layouts/partials/cv/locations/heatmap.js
Normal file
47
layouts/partials/cv/locations/heatmap.js
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
/*
|
||||||
|
Recursively render an ordered or unordered list from a set of arbitrarily-
|
||||||
|
deeply-nested items.
|
||||||
|
|
||||||
|
@params all_pages All site pages
|
||||||
|
*/
|
||||||
|
|
||||||
|
var map = L.map('map', {
|
||||||
|
fullscreenControl: true
|
||||||
|
}).setView([55, -3], 3);
|
||||||
|
|
||||||
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
||||||
|
maxZoom: 19,
|
||||||
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a>'
|
||||||
|
}).addTo(map);
|
||||||
|
|
||||||
|
{{- $locations := partialCached "util/get_location_leaf_nodes.html" $.Site.Data.locations -}}
|
||||||
|
|
||||||
|
{{/*
|
||||||
|
{{- range .Site.AllPages -}}
|
||||||
|
{{- with .Params.locations -}}
|
||||||
|
{{- range . -}}
|
||||||
|
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
|
||||||
|
L.marker([{{ .lat }}, {{ .lon }}]).addTo(map);
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
*/}}
|
||||||
|
|
||||||
|
L.heatLayer(
|
||||||
|
[
|
||||||
|
{{- range .all_pages -}}
|
||||||
|
{{- with .Params.locations -}}
|
||||||
|
{{- range . -}}
|
||||||
|
{{- with ( index $locations ( replaceRE `, [A-Z]+` "" . ) ) -}}
|
||||||
|
[ {{ .lat }}, {{ .lon }} ],
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
{{- end -}}
|
||||||
|
],
|
||||||
|
{
|
||||||
|
minOpacity: 0.5,
|
||||||
|
gradient: {0.1: 'blue', 0.3: 'lime', 0.8: 'orange', 1: 'red'}
|
||||||
|
}
|
||||||
|
).addTo(map);
|
Loading…
Reference in a new issue