@@ -25,14 +25,13 @@ SOFTWARE.
2525package v3
2626
2727import (
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
3837const (
@@ -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+
115125type 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+
166266func (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+
235339func (layer * Layer ) hasBoundingBoxForCRS (crs string ) bool {
236340 for _ , bbox := range layer .BoundingBoxes {
237341 if bbox .CRS == crs {
0 commit comments