mirror of
https://gitlab.com/mrubli/hugo-mod-leaflet.git
synced 2025-10-07 01:54:24 +00:00

The config key name is the layer name with '.' replaced with '_'. For example: params: modules: leaflet: com_thunderforest_outdoors: apiKey: abcdef1234567890abcdef1234567890 If the key is specified in both the config file and the tag attribute, the latter takes precedence. Implements #6
25 lines
817 B
HTML
25 lines
817 B
HTML
{{ if or (not .Parent) (not (eq .Parent.Name "leaflet-map")) }}
|
|
{{ errorf "%s: cannot be used outside leaflet-map: %s" .Name .Position }}
|
|
{{ end }}
|
|
|
|
{{ if not (isset .Params "id") }}
|
|
{{ errorf "%s: missing 'id' parameter: %s" .Name .Position }}
|
|
{{ end }}
|
|
|
|
{{ $uniqueMapId := (printf "%s:%d" .Page.File.UniqueID .Parent.Ordinal) | md5 | safeJS }}
|
|
|
|
{{ $id := .Get "id" }}
|
|
{{ $configId := replace (.Get "id") "." "_" }}
|
|
{{ $apiKey := default (index .Site.Params.modules.leaflet $configId "apiKey") (.Get "apiKey") }}
|
|
<script>
|
|
map_options_{{ $uniqueMapId }}.layers.enabled.push({{ $id }});
|
|
map_options_{{ $uniqueMapId }}.layers["{{ $id }}"] = {
|
|
{{ with $apiKey }}
|
|
apiKey: '{{ . }}',
|
|
{{ end }}
|
|
};
|
|
{{ with .Get "selectorPosition" }}
|
|
map_options_{{ $uniqueMapId }}.layers.position = {{ . }};
|
|
{{ end }}
|
|
</script>
|