-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtilesets.go
127 lines (102 loc) · 3.37 KB
/
tilesets.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package mapbox
import (
"path"
"strconv"
"strings"
"time"
"github.com/pkg/errors"
)
// TilesetType is the data type of the tileset, either "vector" or "raster".
type TilesetType string
const (
VectorTileset TilesetType = "vector"
RasterTileset TilesetType = "raster"
)
// TilesetVisibility is either "public" or "private".
type TilesetVisibility string
const (
PublicTileset TilesetVisibility = "public"
PrivateTileset TilesetVisibility = "private"
)
// ListTilesetsParams defines optional parameters for the ListTilesets request.
type ListTilesetsParams struct {
Type *TilesetType
Visibility *TilesetVisibility
SortBy *SortBy
Limit *int
}
type Tileset struct {
Type string `json:"type,omitempty"`
Center [3]float64 `json:"center,omitempty"`
Created time.Time `json:"created,omitempty"`
Description string `json:"description,omitempty"`
Filesize int64 `json:"filesize,omitempty"`
ID string `json:"id,omitempty"`
Modified time.Time `json:"modified,omitempty"`
Name string `json:"name,omitempty"`
Visibility string `json:"visibility,omitempty"`
Status string `json:"status,omitempty"`
}
type TileJSON struct {
Bounds [4]float64 `json:"bounds,omitempty"`
Center [3]float64 `json:"center,omitempty"`
Created int64 `json:"created,omitempty"`
Format string `json:"format,omitempty"`
MinZoom int64 `json:"minzoom,omitempty"`
MaxZoom int64 `json:"maxzoom,omitempty"`
Name string `json:"name,omitempty"`
Scheme string `json:"scheme,omitempty"`
TileJSON string `json:"tile_json,omitempty"`
Tiles []string `json:"tiles,omitempty"`
VectorLayers []VectorLayer `json:"vector_layers,omitempty"`
}
type VectorLayer struct {
Description string `json:"description,omitempty"`
Fields map[string]string `json:"fields,omitempty"`
ID string `json:"id,omitempty"`
MaxZoom int64 `json:"maxzoom,omitempty"`
MinZoom int64 `json:"minzoom,omitempty"`
Source string `json:"source,omitempty"`
SourceName string `json:"source_name,omitempty"`
}
func (c *Client) ListTilesets(params ListTilesetsParams) ([]Tileset, error) {
url := c.baseURL
url.Path = path.Join(url.Path, "tilesets/v1/", c.username)
q := url.Query()
if params.Type != nil {
q.Add("type", string(*params.Type))
}
if params.Visibility != nil {
q.Add("visibility", string(*params.Visibility))
}
if params.SortBy != nil {
q.Add("sortby", string(*params.SortBy))
}
if params.Limit != nil {
q.Add("limit", strconv.Itoa(*params.Limit))
}
url.RawQuery = q.Encode()
var allTilesets []Tileset
requestURL := &url
for requestURL != nil {
var tilesets []Tileset
resp, err := c.do("GET", *requestURL, nil, &tilesets)
if err != nil {
return nil, errors.Wrap(err, "making request")
}
requestURL = c.nextPageURL(resp.Header)
allTilesets = append(allTilesets, tilesets...)
}
return allTilesets, nil
}
func (c *Client) GetTileJSON(tilesetIDs ...string) (TileJSON, error) {
ids := strings.Join(tilesetIDs, ",")
url := c.baseURL
url.Path = path.Join(url.Path, "v4", ids) + ".json"
var metadata TileJSON
_, err := c.do("GET", url, nil, &metadata)
if err != nil {
return TileJSON{}, err
}
return metadata, nil
}