Beispiel #1
0
func main() {
	flag.Parse()

	input := flag.Arg(0)
	output := flag.Arg(1)
	cwd, _ := os.Getwd()
	defer profile.Start(profile.ProfilePath(cwd)).Stop()

	m, _ := mapping.NewMap(input)

	r := rendering.NewRenderer(m, 5000, 5000)

	r.ClipToMap()
	r.DrawToFile(output)
}
Beispiel #2
0
func main() {
	flag.Parse()

	input := flag.Arg(0)

	m, _ := mapping.NewMap(input)
	r := rendering.NewRenderer(m, 256, 256)

	mux := pat.New()
	mux.Get("/:z/:x/:y.png", http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
		q := req.URL.Query()
		z_str := q.Get(":z")
		x_str := q.Get(":x")
		y_str := q.Get(":y")

		x, _ := strconv.Atoi(x_str)
		y, _ := strconv.Atoi(y_str)
		z, _ := strconv.Atoi(z_str)

		lng0, lat0 := util.Num2deg(x, y, z)
		lng0, lat0 = util.Gps2webmerc(lng0, lat0)
		lng1, lat1 := util.Num2deg(x+1, y+1, z)
		lng1, lat1 = util.Gps2webmerc(lng1, lat1)

		r.Lock()
		r.ClipTo(lng0, lat0, lng1, lat1)
		tile := r.Draw()
		r.Unlock()
		png.Encode(w, tile)
	}))

	http.Handle("/", mux)
	err := http.ListenAndServe(":3001", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}