Skip to content

Commit

Permalink
accept bboxes in capabilities
Browse files Browse the repository at this point in the history
  • Loading branch information
wroge committed Sep 16, 2021
1 parent 619b440 commit 99474af
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 6 deletions.
1 change: 0 additions & 1 deletion cli/cmd/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ var getmapCommand = &cobra.Command{
return err
}
}

if cmd.Flag("dry-run").Changed {
fmt.Println(s)
fmt.Println("File name:", name)
Expand Down
17 changes: 15 additions & 2 deletions getcap/abilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ func (ll Layers) GetLayer(layer string) Layer {

// GetBBox returns a BBox based on a specific EPSG code
func (a Abilities) GetBBox(epsg int) BBox {
return a.Layers.GetBBox(epsg)
bbox := a.Layers.GetBBox(epsg)
if bbox.MinX != 0 && bbox.MaxX != 0 {
return bbox
}
return a.BBoxes.GetBBox(epsg)
}

// GetBBox returns a BBox based on a specific EPSG code
Expand All @@ -60,7 +64,16 @@ func (bb BBoxes) GetBBox(epsg int) BBox {

// GetBBoxes returns BBoxes merged from all Layers
func (a Abilities) GetBBoxes() BBoxes {
return a.Layers.GetBBoxes()
var bb []BBox

for _, b := range append(a.Layers.GetBBoxes(), a.BBoxes...) {
if (b.CRS == "" && b.SRS == "") || (b.MinX == 0 && b.MaxX == 0) {
continue
}
bb = append(bb, b)
}

return bb
}

// GetBBoxes returns BBoxes merged from Layers
Expand Down
4 changes: 4 additions & 0 deletions getcap/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ func (a Abilities) String() string {
result += "\nLayers:\n"
result += a.Layers.String()
}
if a.BBoxes != nil {
result += "\nBBoxes:\n"
result += a.BBoxes.String()
}
return result
}

Expand Down
1 change: 1 addition & 0 deletions getcap/getcap.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ type Abilities struct {
Abstract string `xml:"Service>Abstract"`
Formats Formats `xml:"Capability>Request>GetMap>Format"`
Layers Layers `xml:"Capability>Layer>Layer"`
BBoxes BBoxes `xml:"Capability>Layer>BoundingBox"`
}

// Layer of a GetCapabilities-Request
Expand Down
6 changes: 3 additions & 3 deletions getmap/getmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func AddLayers(layers ...string) func(*Service) error {
func (s *Service) AddLayers(layers ...string) (err error) {
for _, l := range layers {
cl := s.Capabilities.GetLayer(l)
if cl.Name == "" || len(cl.BBoxes) < 1 {
if cl.Name == "" {
return InvalidValue{"Layer", l, s.Capabilities.GetLayerNames()}
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ func AddEPSG(epsgCode int) func(*Service) error {

// AddEPSG adds an EPSG code to a Service
func (s *Service) AddEPSG(epsgCode int) (err error) {
epsgCap := s.Capabilities.GetLayers(s.Layers...).GetBBoxes().GetEPSG()
epsgCap := s.Capabilities.GetBBoxes().GetEPSG()
if len(epsgCap) == 0 {
return errors.New("Adding EPSG failed")
}
Expand Down Expand Up @@ -361,7 +361,7 @@ func (s *Service) GetMap(minx, miny, maxx, maxy float64, o Option) (r *bytes.Rea
err = InvalidInput("Invalid: Image is too big: " + strconv.Itoa(width*height) + " Max Pixel: " + strconv.Itoa(MaxPixel))
return
}
epsgCap := s.Capabilities.GetLayers(s.Layers...).GetBBoxes().GetEPSG()
epsgCap := s.Capabilities.GetBBoxes().GetEPSG()
if !containsInt(epsgCap, s.EPSG) {
from := wgs84.EPSG().Code(s.EPSG)
if from == nil {
Expand Down

0 comments on commit 99474af

Please sign in to comment.