Skip to content

Commit 8670c9e

Browse files
authored
Merge pull request #16 from PDOK/PDOK-17804-wms-mapfilegenerator-input
PDOK-17804 Added WMS mapserver input
2 parents 0f2242f + 413b6bf commit 8670c9e

File tree

7 files changed

+507
-20
lines changed

7 files changed

+507
-20
lines changed

api/v2beta1/wms_conversion.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,11 @@ package v2beta1
2626

2727
import (
2828
"errors"
29-
"log"
30-
"strconv"
31-
3229
sharedModel "github.com/pdok/smooth-operator/model"
33-
30+
"log"
3431
"sigs.k8s.io/controller-runtime/pkg/conversion"
32+
"strconv"
33+
"strings"
3534

3635
pdoknlv3 "github.com/pdok/mapserver-operator/api/v3"
3736
)
@@ -300,11 +299,27 @@ func (v2Service WMSService) MapLayersToV3() pdoknlv3.Layer {
300299
// it needs to be created with defaults from the service
301300
// and in this case the middleLayers are all layers without a group
302301
if topLayer == nil {
302+
boundingBoxes := make([]pdoknlv3.WMSBoundingBox, 0)
303+
if v2Service.Extent != nil {
304+
bboxStringList := strings.Split(*v2Service.Extent, " ")
305+
bbox := pdoknlv3.WMSBoundingBox{
306+
CRS: v2Service.DataEPSG,
307+
BBox: sharedModel.BBox{
308+
MinX: bboxStringList[0],
309+
MaxX: bboxStringList[2],
310+
MinY: bboxStringList[1],
311+
MaxY: bboxStringList[3],
312+
},
313+
}
314+
boundingBoxes = append(boundingBoxes, bbox)
315+
}
316+
303317
topLayer = &pdoknlv3.Layer{
304-
Title: &v2Service.Title,
305-
Abstract: &v2Service.Abstract,
306-
Keywords: v2Service.Keywords,
307-
Layers: &[]pdoknlv3.Layer{},
318+
Title: &v2Service.Title,
319+
Abstract: &v2Service.Abstract,
320+
Keywords: v2Service.Keywords,
321+
Layers: &[]pdoknlv3.Layer{},
322+
BoundingBoxes: boundingBoxes,
308323
}
309324

310325
// adding the bottom layers to the middle layers they are grouped by

api/v3/wms_types.go

Lines changed: 108 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,13 @@ SOFTWARE.
2525
package v3
2626

2727
import (
28-
"maps"
29-
"slices"
30-
"sort"
31-
3228
shared_model "github.com/pdok/smooth-operator/model"
3329
autoscalingv2 "k8s.io/api/autoscaling/v2"
3430
corev1 "k8s.io/api/core/v1"
3531
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
32+
"maps"
33+
"slices"
34+
"sort"
3635
)
3736

3837
const (
@@ -112,6 +111,17 @@ type WMSBoundingBox struct {
112111
BBox shared_model.BBox `json:"bbox"`
113112
}
114113

114+
func (wmsBoundingBox *WMSBoundingBox) ToExtent() string {
115+
return wmsBoundingBox.BBox.ToExtent()
116+
}
117+
118+
func (wmsBoundingBox *WMSBoundingBox) Combine(other *WMSBoundingBox) {
119+
if wmsBoundingBox.CRS != other.CRS {
120+
return
121+
}
122+
wmsBoundingBox.BBox.Combine(other.BBox)
123+
}
124+
115125
type Authority struct {
116126
Name string `json:"name"`
117127
URL string `json:"url"`
@@ -163,6 +173,96 @@ func init() {
163173
SchemeBuilder.Register(&WMS{}, &WMSList{})
164174
}
165175

176+
func (wmsService *WMSService) GetBoundingBox() WMSBoundingBox {
177+
var boundingBox *WMSBoundingBox
178+
179+
allLayers := wmsService.GetAllLayers()
180+
for _, layer := range allLayers {
181+
if layer.BoundingBoxes != nil && len(layer.BoundingBoxes) > 0 {
182+
for _, bbox := range wmsService.Layer.BoundingBoxes {
183+
if boundingBox == nil {
184+
boundingBox = &bbox
185+
} else {
186+
boundingBox.Combine(&bbox)
187+
}
188+
}
189+
}
190+
}
191+
192+
if boundingBox != nil {
193+
return *boundingBox
194+
} else {
195+
return WMSBoundingBox{
196+
CRS: "EPSG:28992",
197+
BBox: shared_model.BBox{
198+
MinX: "-25000",
199+
MaxX: "280000",
200+
MinY: "250000",
201+
MaxY: "860000",
202+
},
203+
}
204+
}
205+
206+
}
207+
208+
type AnnotatedLayer struct {
209+
// The name of the group that this layer belongs to, nil if it is not a member of a group. Groups can be a member of the toplayer as a group
210+
GroupName *string
211+
// Only for spec.Service.Layer
212+
IsTopLayer bool
213+
// Top layer or layer below the toplayer with children itself
214+
IsGroupLayer bool
215+
// Contains actual data
216+
IsDataLayer bool
217+
Layer Layer
218+
}
219+
220+
func (wmsService *WMSService) GetAnnotatedLayers() []AnnotatedLayer {
221+
result := make([]AnnotatedLayer, 0)
222+
223+
topLayer := wmsService.Layer
224+
annotatedTopLayer := AnnotatedLayer{
225+
GroupName: nil,
226+
IsTopLayer: true,
227+
IsGroupLayer: topLayer.Name != nil,
228+
IsDataLayer: false,
229+
Layer: topLayer,
230+
}
231+
result = append(result, annotatedTopLayer)
232+
233+
for _, topLayerChild := range *topLayer.Layers {
234+
groupName := topLayer.Name
235+
isGroupLayer := topLayerChild.Layers != nil && len(*topLayerChild.Layers) > 0
236+
isDataLayer := !isGroupLayer
237+
result = append(result, AnnotatedLayer{
238+
GroupName: groupName,
239+
IsTopLayer: false,
240+
IsGroupLayer: isGroupLayer,
241+
IsDataLayer: isDataLayer,
242+
Layer: topLayerChild,
243+
})
244+
245+
if topLayerChild.Layers != nil && len(*topLayerChild.Layers) > 0 {
246+
for _, middleLayerChild := range *topLayerChild.Layers {
247+
groupName = topLayerChild.Name
248+
result = append(result, AnnotatedLayer{
249+
GroupName: groupName,
250+
IsTopLayer: false,
251+
IsGroupLayer: false,
252+
IsDataLayer: true,
253+
Layer: middleLayerChild,
254+
})
255+
}
256+
}
257+
}
258+
259+
return result
260+
}
261+
262+
func (wmsService *WMSService) GetAllLayers() (layers []Layer) {
263+
return wmsService.Layer.GetAllLayers()
264+
}
265+
166266
func (layer *Layer) GetAllLayers() (layers []Layer) {
167267
layers = append(layers, *layer)
168268
if layer.Layers != nil {
@@ -232,6 +332,10 @@ func (layer *Layer) IsGroupLayer() bool {
232332
return layer.Layers != nil && len(*layer.Layers) > 0
233333
}
234334

335+
func (layer *Layer) IsTopLayer(service *WMSService) bool {
336+
return layer.Name == service.Layer.Name
337+
}
338+
235339
func (layer *Layer) hasBoundingBoxForCRS(crs string) bool {
236340
for _, bbox := range layer.BoundingBoxes {
237341
if bbox.CRS == crs {

internal/controller/mapfilegenerator/mapfile_generator.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package mapfilegenerator
22

33
import (
44
"encoding/json"
5-
"errors"
65
"fmt"
76
"strings"
87

@@ -50,8 +49,8 @@ func GetConfig[W pdoknlv3.WMSWFS](webservice W, ownerInfo *smoothoperatorv1.Owne
5049
return createConfigForWFS(WFS, ownerInfo)
5150
}
5251
case *pdoknlv3.WMS:
53-
if _, ok := any(webservice).(*pdoknlv3.WMS); ok {
54-
return "", errors.New("not implemented for WMS")
52+
if WMS, ok := any(webservice).(*pdoknlv3.WMS); ok {
53+
return createConfigForWMS(WMS, ownerInfo)
5554
}
5655
default:
5756
return "", fmt.Errorf("unexpected input, webservice should be of type WFS or WMS, webservice: %v", webservice)
@@ -71,3 +70,16 @@ func createConfigForWFS(wfs *pdoknlv3.WFS, ownerInfo *smoothoperatorv1.OwnerInfo
7170
}
7271
return string(jsonConfig), nil
7372
}
73+
74+
func createConfigForWMS(wms *pdoknlv3.WMS, ownerInfo *smoothoperatorv1.OwnerInfo) (config string, err error) {
75+
input, err := MapWMSToMapfileGeneratorInput(wms, ownerInfo)
76+
if err != nil {
77+
return "", err
78+
}
79+
80+
jsonConfig, err := json.MarshalIndent(input, "", " ")
81+
if err != nil {
82+
return "", err
83+
}
84+
return string(jsonConfig), nil
85+
}

0 commit comments

Comments
 (0)