Skip to content

Commit 29ecc13

Browse files
author
Jelle Dijkstra
committed
Changes
1 parent 6542ed0 commit 29ecc13

File tree

12 files changed

+267
-264
lines changed

12 files changed

+267
-264
lines changed

api/v3/shared_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ type TIF struct {
215215
// This option can be used to control the resampling kernel used sampling raster images, optional
216216
// +kubebuilder:validation:MinLength:=1
217217
// +kubebuilder:validation:Pattern=`(NEAREST|AVERAGE|BILINEAR)`
218+
// +kubebuilder:default=NEAREST
218219
Resample *string `json:"resample,omitempty"`
219220

220221
// Sets the color index to treat as transparent for raster layers, optional, hex or rgb

api/v3/wms_types.go

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,29 +376,41 @@ func (wmsService *WMSService) GetAnnotatedLayers() []AnnotatedLayer {
376376
}
377377

378378
func (wmsService *WMSService) GetAllLayers() (layers []Layer) {
379-
return append([]Layer{wmsService.Layer}, wmsService.Layer.GetAllLayers()...)
379+
return wmsService.Layer.FlattenLayers()
380380
}
381381

382-
func (layer *Layer) GetAllLayers() (layers []Layer) {
382+
// FlattenLayers - flattens the layer and its sublayers into one array
383+
func (layer *Layer) FlattenLayers() []Layer {
384+
layers := []Layer{*layer}
383385
for _, childLayer := range layer.Layers {
384-
layers = append(layers, childLayer.GetAllLayers()...)
386+
layers = append(layers, childLayer.FlattenLayers()...)
385387
}
386-
return
388+
return layers
389+
}
390+
391+
// GetAllSublayers - get all sublayers of a layer, the result does not include the layer itself
392+
func (layer *Layer) GetAllSublayers() []Layer {
393+
layers := layer.Layers
394+
for _, childLayer := range layer.Layers {
395+
layers = append(layers, childLayer.GetAllSublayers()...)
396+
}
397+
return layers
387398
}
388399

389-
func (layer *Layer) GetParent(candidateLayer *Layer) *Layer {
390-
if candidateLayer.Layers == nil {
400+
func (wmsService *WMSService) GetParentLayer(layer Layer) *Layer {
401+
if wmsService.Layer.Layers == nil {
391402
return nil
392403
}
393404

394-
for _, childLayer := range candidateLayer.Layers {
395-
if childLayer.Name == layer.Name {
396-
return candidateLayer
405+
for _, middleLayer := range wmsService.Layer.Layers {
406+
if middleLayer.Name == layer.Name {
407+
return &wmsService.Layer
397408
}
398409

399-
parent := layer.GetParent(&childLayer)
400-
if parent != nil {
401-
return parent
410+
for _, bottomLayer := range middleLayer.Layers {
411+
if bottomLayer.Name == layer.Name {
412+
return &middleLayer
413+
}
402414
}
403415
}
404416
return nil

api/v3/wms_types_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func TestLayer_GetParent(t *testing.T) {
134134
topLayer := Layer{Name: controller.Pointer("toplayer"), Layers: []Layer{childLayer1}}
135135

136136
type args struct {
137-
candidateLayer *Layer
137+
service WMSService
138138
}
139139
tests := []struct {
140140
name string
@@ -145,19 +145,19 @@ func TestLayer_GetParent(t *testing.T) {
145145
{
146146
name: "Test GetParent on layer with parent",
147147
layer: childLayer2,
148-
args: args{candidateLayer: &topLayer},
148+
args: args{service: WMSService{Layer: topLayer}},
149149
want: &childLayer1,
150150
},
151151
{
152152
name: "Test GetParent on layer without parent",
153153
layer: topLayer,
154-
args: args{candidateLayer: &topLayer},
154+
args: args{service: WMSService{Layer: topLayer}},
155155
want: nil,
156156
},
157157
}
158158
for _, tt := range tests {
159159
t.Run(tt.name, func(t *testing.T) {
160-
if got := tt.layer.GetParent(tt.args.candidateLayer); !reflect.DeepEqual(got, tt.want) {
160+
if got := tt.args.service.GetParentLayer(tt.layer); !reflect.DeepEqual(got, tt.want) {
161161
t.Errorf("GetParent() = %v, want %v", got, tt.want)
162162
}
163163
})

config/crd/bases/pdok.nl_wfs.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,6 +1337,7 @@ spec:
13371337
pattern: (#[0-9A-F]{6}([0-9A-F]{2})?)|([0-9]{1,3}\s[0-9]{1,3}\s[0-9]{1,3})
13381338
type: string
13391339
resample:
1340+
default: NEAREST
13401341
description: This option can be used to control
13411342
the resampling kernel used sampling raster images,
13421343
optional

config/crd/bases/pdok.nl_wms.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ spec:
13291329
pattern: (#[0-9A-F]{6}([0-9A-F]{2})?)|([0-9]{1,3}\s[0-9]{1,3}\s[0-9]{1,3})
13301330
type: string
13311331
resample:
1332+
default: NEAREST
13321333
description: This option can be used to control the resampling kernel used sampling raster images, optional
13331334
minLength: 1
13341335
pattern: (NEAREST|AVERAGE|BILINEAR)
@@ -1537,6 +1538,7 @@ spec:
15371538
pattern: (#[0-9A-F]{6}([0-9A-F]{2})?)|([0-9]{1,3}\s[0-9]{1,3}\s[0-9]{1,3})
15381539
type: string
15391540
resample:
1541+
default: NEAREST
15401542
description: This option can be used to control the resampling kernel used sampling raster images, optional
15411543
minLength: 1
15421544
pattern: (NEAREST|AVERAGE|BILINEAR)
@@ -1745,6 +1747,7 @@ spec:
17451747
pattern: (#[0-9A-F]{6}([0-9A-F]{2})?)|([0-9]{1,3}\s[0-9]{1,3}\s[0-9]{1,3})
17461748
type: string
17471749
resample:
1750+
default: NEAREST
17481751
description: This option can be used to control the resampling kernel used sampling raster images, optional
17491752
minLength: 1
17501753
pattern: (NEAREST|AVERAGE|BILINEAR)

internal/controller/blobdownload/blob_download_test.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package blobdownload
22

33
import (
4+
"github.com/google/go-cmp/cmp"
45
"strings"
56
"testing"
67

@@ -32,10 +33,10 @@ echo font-2 font-2.ttf >> /srv/data/config/fonts/fonts.list;
3233
echo 'generated fonts.list:';
3334
cat /srv/data/config/fonts/fonts.list;
3435
mkdir -p /var/www/legend/wms-gpkg-layer-1-name;
35-
rclone copyto blobs:/resources-bucket/key/gpkg-layer-1-legend.png /var/www/legend/wms-gpkg-layer-1-name/wms-gpkg-style-1-name.png || exit 1;
36+
rclone copyto blobs:/resources-bucket/key/gpkg-layer-1-legend.png /var/www/legend/wms-gpkg-layer-1-name/wms-gpkg-style-1-name.png || exit 1;
3637
Copied legend gpkg-layer-1-legend.png to /var/www/legend/wms-gpkg-layer-1-name/wms-gpkg-style-1-name.png;
3738
mkdir -p /var/www/legend/wms-gpkg-layer-2-name;
38-
rclone copyto blobs:/resources-bucket/key/gpkg-layer-2-legend.png /var/www/legend/wms-gpkg-layer-2-name/wms-gpkg-style-2-name.png || exit 1;
39+
rclone copyto blobs:/resources-bucket/key/gpkg-layer-2-legend.png /var/www/legend/wms-gpkg-layer-2-name/wms-gpkg-style-2-name.png || exit 1;
3940
Copied legend gpkg-layer-2-legend.png to /var/www/legend/wms-gpkg-layer-2-name/wms-gpkg-style-2-name.png;
4041
chown -R 999:999 /var/www/legend
4142
`
@@ -44,8 +45,8 @@ chown -R 999:999 /var/www/legend
4445
mkdir -p /srv/data/config/;
4546
rclone config create --non-interactive --obscure blobs azureblob endpoint $BLOBS_ENDPOINT account $BLOBS_ACCOUNT key $BLOBS_KEY use_emulator true;
4647
bash /srv/scripts/gpkg_download.sh;
47-
rclone copyto blobs:/tifs-bucket/key/tif-layer-1-data.tif /srv/data/tif/tif-layer-1-data.tif || exit 1;
48-
rclone copyto blobs:/tifs-bucket/key/tif-layer-2-data.tif /srv/data/tif/tif-layer-2-data.tif || exit 1;
48+
rclone copyto blobs:/tifs-bucket/key/tif-layer-1-data.tif /srv/data/tif/tif-layer-1-data.tif || exit 1;
49+
rclone copyto blobs:/tifs-bucket/key/tif-layer-2-data.tif /srv/data/tif/tif-layer-2-data.tif || exit 1;
4950
rclone copyto blobs:/resources-bucket/key/tif-symbol.png /srv/data/images/tif-symbol.png || exit 1;
5051
rclone copyto blobs:/resources-bucket/key/symbol.svg /srv/data/images/symbol.svg || exit 1;
5152
rclone copyto blobs:/resources-bucket/key/font-1.ttf /srv/data/config/fonts/font-1.ttf || exit 1;
@@ -55,10 +56,10 @@ echo font-2 font-2.ttf >> /srv/data/config/fonts/fonts.list;
5556
echo 'generated fonts.list:';
5657
cat /srv/data/config/fonts/fonts.list;
5758
mkdir -p /var/www/legend/wms-tif-layer-1-name;
58-
rclone copyto blobs:/resources-bucket/key/tif-layer-1-legend.png /var/www/legend/wms-tif-layer-1-name/wms-tif-style-1-name.png || exit 1;
59+
rclone copyto blobs:/resources-bucket/key/tif-layer-1-legend.png /var/www/legend/wms-tif-layer-1-name/wms-tif-style-1-name.png || exit 1;
5960
Copied legend tif-layer-1-legend.png to /var/www/legend/wms-tif-layer-1-name/wms-tif-style-1-name.png;
6061
mkdir -p /var/www/legend/wms-tif-layer-2-name;
61-
rclone copyto blobs:/resources-bucket/key/tif-layer-2-legend.png /var/www/legend/wms-tif-layer-2-name/wms-tif-style-2-name.png || exit 1;
62+
rclone copyto blobs:/resources-bucket/key/tif-layer-2-legend.png /var/www/legend/wms-tif-layer-2-name/wms-tif-style-2-name.png || exit 1;
6263
Copied legend tif-layer-2-legend.png to /var/www/legend/wms-tif-layer-2-name/wms-tif-style-2-name.png;
6364
chown -R 999:999 /var/www/legend
6465
`
@@ -290,7 +291,8 @@ func TestGetArgsForWMS(t *testing.T) {
290291
return
291292
}
292293
if args != tt.wantArgs {
293-
t.Errorf("GetArgs() = %v, want %v", args, tt.wantArgs)
294+
diff := cmp.Diff(tt.wantArgs, args)
295+
t.Errorf("GetArgs() -want, +got %s", diff)
294296
return
295297
}
296298
})

0 commit comments

Comments
 (0)