hugo-theme/layouts/shortcodes/maps.html

62 lines
1.9 KiB
HTML
Raw Normal View History

{{/* Required params. Fail if missing. */}}
2024-02-05 11:39:47 +00:00
{{ $apiKey := .Site.Params.apiKey }}
{{ if not $apiKey }}
{{ errorf "Error: 'apiKey' is a required site parameter for this shortcode." }}
{{ end }}
2024-02-05 11:39:47 +00:00
{{ $adr := .Get "address" }}
{{ if not $adr }}
{{ errorf "Error: 'address' is a required parameter for this shortcode." }}
{{ end }}
2024-02-05 11:39:47 +00:00
{{ $path := .Get "path" }}
{{ if not $path }}
{{ errorf "Error: 'path' is a required parameter for this shortcode." }}
{{ end }}
2024-02-05 11:39:47 +00:00
{{/* Optional params. No error checking. */}}
2024-02-05 11:39:47 +00:00
{{ $label := .Get "label" }}
{{ $url := .Get "url" }}
2024-02-05 11:39:47 +00:00
{{ $adrURL := urlquery $adr }}
{{ $LLapiURL := printf "https://api.geoapify.com/v1/geocode/search?text=%s&format=json&apiKey=%s" $adrURL $apiKey }}
2024-02-05 11:39:47 +00:00
{{ $data := getJSON $LLapiURL }}
{{ with index $data.results 0 }}
{{ $lon := .lon }}
{{ $lat := .lat }}
{{ $MapApiUrl := printf "https://maps.geoapify.com/v1/staticmap?style=osm-bright&width=500&height=500&center=lonlat:%f,%f&zoom=12&marker=lonlat:%f,%f;color:%%23ff0000;size:medium&scaleFactor=2&apiKey=%s" $lon $lat $lon $lat $apiKey }}
2024-02-06 21:02:29 +00:00
<blockquote>
<div class="map" >
{{ with resources.GetRemote $MapApiUrl }}
{{ with resources.Copy $path . }}
{{ with .Err }}
{{ errorf "%s" . }}
{{ else }}
<img src="{{ .RelPermalink }}" width=350px />
{{ end }}
{{ else }}
{{ errorf "Unable to get remote resource %q" $MapApiUrl }}
{{ end }}
{{ end }}
2024-02-05 11:39:47 +00:00
<div class="map-txt-grid">
<div class="grid-item">
{{ with $label }}
<p><b>{{ $label }}</b></p>
{{ end }}
</div>
2024-02-05 11:39:47 +00:00
<div class="grid-item"><p>{{ .address_line1 }}<br/>{{ replaceRE `, United States of America$` "" .address_line2 }}</p></div>
{{end}}
<div class="grid-item">
<div class="child-element">
{{ with $url }}
<a class="map-button" href="{{ $url }}" target="_blank">See on Google Maps</a>
{{ end }}
2024-02-05 11:39:47 +00:00
</div>
</div>
</div>
</div>
2024-02-06 21:02:29 +00:00
</blockquote>