Skip to content

Commit eaf9d3e

Browse files
committed
Iterate over WMS child layers
1 parent 89e6c16 commit eaf9d3e

File tree

2 files changed

+34
-10
lines changed

2 files changed

+34
-10
lines changed

api/v3/wms_types.go

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -151,18 +151,42 @@ func init() {
151151
SchemeBuilder.Register(&WMS{}, &WMSList{})
152152
}
153153

154-
func (wms *WMS) GetUniqueTiffBlobKeys() []string {
155-
blobKeys := map[string]bool{}
154+
func (layer *Layer) getAllLayers() (layers []Layer) {
155+
layers = append(layers, *layer)
156+
for _, childLayer := range layer.Layers {
157+
layers = append(layers, childLayer.getAllLayers()...)
158+
}
159+
return
160+
}
161+
162+
func (layer *Layer) hasData() bool {
163+
switch {
164+
case layer.Data.Gpkg != nil:
165+
return true
166+
case layer.Data.Postgis != nil:
167+
return true
168+
case layer.Data.TIF != nil:
169+
return true
170+
default:
171+
return false
172+
}
173+
}
156174

157-
if wms.Spec.Service.Layer.Data.TIF != nil && wms.Spec.Service.Layer.Data.TIF.BlobKey != "" {
158-
blobKeys[wms.Spec.Service.Layer.Data.TIF.BlobKey] = true
175+
func (wms *WMS) GetAllLayersWithLegend() (layers []Layer) {
176+
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
177+
if layer.hasData() && layer.Style.Legend.BlobKey != "" {
178+
layers = append(layers, layer)
179+
}
159180
}
181+
return
182+
}
183+
184+
func (wms *WMS) GetUniqueTiffBlobKeys() []string {
185+
blobKeys := map[string]bool{}
160186

161-
if len(wms.Spec.Service.Layer.Layers) > 0 {
162-
for _, layer := range wms.Spec.Service.Layer.Layers {
163-
if layer.Data.TIF != nil && layer.Data.TIF.BlobKey != "" {
164-
blobKeys[layer.Data.TIF.BlobKey] = true
165-
}
187+
for _, layer := range wms.Spec.Service.Layer.getAllLayers() {
188+
if layer.Data.TIF != nil && layer.Data.TIF.BlobKey != "" {
189+
blobKeys[layer.Data.TIF.BlobKey] = true
166190
}
167191
}
168192
return slices.Collect(maps.Keys(blobKeys))

internal/controller/blobdownload/blob_download.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ func downloadStylingAssets(sb *strings.Builder, WMS *pdoknlv3.WMS) error {
107107
}
108108

109109
func downloadLegends(sb *strings.Builder, WMS *pdoknlv3.WMS) error {
110-
for _, layer := range WMS.Spec.Service.Layer.Layers {
110+
for _, layer := range WMS.GetAllLayersWithLegend() {
111111
writeLine(sb, "mkdir -p %s/%s;", legendPath, layer.Name)
112112
writeLine(sb, "rclone copyto blobs:/%s %s/%s/%s.png || exit 1;", layer.Style.Legend.BlobKey, legendPath, layer.Name, layer.Style.Name)
113113
fileName, err := getFilenameFromBlobKey(layer.Style.Legend.BlobKey)

0 commit comments

Comments
 (0)