aboutsummaryrefslogtreecommitdiff
path: root/main.go
blob: 80c5f31df4ba8f79cc10a73d55b5a5a15cf56a2b (plain) (blame)
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
/*
Copyright © 2020 Alexander Kiryukhin <a.kiryukhin@mail.ru>
This file is part of StaticMap project.
*/
package main

import (
	"github.com/labstack/echo/v4"
	"github.com/neonxp/StaticMap/pkg/static"
	"log"
	"strconv"
)

func main() {
	e := echo.New()
	e.GET("/map", func(c echo.Context) error {
		lat, err := strconv.ParseFloat(c.QueryParam("lat"), 64)
		if err != nil {
			return err
		}
		lon, err := strconv.ParseFloat(c.QueryParam("lon"), 64)
		if err != nil {
			return err
		}
		w, err := strconv.Atoi(c.QueryParam("w"))
		if err != nil {
			w = 800
		}
		h, err := strconv.Atoi(c.QueryParam("h"))
		if err != nil {
			h = 800
		}
		zoom, err := strconv.Atoi(c.QueryParam("zoom"))
		if err != nil {
			zoom = 16
		}
		if zoom < 1 {
			zoom = 1
		}
		if zoom > 20 {
			zoom = 20
		}
		img, err := static.GetMapImage(lat, lon, zoom, w, h)
		if err != nil {
			return err
		}
		return c.Blob(200, "image/png", img)
	})
	log.Fatal(e.Start(":8000"))
}