forked from v4lli/prioritile
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile.go
More file actions
39 lines (33 loc) · 699 Bytes
/
Copy pathtile.go
File metadata and controls
39 lines (33 loc) · 699 Bytes
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
package main
import (
"fmt"
"strconv"
"strings"
)
type TileDescriptor struct {
X int
Y int
Z int
Format string
TileSet *TilesetDescriptor
}
func (p TileDescriptor) String() string {
return fmt.Sprintf("%d/%d/%d.%s", p.Z, p.X, p.Y, p.Format)
}
func Str2Tile(tileSpec string) (*TileDescriptor, error) {
parts := strings.Split(tileSpec, "/")
yParts := strings.Split(parts[2], ".")
z, err := strconv.Atoi(parts[0])
if err != nil {
return nil, err
}
x, err := strconv.Atoi(parts[1])
if err != nil {
return nil, err
}
y, err := strconv.Atoi(yParts[0])
if err != nil {
return nil, err
}
return &TileDescriptor{Z: z, X: x, Y: y, Format: yParts[1]}, nil
}