Skip to content

Commit

Permalink
Merge pull request #10 from PDOK/wmts-legendurl
Browse files Browse the repository at this point in the history
Wmts legendurl
  • Loading branch information
Shalucik authored Feb 9, 2021
2 parents 502254a + c39ad1b commit 8a587e5
Show file tree
Hide file tree
Showing 3 changed files with 134 additions and 11 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
# Dependency directories (remove the comment below to include it)
# vendor/

.vscode/*
.vscode/*

# Intellij files
.idea/
39 changes: 29 additions & 10 deletions pkg/wmts100/capabilities/capabilities.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package capabilities

import "github.com/pdok/ogc-specifications/pkg/ows"

// ParseXML func
func (c *Contents) ParseXML(doc []byte) error {
return nil
Expand Down Expand Up @@ -29,16 +31,12 @@ func (c Contents) GetTilematrixsets() map[string]bool {

// Layer in struct for repeatability
type Layer struct {
Title string `xml:"ows:Title" yaml:"title"`
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
WGS84BoundingBox struct {
LowerCorner string `xml:"ows:LowerCorner" yaml:"lowercorner"`
UpperCorner string `xml:"ows:UpperCorner" yaml:"uppercorner"`
} `xml:"ows:WGS84BoundingBox" yaml:"wgs84boundingbox"`
Identifier string `xml:"ows:Identifier" yaml:"identifier"`
Style struct {
Identifier string `xml:"ows:Identifier" yaml:"identifier"`
} `xml:"Style" yaml:"style"`
Title string `xml:"ows:Title" yaml:"title"`
Abstract string `xml:"ows:Abstract" yaml:"abstract"`
WGS84BoundingBox ows.BoundingBox `xml:"ows:WGS84BoundingBox" yaml:"wgs84boundingbox"`
Identifier string `xml:"ows:Identifier" yaml:"identifier"`
Metadata Metadata `xml:"Metadata" yaml:"metadata"`
Style []Style `xml:"Style" yaml:"style"`
Format string `xml:"Format" yaml:"format"`
TileMatrixSetLink []TileMatrixSetLink `xml:"TileMatrixSetLink" yaml:"tilematrixsetlink"`
ResourceURL struct {
Expand All @@ -48,6 +46,21 @@ type Layer struct {
} `xml:"ResourceURL" yaml:"resourceurl"`
}

// Metadata in struct for repeatability
type Metadata struct {
Href string `xml:"xlink:href,attr" yaml:"href"`
}

// Style in struct for repeatability
type Style struct {
Identifier string `xml:"ows:Identifier" yaml:"identifier"`
Title *string `xml:"ows:Title,omitempty" yaml:"title"`
Abstract *string `xml:"ows:Abstract,omitempty" yaml:"abstract"`
Keywords *ows.Keywords `xml:"Keywords,omitempty" yaml:"keywords"`
LegendURL []*LegendURL `xml:"LegendURL,omitempty" yaml:"legendurl"`
IsDefault *bool `xml:"isDefault,attr,omitempty" yaml:"isdefault"`
}

// TileMatrixSetLink in struct for repeatability
type TileMatrixSetLink struct {
TileMatrixSet string `xml:"TileMatrixSet" yaml:"tilematrixset"`
Expand All @@ -70,3 +83,9 @@ type TileMatrix struct {
MatrixWidth string `xml:"MatrixWidth" yaml:"matrixwidth"`
MatrixHeight string `xml:"MatrixHeight" yaml:"matrixheight"`
}

// LegendURL in struct for optionality
type LegendURL struct {
Format string `xml:"format,attr,omitempty" yaml:"format,omitempty"`
Href string `xml:"xlink:href,attr,omitempty" yaml:"href,omitempty"`
}
101 changes: 101 additions & 0 deletions pkg/wmts100/capabilities/capabilities_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package capabilities

import (
"encoding/xml"
"testing"

"github.com/pdok/ogc-specifications/pkg/ows"
)

func sp(s string) *string {
return &s
}

func bp(b bool) *bool {
return &b
}

// Example based on 7.1.1.3 ServiceMetadata document example from OGC WMTS 1.0.0 spec
var contentsWithLegend = Contents{
Layer: []Layer{
{
Title: "etopo2",
Abstract: `ETOPO2 - 2 minute Worldwide Bathymetry/Topography
Data taken from National Geophysical Data Center(NGDC),
ETOPO2 Global 2' Elevations, September 2001...`,
WGS84BoundingBox: ows.BoundingBox{LowerCorner: ows.Position{-180, -90}, UpperCorner: ows.Position{180, 90}},
Identifier: "etopo2",
Metadata: Metadata{Href: "http://www.maps.bob/etopo2/ metadata.htm"},
Style: []Style{
{
Title: sp(`default`),
Identifier: `default`,
LegendURL: []*LegendURL{
{
Format: "image/png",
Href: "http://www.maps.bob/etopo2/legend.png",
},
},
IsDefault: bp(true),
},
},
Format: "image/png",
TileMatrixSetLink: []TileMatrixSetLink{
{
TileMatrixSet: "WholeWorld_CRS_84",
},
},
},
},
}

func TestBuildStyleWithLegend(t *testing.T) {
expected := `<Style isDefault="true">
<ows:Identifier>default</ows:Identifier>
<ows:Title>default</ows:Title>
<LegendURL format="image/png" xlink:href="http://www.maps.bob/etopo2/legend.png"></LegendURL>
</Style>`
output, _ := xml.MarshalIndent(contentsWithLegend.Layer[0].Style, "", " ")
if string(output) != expected {
t.Errorf("test: %d, expected: %s ,\n got: %s", 1, expected, string(output))
}
}

// Example based on 7.1.1.3 ServiceMetadata document example from OGC WMTS 1.0.0 spec
var contentsWithoutLegend = Contents{
Layer: []Layer{
{
Title: "etopo2",
Abstract: `ETOPO2 - 2 minute Worldwide Bathymetry/Topography
Data taken from National Geophysical Data Center(NGDC),
ETOPO2 Global 2' Elevations, September 2001...`,
WGS84BoundingBox: ows.BoundingBox{LowerCorner: ows.Position{-180, -90}, UpperCorner: ows.Position{180, 90}},
Identifier: "etopo2",
Metadata: Metadata{Href: "http://www.maps.bob/etopo2/ metadata.htm"},
Style: []Style{
{
Title: sp(`default`),
Identifier: `default`,
IsDefault: bp(true),
},
},
Format: "image/png",
TileMatrixSetLink: []TileMatrixSetLink{
{
TileMatrixSet: "WholeWorld_CRS_84",
},
},
},
},
}

func TestBuildStyleWithoutLegend(t *testing.T) {
expected := `<Style isDefault="true">
<ows:Identifier>default</ows:Identifier>
<ows:Title>default</ows:Title>
</Style>`
output, _ := xml.MarshalIndent(contentsWithoutLegend.Layer[0].Style, "", " ")
if string(output) != expected {
t.Errorf("test: %d, expected: %s ,\n got: %s", 1, expected, string(output))
}
}

0 comments on commit 8a587e5

Please sign in to comment.