Tiles.go
780 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
40
41
42
package Api
import (
"fmt"
"github.com/gin-gonic/gin"
"io/ioutil"
"os"
)
func Tiles(c *gin.Context) {
c.Header("Access-Control-Allow-Origin", c.Request.Header.Get("Origin"))
c.Header("Access-Control-Allow-Credentials", "true")
dir, _ := os.Getwd()
//path := dir + "/tiles/" + c.Query("z") + "/" + c.Query("x") + "/" + c.Query("y") + ".jpg"
path := fmt.Sprintf("%s/tiles/%s/%s/%s.jpg",dir,c.Query("z"),c.Query("x"),c.Query("y"))
if !PathExists(path) {
path = dir + "/tiles/blank.png"
}
b, err := ioutil.ReadFile(path)
if err != nil {
fmt.Print(err)
}
c.Data(200, "Content-type: image/jpeg", b)
}
func PathExists(path string) (bool) {
_, err := os.Stat(path)
if err == nil {
return true
}
if os.IsNotExist(err) {
return false
}
return false
}