forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
handle_capabilities.go
65 lines (53 loc) · 1.43 KB
/
handle_capabilities.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package server
import (
"encoding/json"
"fmt"
"net/http"
)
type Capabilities struct {
Version string `json:"version"`
Maps []CapabilitiesMap `json:"maps"`
}
type CapabilitiesMap struct {
Name string `json:"name"`
URI string `json:"uri"`
Layers []CapabilitiesLayer `json:"layers"`
}
type CapabilitiesLayer struct {
Name string `json:"name"`
URI string `json:"uri"`
MinZoom int `json:"minZoom"`
MaxZoom int `json:"maxZoom"`
}
type HandleCapabilities struct{}
func (req HandleCapabilities) ServeHTTP(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case "GET":
// new capabilities struct
var capabilities Capabilities
capabilities.Version = Version
// iterate our registered maps
for name, m := range maps {
// build the map details
cMap := CapabilitiesMap{
Name: name,
URI: fmt.Sprintf("/maps/%v", name),
}
for _, layer := range m {
// build the layer details
cLayer := CapabilitiesLayer{
Name: layer.Name,
URI: fmt.Sprintf("/maps/%v/%v", name, layer.Name),
MinZoom: layer.MinZoom,
MaxZoom: layer.MaxZoom,
}
// add the layer to the map
cMap.Layers = append(cMap.Layers, cLayer)
}
// add the map to the capabilities struct
capabilities.Maps = append(capabilities.Maps, cMap)
}
// setup a new json encoder and encode our capabilities
json.NewEncoder(w).Encode(capabilities)
}
}