tile route
This commit is contained in:
parent
224ccde00d
commit
51bc900b00
@ -1,7 +1,6 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/sirupsen/logrus"
|
||||
"mapserver/app"
|
||||
"mapserver/vfs"
|
||||
@ -19,10 +18,7 @@ func Serve(ctx *app.App) {
|
||||
mux := http.NewServeMux()
|
||||
|
||||
mux.Handle("/", http.FileServer(vfs.FS(ctx.Config.Webdev)))
|
||||
|
||||
mux.HandleFunc("/api", func(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprint(w, "Api endpoint")
|
||||
})
|
||||
mux.Handle("/tile/", &Tiles{ctx: ctx})
|
||||
|
||||
err := http.ListenAndServe(":"+strconv.Itoa(ctx.Config.Port), mux)
|
||||
if err != nil {
|
||||
|
34
web/tiles.go
Normal file
34
web/tiles.go
Normal file
@ -0,0 +1,34 @@
|
||||
package web
|
||||
|
||||
import (
|
||||
"mapserver/app"
|
||||
"mapserver/coords"
|
||||
"net/http"
|
||||
"strings"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type Tiles struct {
|
||||
ctx *app.App
|
||||
}
|
||||
|
||||
func (t *Tiles) ServeHTTP(resp http.ResponseWriter, req *http.Request){
|
||||
str := strings.TrimPrefix(req.URL.Path, "/tile/")
|
||||
parts := strings.Split(str, "/")
|
||||
layerid, _ := strconv.Atoi(parts[0])
|
||||
x, _ := strconv.Atoi(parts[1])
|
||||
y, _ := strconv.Atoi(parts[2])
|
||||
zoom, _ := strconv.Atoi(parts[3])
|
||||
|
||||
c := coords.NewTileCoords(x,y,zoom,layerid)
|
||||
data, err := t.ctx.Tilerenderer.Render(c)
|
||||
|
||||
if err != nil {
|
||||
resp.WriteHeader(500)
|
||||
resp.Write([]byte(err.Error()))
|
||||
|
||||
} else {
|
||||
resp.Header().Add("content-type", "image/png")
|
||||
resp.Write(data)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user