-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtile_type.go
More file actions
67 lines (58 loc) · 1.2 KB
/
tile_type.go
File metadata and controls
67 lines (58 loc) · 1.2 KB
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
package pmtilr
import (
"encoding/json"
"fmt"
)
type TileType uint8
const (
TileTypeUnknown = iota
TileTypeMVT
TileTypePNG
TileTypeJPEG
TileTypeWebp
TileTypeAvif
TileTypeMLT
)
var tileTypeOptions = map[TileType]string{
TileTypeUnknown: "unknown",
TileTypeMVT: "mvt",
TileTypeAvif: "avif",
TileTypeJPEG: "jpeg",
TileTypeWebp: "webp",
TileTypePNG: "png",
TileTypeMLT: "mlt",
}
func (t TileType) String() string {
return tileTypeOptions[t]
}
func (c TileType) MarshalJSON() ([]byte, error) {
str, ok := tileTypeOptions[c]
if !ok {
str = tileTypeOptions[TileTypeUnknown]
}
return json.Marshal(str)
}
func (t TileType) Ext() string {
return fmt.Sprintf(".%s", tileTypeOptions[t])
}
func (t TileType) ToContentType() (string, bool) {
switch t {
case TileTypeMVT:
return "application/x-protobuf", true
case TileTypeMLT:
return "application/vnd.maplibre-vector-tile", true
case TileTypeAvif:
return "image/avif", true
case TileTypeJPEG:
return "image/jpeg", true
case TileTypePNG:
return "image/png", true
case TileTypeWebp:
return "image/webp", true
default:
return "", false
}
}
func (t TileType) IsVector() bool {
return t == TileTypeMVT || t == TileTypeMLT
}