forked from go-spatial/tegola
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtile.go
65 lines (57 loc) · 1.52 KB
/
tile.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 mvt
import (
"fmt"
"context"
"github.com/terranodo/tegola"
"github.com/terranodo/tegola/mvt/vector_tile"
)
//Tile describes a tile.
type Tile struct {
layers []Layer
}
//AddLayers adds a Layer to the tile
func (t *Tile) AddLayers(layers ...*Layer) error {
// Need to make sure that all layer names are unique.
for i := range layers {
nl := layers[i]
if nl == nil {
// log.Printf("Got a nil layer for %v", i)
continue
}
for i, l := range t.layers {
if l.Name == nl.Name {
return fmt.Errorf("Layer %v, already is named %v, new layer not added.", i, l.Name)
}
}
t.layers = append(t.layers, *nl)
}
return nil
}
// Layers returns a copy of the layers in this tile.
func (t *Tile) Layers() (l []Layer) {
l = append(l, t.layers...)
return l
}
//VTile returns a tile object according to the Google Protobuff def. This function
// does the hard work of converting everything to the standard.
func (t *Tile) VTile(ctx context.Context, tile *tegola.Tile) (vt *vectorTile.Tile, err error) {
vt = new(vectorTile.Tile)
for _, l := range t.layers {
vtl, err := l.VTileLayer(ctx, tile)
if err != nil {
switch err {
case context.Canceled:
return nil, err
default:
return nil, fmt.Errorf("Error Getting VTileLayer: %v", err)
}
}
vt.Layers = append(vt.Layers, vtl)
}
return vt, nil
}
//TODO: What is this functions suppose to do?
//TileFromVTile will return a Tile object from the given vectorTile Tile object
func TileFromVTile(t *vectorTile.Tile) (*Tile, error) {
return nil, nil
}